Returns an Erlang-TTB encoded tuple with the appropriate data and
        metadata from a TsObject.

        :param tsobj: a TsObject
        :type tsobj: TsObject
        :rtype: term-to-binary encoded object
513951
def encode_timeseries_put(self, tsobj):
        '''
        
        '''
        if tsobj.columns:
            raise NotImplementedError('columns are not used')

        if tsobj.rows and isinstance(tsobj.rows, list):
            req_rows = []
            for row in tsobj.rows:
                req_r = []
                for cell in row:
                    req_r.append(self.encode_to_ts_cell(cell))
                req_rows.append(tuple(req_r))
            req = tsputreq_a, tsobj.table.name, [], req_rows
            mc = MSG_CODE_TS_TTB_MSG
            rc = MSG_CODE_TS_TTB_MSG
            return Msg(mc, encode(req), rc)
        else:
            raise RiakError("TsObject requires a list of rows")
1063909
def tob(data, enc='utf8'):
    
    return data.encode(enc) if isinstance(data, six.text_type) else bytes(data)
1299019
def to_binary(value, encoding='utf-8'):
    
    if not value:
        return b''
    if isinstance(value, six.binary_type):
        return value
    if isinstance(value, six.text_type):
        return value.encode(encoding)
    return to_text(value).encode(encoding)
837054
def dumps_bytes(obj):
    
    b = dumps(obj)
    if isinstance(b, unicode):
        b = b.encode("ascii")
    return b
826074
def get_tuple(self):
        """"""
        objType, objInstance = self.value

        if isinstance(objType, int):
            pass
        elif isinstance(objType, str):
            # turn it back into an integer
            objType = self.objectTypeClass()[objType]
        else:
            raise TypeError("invalid datatype for objType")

        # pack the components together
        return (objType, objInstance)
151257
def _get_tcntobj(goids, go2obj, **kws):
        """"""
        # kws: gaf (gene2go taxid)
        if 'gaf' in kws or 'gene2go' in kws:
            # Get a reduced go2obj set for TermCounts
            _gosubdag = GoSubDag(goids, go2obj, rcntobj=False, prt=None)
            return get_tcntobj(_gosubdag.go2obj, **kws)
578728
function convertStrItems2Obj(obj) {
	var result = {};
	for (var key in obj) {
		var val = obj[key];
		val = extractTypeAndCast(val);
		convertStrItem2Obj(key, val, result);
	}

	return result;
}
706046
def create_data_types(self):
        """"""
        return {
            'Binary': self.create_binary,
            'BinaryArray': self.create_binary_array,
            'KeyValue': self.create_key_value,
            'KeyValueArray': self.create_key_value_array,
            'String': self.create_string,
            'StringArray': self.create_string_array,
            'TCEntity': self.create_tc_entity,
            'TCEntityArray': self.create_tc_entity_array,
        }
782438
def data_from_bytes(self, byte_representation):
        
        text = byte_representation.decode(self.encoding)
        return self.data_from_string(text)
84814
def get_attr_dict(self):
        '''
        
        '''
        try:
            typeobj = self.type()
            dictoffset = int_from_int(typeobj.field('tp_dictoffset'))
            if dictoffset != 0:
                if dictoffset < 0:
                    type_PyVarObject_ptr = gdb.lookup_type('PyVarObject').pointer()
                    tsize = int_from_int(self._gdbval.cast(type_PyVarObject_ptr)['ob_size'])
                    if tsize < 0:
                        tsize = -tsize
                    size = _PyObject_VAR_SIZE(typeobj, tsize)
                    dictoffset += size
                    assert dictoffset > 0
                    assert dictoffset % SIZEOF_VOID_P == 0

                dictptr = self._gdbval.cast(_type_char_ptr) + dictoffset
                PyObjectPtrPtr = PyObjectPtr.get_gdb_type().pointer()
                dictptr = dictptr.cast(PyObjectPtrPtr)
                return PyObjectPtr.from_pyobject_ptr(dictptr.dereference())
        except RuntimeError:
            # Corrupt data somewhere; fail safe
            pass

        # Not found, or some kind of error:
        return None
37391
def to_bytes(obj):
    

    if PY3:
        if isinstance(obj, str):
            return obj.encode(settings.DEFAULT_ENCODING)
        else:
            return obj if isinstance(obj, bytes) else b''
    else:
        if isinstance(obj, str):
            return obj
        else:
            return obj.encode(settings.DEFAULT_ENCODING) if isinstance(obj, unicode) else ''
