Convert an object to a dictionary. Use 'post_processor(original_obj, dictionary)' to update the
    dictionary in the process
13306
def todict(obj, post_processor=None):  # pylint: disable=too-many-return-statements
    
    if isinstance(obj, dict):
        result = {k: todict(v, post_processor) for (k, v) in obj.items()}
        return post_processor(obj, result) if post_processor else result
    if isinstance(obj, list):
        return [todict(a, post_processor) for a in obj]
    if isinstance(obj, Enum):
        return obj.value
    if isinstance(obj, (date, time, datetime)):
        return obj.isoformat()
    if isinstance(obj, timedelta):
        return str(obj)
    if hasattr(obj, '_asdict'):
        return todict(obj._asdict(), post_processor)
    if hasattr(obj, '__dict__'):
        result = {to_camel_case(k): todict(v, post_processor)
                  for k, v in obj.__dict__.items()
                  if not callable(v) and not k.startswith('_')}
        return post_processor(obj, result) if post_processor else result
    return obj
1212902
def convert_to_process_params_dict(opt):
    
    opt = copy.deepcopy(opt)
    for arg, val in vars(opt).items():
        if isinstance(val, DictWithDefaultReturn):
            new_val = []
            for key in val.keys():
                if isinstance(val[key], list):
                    for item in val[key]:
                        if item is not None:
                            new_val.append(':'.join([key, str(item)]))
                else:
                    if val[key] is not None:
                        new_val.append(':'.join([key, str(val[key])]))
            setattr(opt, arg, new_val)
    return vars(opt)
1059406
def rec_dict_to_numpy_dict(obj_dict):
    
    if type(obj_dict) == dict:
        return {key: rec_dict_to_numpy_dict(value) if value is not None else None for key, value in obj_dict.items()}
    elif obj_dict is None:
        return None
    else:
        return np.asarray(obj_dict)
1142719
def dict_from_object(obj: object):
    """"""

    # If object is a dict instance, no need to convert.
    return (obj if isinstance(obj, dict)
            else {attr: getattr(obj, attr)
                  for attr in dir(obj) if not attr.startswith('_')})
356212
def fromDict(cls, _dict):
        
        obj = cls()
        obj.__dict__.update(_dict)
        return obj
1182800
def dict_update(base_dict, update_dict):
    
    if isinstance(update_dict, dict):
        base_dict.update(update_dict)

    return base_dict
1199308
def _response_item_to_object(self, resp_item):
        
        item_cls = resources.get_model_class(self.resource_type)
        properties_dict = resp_item[self.resource_type]
        new_dict = helpers.remove_properties_containing_None(properties_dict)
        # raises exception if something goes wrong
        obj = item_cls(new_dict)
        return obj
1266287
def get_dict(self, obj, state=None, base_name='View'):
        
        return self.get_dict_for_class(class_name=obj.__class__,
                                       state=obj.state,
                                       base_name=base_name)
266021
def from_dict(cls, obj_dict: Dict[str, Any]) -> "IterationRecord":
        """"""
        obj = cls()
        for key, item in obj_dict.items():
            obj.__dict__[key] = item

        return obj
1356472
def as_dict(self):
        
        result = {}
        for key in self._valid_properties:
            val = getattr(self, key)
            if isinstance(val, datetime):
                val = val.isoformat()
            # Parse custom classes
            elif val and not Model._is_builtin(val):
                val = val.as_dict()
            # Parse lists of objects
            elif isinstance(val, list):
                # We only want to call as_dict in the case where the item
                # isn't a builtin type.
                for i in range(len(val)):
                    if Model._is_builtin(val[i]):
                        continue
                    val[i] = val[i].as_dict()
            # If it's a boolean, add it regardless of the value
            elif isinstance(val, bool):
                result[key] = val

            # Add it if it's not None
            if val:
                result[key] = val
        return result
699704
def to_dict(self, minimal=False):

        """"""

        data = collections.OrderedDict()

        if minimal:

            # In the minimal representation we just output the value

            data['value'] = self._to_python_type(self.value)

        else:

            # In the complete representation we output everything is needed to re-build the object

            data['value'] = self._to_python_type(self.value)
            data['desc'] = str(self.description)
            data['min_value'] = self._to_python_type(self.min_value)
            data['max_value'] = self._to_python_type(self.max_value)
            # We use our own thread-safe format for the unit
            data['unit'] = self.unit.to_string(format='threadsafe')

        return data
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)
644135
def from_dict(cls, obj, **kwargs):
        """"""
        _origin = _pop_origin(kwargs)

        if isinstance(obj, string):
            obj = {'source': obj}

        cls._check_keys(obj)
        if _origin:
            if 'source' not in obj:
                raise context.TypeError("parameter 'source' is required but "
                                        "wasn't provided")
            obj = dict(obj)
            obj['source'] = cls._normpath(obj['source'], _origin)
        return cls(**obj)
1200841
def take(self, obj):
        """"""
        cached = self._thread_local.cache[self._get_cache_key(obj)]
        build_kwargs = {}

        if 'model' in cached and 'pks' in cached:
            build_kwargs['queryset'] = cached['model'].objects.filter(pk__in=cached['pks'])

        elif 'obj' in cached:
            if cached['obj'].__class__.objects.filter(pk=cached['obj'].pk).exists():
                build_kwargs['obj'] = cached['obj']
            else:
                # Object was deleted in the meantime.
                build_kwargs['queryset'] = cached['obj'].__class__.objects.none()

        self._clean_cache(obj)

        return build_kwargs
660269
def as_dictionary(self):
        
        return {
            "name": self.name,
            "type": self.type,
            "value": remove_0x_prefix(self.value) if self.type == 'bytes32' else self.value
        }
1153719
def to_dict(self):
        
        with self._lock:
            result = {}
            if self._gpayload:
                result.update(self._gpayload)
            if self._tpayload:
                result.update(getattr(self._tpayload, "context", {}))
            return result
651967
def to_dict(self):
        
        obj_dict = super(Text, self).to_dict()
        texts_dict = None
        if isinstance(self.text, list):
            texts_dict = [t.to_dict() for t in self.text]
        child_dict = {
            'type': self.__class__.__name__,
            'text': texts_dict
        }
        obj_dict.update(child_dict)
        return obj_dict