A dictionary representing the the data of the class is returned.
        Native Python objects will still exist in this dictionary (for example,
        a ``datetime`` object will be returned rather than a string)
        unless ``serial`` is set to True.
505778
def to_dict(self, serial=False):
        '''

        '''
        if serial:
            return dict((key, self._fields[key].to_serial(getattr(self, key)))
                        for key in list(self._fields.keys()) if hasattr(self, key))
        else:
            return dict((key, getattr(self, key)) for key in list(self._fields.keys())
                       if hasattr(self, key))
69233
def to_json(self):
        
        data = {}
        for k, v in self.__dict__.items():
            if not k.startswith('_'):
                # values not serializable, should be converted to strings
                if isinstance(v, datetime):
                    v = utils.datetime_to_string(v)
                elif isinstance(v, date):
                    v = utils.date_to_string(v)
                elif isinstance(v, uuid.UUID):
                    v = str(v)
                elif isinstance(v, Decimal):
                    v = str(v)
                data[k] = v
        return data
91339
def json_data(self, instance, default=None):
        
        value = self.get(instance)
        if value:
            return value.output
        return value
991143
def __deserialize(self, data, klass):
        
        if data is None:
            return None

        if type(klass) == str:
            if klass.startswith('list['):
                sub_kls = re.match('list\[(.*)\]', klass).group(1)
                return [self.__deserialize(sub_data, sub_kls)
                        for sub_data in data]

            if klass.startswith('dict('):
                sub_kls = re.match('dict\(([^,]*), (.*)\)', klass).group(2)
                return {k: self.__deserialize(v, sub_kls)
                        for k, v in iteritems(data)}

            # convert str to class
            # for native types
            if klass in ['int', 'float', 'str', 'bool',
                         "date", 'datetime', "object"]:
                klass = eval(klass)
            # for model types
            else:
                klass = eval('models.' + klass)

        if klass in [int, float, str, bool]:
            return self.__deserialize_primitive(data, klass)
        elif klass == object:
            return self.__deserialize_object(data)
        elif klass == date:
            return self.__deserialize_date(data)
        elif klass == datetime:
            return self.__deserialize_datatime(data)
        else:
            return self.__deserialize_model(data, klass)
628318
def as_dict(self):
        
        if not self.cursor.rowcount:
            return {}

        self._rewind()
        if self.cursor.rowcount == 1:
            return dict(self.cursor.fetchone())
        else:
            raise ValueError('More than one row')
1151948
def to_dict(self):
        
        obj = {
            'id' : self.identifier,
            'name' : self.name,
            'description' : self.description,
            'type' : self.data_type.to_dict()
        }
        if not self.default is None:
            obj['default'] = self.default
        return obj
651935
def as_dict(self):
        
        d = {"@module": self.__class__.__module__,
             "@class": self.__class__.__name__}
        # print("in as_dict", type(self.x), type(self.c), type(self.xc))
        if self.x is not None: d["x"] = self.x.as_dict()
        if self.c is not None: d["c"] = self.c.as_dict()
        if self.xc is not None: d["xc"] = self.xc.as_dict()
        return d
643954
def serialize(self, data):
        
        if data is None:
            return None
        elif isinstance(data, dict):
            return serializer.Serializer().serialize(data)
        else:
            raise Exception(_("Unable to serialize object of type = '%s'") %
                            type(data))
1032650
def to_dict(self):
        
        rv = {'code': self.code}
        if not self.is_native():
            rv['issuer'] = self.issuer
            rv['type'] = self.type
        else:
            rv['type'] = 'native'
        return rv
1020027
def to_dict(cls, convert_datetime=True):
    
    def todict(obj):
        """
        recurse the objects and represent as a dict
        use the registered handlers if possible
        """
        data = {}
        if isinstance(obj, dict):
            for (key, val) in obj.items():
                data[key] = todict(val)
            return data
        if not convert_datetime and isinstance(obj, datetime):
            return obj
        elif type_handler_value(obj):
            return type_handler_value(obj)
        elif isinstance(obj, collections.Sequence) and not isinstance(obj, basestring):
            return [todict(v) for v in obj]
        elif hasattr(obj, "__dict__"):
            for key, value in obj.__dict__.items():
                if not callable(value) and not key.startswith('_'):
                    data[key] = todict(value)
            return data
        else:
            return obj

    return todict(cls)
937656
def serialize(self):
        
        return {
            "uuid": self.uuid, "type": self.type, "instance_id": self.instance_id,
            "prepared": self.prepared, "creation_time": self.creation_time,
            "data": self.data
        }
1341457
def get_as_datadict(self):
        
        return dict(type=self.__class__.__name__, tags=list(self.tags))
390044
def _serialize_default(cls, obj):
        

        if obj is None or cls._is_primitive(obj):
            return obj
        elif cls._is_bytes(obj):
            return obj.decode()
        elif type(obj) == list:
            return cls._serialize_list(obj)
        else:
            dict_ = cls._get_obj_raw(obj)

            return cls._serialize_dict(dict_)
545136
def dict(self):
        

        return {
            'title': self.title,
            'description': self.description,
            'time': self.time.isoformat(),
            'data': self.data()
        }
532254
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self, 'class_name') and self.class_name is not None:
            _dict['class'] = self.class_name
        return _dict
683752
def __deserialize(self, data, klass):
        
        if data is None:
            return None

        if type(klass) == str:
            from tradenity.resources.paging import Page
            if klass.startswith('page['):
                sub_kls = re.match('page\[(.*)\]', klass).group(1)
                return Page([self.__deserialize(sub_data, sub_kls)
                            for sub_data in data["items"]], self.__deserialize_page_info(data["__meta"]))
            if klass.startswith('list['):
                sub_kls = re.match('list\[(.*)\]', klass).group(1)
                return [self.__deserialize(sub_data, sub_kls)
                        for sub_data in data]

            if klass.startswith('dict('):
                sub_kls = re.match('dict\(([^,]*), (.*)\)', klass).group(2)
                return {k: self.__deserialize(v, sub_kls)
                        for k, v in six.iteritems(data)}

            # convert str to class
            if klass in self.NATIVE_TYPES_MAPPING:
                klass = self.NATIVE_TYPES_MAPPING[klass]
            else:
                klass = getattr(tradenity.resources, klass)

        if klass in self.PRIMITIVE_TYPES:
            return self.__deserialize_primitive(data, klass)
        elif klass == object:
            return self.__deserialize_object(data)
        elif klass == datetime.date:
            return self.__deserialize_date(data)
        elif klass == datetime.datetime:
            return self.__deserialize_datatime(data)
        else:
            return self.__deserialize_model(data, klass)
657407
def json_serial(obj):
        

        if isinstance(obj, (datetime.datetime, datetime.date)):
            return obj.isoformat()

        raise TypeError('Type {} not serializable.'.format(type(obj)))