1050116
def _decode(self, s, encode_nominal=False, matrix_type=DENSE):
        ''''''

        # Make sure this method is idempotent
        self._current_line = 0

        # If string, convert to a list of lines
        if isinstance(s, basestring):
            s = s.strip('\r\n ').replace('\r\n', '\n').split('\n')

        # Create the return object
        obj = {
            u'description': u'',
            u'relation': u'',
            u'attributes': [],
            u'data': []
        }
        attribute_names = {}

        # Create the data helper object
        data = _get_data_object_for_decoding(matrix_type)

        # Read all lines
        STATE = _TK_DESCRIPTION
        s = iter(s)
        for row in s:
            self._current_line += 1
            # Ignore empty lines
            row = row.strip(' \r\n')
            if not row: continue

            u_row = row.upper()

            # DESCRIPTION -----------------------------------------------------
            if u_row.startswith(_TK_DESCRIPTION) and STATE == _TK_DESCRIPTION:
                obj['description'] += self._decode_comment(row) + '\n'
            # -----------------------------------------------------------------

            # RELATION --------------------------------------------------------
            elif u_row.startswith(_TK_RELATION):
                if STATE != _TK_DESCRIPTION:
                    raise BadLayout()

                STATE = _TK_RELATION
                obj['relation'] = self._decode_relation(row)
            # -----------------------------------------------------------------

            # ATTRIBUTE -------------------------------------------------------
            elif u_row.startswith(_TK_ATTRIBUTE):
                if STATE != _TK_RELATION and STATE != _TK_ATTRIBUTE:
                    raise BadLayout()

                STATE = _TK_ATTRIBUTE

                attr = self._decode_attribute(row)
                if attr[0] in attribute_names:
                    raise BadAttributeName(attr[0], attribute_names[attr[0]])
                else:
                    attribute_names[attr[0]] = self._current_line
                obj['attributes'].append(attr)

                if isinstance(attr[1], (list, tuple)):
                    if encode_nominal:
                        conversor = EncodedNominalConversor(attr[1])
                    else:
                        conversor = NominalConversor(attr[1])
                else:
                    CONVERSOR_MAP = {'STRING': unicode,
                                     'INTEGER': lambda x: int(float(x)),
                                     'NUMERIC': float,
                                     'REAL': float}
                    conversor = CONVERSOR_MAP[attr[1]]

                self._conversors.append(conversor)
            # -----------------------------------------------------------------

            # DATA ------------------------------------------------------------
            elif u_row.startswith(_TK_DATA):
                if STATE != _TK_ATTRIBUTE:
                    raise BadLayout()

                break
            # -----------------------------------------------------------------

            # COMMENT ---------------------------------------------------------
            elif u_row.startswith(_TK_COMMENT):
                pass
            # -----------------------------------------------------------------
        else:
            # Never found @DATA
            raise BadLayout()

        def stream():
            for row in s:
                self._current_line += 1
                row = row.strip()
                # Ignore empty lines and comment lines.
                if row and not row.startswith(_TK_COMMENT):
                    yield row

        # Alter the data object
        obj['data'] = data.decode_rows(stream(), self._conversors)
        if obj['description'].endswith('\n'):
            obj['description'] = obj['description'][:-1]

        return obj
220433
def serialize(self, elt, sw, pyobj, **kw):
        '''
        '''
        if isinstance(pyobj, TypeCode):
            raise TypeError, 'pyobj is a typecode instance.'
        
        what = getattr(pyobj, 'typecode', None)
        if what is not None and type(pyobj) is types.InstanceType:
            tc = pyobj.__class__
            what = Any.serialmap.get(tc)
            if not what:
                tc = (types.ClassType, pyobj.__class__.__name__)
                what = Any.serialmap.get(tc)
        
        self.logger.debug('processContents: %s', self.processContents)

        # failed to find a registered type for class
        if what is None:
            #TODO: seems incomplete.  what about facets.
            #if self.processContents == 'strict':
            what = Any(pname=(self.nspname,self.pname))
                
        self.logger.debug('serialize with %s', what.__class__.__name__)
        what.serialize(elt, sw, pyobj, **kw)
1193845
def get_data(self) -> bytes:
        
        data = {
            "_class_name": self.__class__.__name__,
            "version": 1,
            "segments_bin": SegmentSequence([self.command_seg, self.tan_request]).render_bytes(),
            "resume_method": self.resume_method,
            "tan_request_structured": self.tan_request_structured,
        }
        return compress_datablob(DATA_BLOB_MAGIC_RETRY, 1, data)
989941
def objparse(ts)
    ts = eat('{', ts)
    obj = {}

    if ts[0][0] == '}'
      return obj, ts[1..-1]
    end

    k, v, ts = pairparse(ts)
    obj[k] = v

    if ts[0][0] == '}'
      return obj, ts[1..-1]
    end

    loop do
      ts = eat(',', ts)

      k, v, ts = pairparse(ts)
      obj[k] = v

      if ts[0][0] == '}'
        return obj, ts[1..-1]
      end
    end
  end
1073312
def code_binary(item):
    
    code_str = code(item)
    if isinstance(code_str, six.string_types):
        return code_str.encode('utf-8')
    return code_str
1088980
def to_unicode(obj, encoding='utf-8'):
    
    if isinstance(obj, string_types) or isinstance(obj, binary_type):
        if not isinstance(obj, text_type):
            obj = text_type(obj, encoding)
    return obj