Subclassing hook to specialize how JSON data is converted
        to keyword arguments
194975
def json_to_initkwargs(self, json_data, kwargs):
        """"""
        if isinstance(json_data, basestring):
            json_data = json.loads(json_data)
        return json_to_initkwargs(self, json_data, kwargs)
644955
def _parse_codeargs(argstr):
    '''
    
    '''
    args = []
    kwargs = {}
    if isinstance(argstr, str):
        for a in argstr.split():
            if '=' in a:
                k,attr = a.split('=')
                kwargs[k] = attr
            else:
                args.append(a)
    rd = {'args':args, 'kwargs':kwargs}
    return rd
548907
def _api_handler(self, *args, **kwargs):
        
        keyword_arguments = {}
        keyword_arguments.update(self.keywords)
        keyword_arguments.update(kwargs)
        return api_handler(*args, **keyword_arguments)
956297
def json(func):
    
    if inspect.isclass(func):
        apply_function_to_members(func, json)
        return func
    else:
        @functools.wraps(func)
        def decorated_view(*args, **kwargs):
            data = func(*args, **kwargs)
            return _build_response(data, jsonify)
        return decorated_view
467359
def translate_kwargs(self, **kwargs):
        """"""
        local_kwargs = self.kwargs.copy()
        local_kwargs.update(kwargs)

        if "data" in local_kwargs and "json" in local_kwargs:
            raise ValueError("Cannot use data and json together")

        if "data" in local_kwargs and isinstance(local_kwargs["data"], dict):
            local_kwargs.update({"json": local_kwargs["data"]})
            del local_kwargs["data"]

        headers = DEFAULT_HEADERS.copy()
        if "headers" in kwargs:
            headers.update(kwargs["headers"])
        if "json" in local_kwargs:
            headers.update({"Content-Type": "application/json;charset=UTF-8"})
        local_kwargs.update({"headers": headers})

        return local_kwargs
122319
def parameters(self, namespaced=False):
        """"""
        if namespaced:
            return json.loads(json.dumps(self.args[0]['parameters']), object_hook=lambda d: SimpleNamespace(**d))
        else:
            return self.args[0].get('parameters')
1251226
def dispatch_hook(cls, _pkt=None, *args, **kargs):
        '''
          
        '''
        if _pkt and len(_pkt) >= 2:
            version = orb(_pkt[0])
            pdu_type = orb(_pkt[1])
            if version == 0:
                return PDU_CLASS_VERSION_0[pdu_type]
            elif version == 1:
                return PDU_CLASS_VERSION_1[pdu_type]
        return Raw
807811
def parse_map(self, obj, mapping=None, *args, **kwargs):
        
        mapping = mapping or obj._mapping

        if "data" in kwargs:
            for k, v in mapping.items():
                if kwargs["data"].get(v, None) is not None:
                    val = kwargs["data"][v]
                else:
                    val = None
                self.add_attr(obj, k, val, from_json=True)
        else:
            for k, v in mapping.items():
                if k in kwargs:
                    self.add_attr(obj, k, kwargs[k])
637585
def dispatch_hook(cls, _pkt, _underlayer=None, *args, **kargs):
        """"""
        for klass in cls._payload_class:
            if hasattr(klass, "can_handle") and \
                    klass.can_handle(_pkt, _underlayer):
                return klass
        print("DCE/RPC payload class not found or undefined (using Raw)")
        return Raw
791251
def from_json(cls, json):
    
    if json[cls.KEY_RANGE_PARAM] is None:
      # pylint: disable=redefined-outer-name
      key_ranges = None
    else:
      key_ranges = []
      for k in json[cls.KEY_RANGE_PARAM]:
        if k:
          key_ranges.append(key_range.KeyRange.from_json(k))
        else:
          key_ranges.append(None)

    if json[cls.NAMESPACE_RANGE_PARAM] is None:
      ns_range = None
    else:
      ns_range = namespace_range.NamespaceRange.from_json_object(
          json[cls.NAMESPACE_RANGE_PARAM])

    if json[cls.CURRENT_KEY_RANGE_PARAM] is None:
      current_key_range = None
    else:
      current_key_range = key_range.KeyRange.from_json(
          json[cls.CURRENT_KEY_RANGE_PARAM])

    return cls(
        json[cls.ENTITY_KIND_PARAM],
        key_ranges,
        ns_range,
        json[cls.BATCH_SIZE_PARAM],
        current_key_range,
        filters=json.get(cls.FILTERS_PARAM))
