Deserializes msgpack bytes to OrderedDict (in the same sorted order as for serialize)
        :param data: the data in bytes
        :return: sorted OrderedDict
964726
def deserialize(self, data, fields=None):
        
        # TODO: it can be that we returned data by `get_lines`, that is already deserialized
        if not isinstance(data, (bytes, bytearray)):
            return data
        return msgpack.unpackb(data, encoding='utf-8', object_pairs_hook=decode_to_sorted)
404720
def iteritems_sorted(dict_):
    
    if isinstance(dict_, OrderedDict):
        return six.iteritems(dict_)
    else:
        return iter(sorted(six.iteritems(dict_)))
321325
def ordered_dict_to_dict(d):
    
    ret = {}
    new_d = deepcopy(d)
    for k, v in new_d.items():
        if isinstance(v, OrderedDict):
            v = dict(v)
        if isinstance(v, dict):
            v = ordered_dict_to_dict(v)
        ret[k] = v
    return ret
986169
def _sort(self):
        
        self.versions = OrderedDict(sorted(self.versions.items(), key=lambda v: v[0]))
305514
def format_response(self, data):
        
        self.count = self.max_count

        return OrderedDict([
            ('highest_count', self.max_count),
            ('overall_total', self.total),
            ('next', self.get_next_link()),
            ('previous', self.get_previous_link()),
            ('results', data)
        ])
595749
def _deserialize_data(self, json_data):
        

        my_dict = json.loads(json_data.decode('utf8').replace("'", '"'),
            encoding='UTF-8')

        for item in my_dict:
            if item == const.ADIF:
                my_dict[item] = int(my_dict[item])
            elif item == const.DELETED:
                my_dict[item] = self._str_to_bool(my_dict[item])
            elif item == const.CQZ:
                my_dict[item] = int(my_dict[item])
            elif item == const.ITUZ:
                my_dict[item] = int(my_dict[item])
            elif item == const.LATITUDE:
                my_dict[item] = float(my_dict[item])
            elif item == const.LONGITUDE:
                my_dict[item] = float(my_dict[item])
            elif item == const.START:
                my_dict[item] = datetime.strptime(my_dict[item], '%Y-%m-%d%H:%M:%S').replace(tzinfo=UTC)
            elif item == const.END:
                my_dict[item] = datetime.strptime(my_dict[item], '%Y-%m-%d%H:%M:%S').replace(tzinfo=UTC)
            elif item == const.WHITELIST_START:
                my_dict[item] = datetime.strptime(my_dict[item], '%Y-%m-%d%H:%M:%S').replace(tzinfo=UTC)
            elif item == const.WHITELIST_END:
                my_dict[item] = datetime.strptime(my_dict[item], '%Y-%m-%d%H:%M:%S').replace(tzinfo=UTC)
            elif item == const.WHITELIST:
                my_dict[item] = self._str_to_bool(my_dict[item])
            else:
                my_dict[item] = unicode(my_dict[item])

        return my_dict
876207
def as_json(data, **kwargs):
    

    if 'sort_keys' not in kwargs:
        kwargs['sort_keys'] = False
    if 'ensure_ascii' not in kwargs:
        kwargs['ensure_ascii'] = False

    data = json.dumps(data, **kwargs)

    return data
276462
def header2dict(self, names, struct_format, data):
        
        unpacked_data = struct.unpack(struct_format, data)
        return dict(zip(names, unpacked_data))
534785
def __deserialize_primitive(self, data, klass):
        
        try:
            return klass(data)
        except UnicodeEncodeError:
            return text(data)
        except TypeError:
            return data
773471
def loads(s, single=False, version=_default_version,
          strict=False, errors='warn'):
    
    ms = deserialize(s, version=version, strict=strict, errors=errors)
    if single:
        return next(ms)
    else:
        return ms
608201
def write_data(data):
    

    sorted_dict = sort_recursive(data)

    with open(_datafile, 'w') as file:
        _json.dump(sorted_dict, file, indent=2)
121241
def decode(cls, data, bytes_to_read=None):
        
        if isinstance(data, bytes):
            data = io.BytesIO(data)
        if bytes_to_read is None:
            bytes_to_read = Int32.decode(data)

        # if FetchRequest max_bytes is smaller than the available message set
        # the server returns partial data for the final message
        # So create an internal buffer to avoid over-reading
        raw = io.BytesIO(data.read(bytes_to_read))

        items = []
        while bytes_to_read:
            try:
                offset = Int64.decode(raw)
                msg_bytes = Bytes.decode(raw)
                bytes_to_read -= 8 + 4 + len(msg_bytes)
                items.append((offset, len(msg_bytes), Message.decode(msg_bytes)))
            except ValueError:
                # PartialMessage to signal that max_bytes may be too small
                items.append((None, None, PartialMessage()))
                break
        return items
787017
def _serialize_dict(cls, data):
        '''
        
        '''
        return b64encode(zlib.compress(cPickle.dumps(data, protocol=2))).decode()
1162917
def _GetOrderedEntries(data):
  

  # The raw data dictionary has two kinds of keys: strings (which correspond to
  # field name) or integers (if the name is unknown). In Python 3 it is not
  # possible to compare integers and strings to each other, so we first tag each
  # with either a 0 or 1 (so named fields are going to be serialized first) and
  # let the lexicographical ordering of the tuples take care of the rest.
  def Tag(field):
    """Tags field name with a number to make comparison possible."""

    # TODO: We use `string_types` here because in Python 2
    # attribute names (which are passed e.g. through keyword arguments) are
    # represented as `bytes` whereas in Python 3 it is `unicode`. This should
    # be replaced with `str` once support for Python 2 is dropped.
    if isinstance(field, string_types):
      return 0, field
    if isinstance(field, int):
      return 1, field

    message = "Unexpected field '{}' of type '{}'".format(field, type(field))
    raise TypeError(message)

  for field in sorted(iterkeys(data), key=Tag):
    yield data[field]
959449
def dict(self):
        
        from collections import OrderedDict
        SKIP_KEYS = ()
        return OrderedDict(
            (p.key, getattr(self, p.key)) for p in self.__mapper__.attrs if p.key not in SKIP_KEYS)
739099
def _deserialize(data)
      @data = data.map { |v| v.is_a?(POReference) ?
                         POXReference.new(@store, v.id) : v }
    end
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)