1043228
def serialize_hook(self, instance):
        
        if getattr(instance, 'serialize_hook', None) and callable(instance.serialize_hook):
            return instance.serialize_hook(hook=self)
        if getattr(settings, 'HOOK_SERIALIZER', None):
            serializer = get_module(settings.HOOK_SERIALIZER)
            return serializer(instance, hook=self)
        # if no user defined serializers, fallback to the django builtin!
        data = serializers.serialize('python', [instance])[0]
        for k, v in data.items():
            if isinstance(v, OrderedDict):
                data[k] = dict(v)

        if isinstance(data, OrderedDict):
            data = dict(data)

        return {
            'hook': self.dict(),
            'data': data,
        }
897258
def json_class_decoder_hook(d: Dict) -> Any:
    
    if TYPE_LABEL in d:
        typename = d.get(TYPE_LABEL)
        if typename in TYPE_MAP:
            if DEBUG:
                log.debug("Deserializing: {!r}", d)
            d.pop(TYPE_LABEL)
            descriptor = TYPE_MAP[typename]
            obj = descriptor.to_obj(d)
            if DEBUG:
                log.debug("... to: {!r}", obj)
            return obj
    return d
694296
function processData(res, data, options) {
  const handlers = Object.assign({}, deserializers, options.deserializers);
  const contentType = res.headers['content-type'];
  const types = typeof contentType === 'string' ? contentType.split(';') : [];

  // if there are no content types, return the data unmodified
  if (!types.length) {
    return data;
  }

  return types.reduce((d, type) => {
    try {
      const t = type.toLocaleLowerCase().trim();
      const handler = handlers[t];

      if (d instanceof Error || typeof handler !== 'function') {
        return d;
      }
      return handler(d);
    } catch (error) {
      return error;
    }
  }, data);
}
1110012
function __serializeObject(data, options=DEFAULT_OPTIONS) {
	let dataBuffers = [];
	let allKeys = (options.sort_key === true) ? Object.keys(data).sort() : Object.keys(data);
	// ignore undefined value
	for (let key of allKeys) {
		let subData = data[key];
		if (subData === undefined) continue;

		let subType = __getType(subData, options);
		let subTypeBuffer = __serializeType(subType);
		let keyBuffers = __serializeShortString(key);
		let subDataBuffers = __serializeData(subType, subData, options);
		dataBuffers.push(subTypeBuffer, ...keyBuffers, ...subDataBuffers);
	}
	let length = __getLengthByArrayBuffers(dataBuffers);
	let lengthData = new Uint32Array([length]);
	return [lengthData.buffer, ...dataBuffers];
}
1275131
def from_json(cls, data):
        
        assert 'header' in data, 'Required keyword "header" is missing!'
        assert 'values' in data, 'Required keyword "values" is missing!'
        return cls(Header.from_json(data['header']), data['values'])
32811
def abbrev_hook(self, data: cmd2.plugin.PostparsingData) -> cmd2.plugin.PostparsingData:
        """"""
        func = self.cmd_func(data.statement.command)
        if func is None:
            # check if the entered command might be an abbreviation
            possible_cmds = [cmd for cmd in self.get_all_commands() if cmd.startswith(data.statement.command)]
            if len(possible_cmds) == 1:
                raw = data.statement.raw.replace(data.statement.command, possible_cmds[0], 1)
                data.statement = self.statement_parser.parse(raw)
        return data
1007384
def from_json(cls, data):
        
        optional_keys = ('city', 'state', 'country', 'latitude', 'longitude',
                         'time_zone', 'elevation', 'station_id', 'source')
        for key in optional_keys:
            if key not in data:
                data[key] = None

        return cls(data['city'], data['state'], data['country'], data['latitude'],
                   data['longitude'], data['time_zone'], data['elevation'],
                   data['station_id'], data['source'])