示例#1
0
 def _flatten_key_value_pair(self, k, v, data):
     """Flatten a key/value pair into the passed-in dictionary."""
     if not util.is_picklable(k, v):
         return data
     if not isinstance(k, (str, unicode)):
         try:
             k = repr(k)
         except:
             k = unicode(k)
     data[k] = self.flatten(v)
     return data
示例#2
0
 def _flatten_key_value_pair(self, k, v, data):
     """Flatten a key/value pair into the passed-in dictionary."""
     if not util.is_picklable(k, v):
         return data
     if type(k) not in types.StringTypes:
         from jsonpickle import encode
         k = tags.DICT_KEY + " " + encode(k)
     self._namestack.append(k)
     data[k] = self.flatten(v)
     self._namestack.pop()
     return data
示例#3
0
 def _flatten_key_value_pair(self, k, v, data):
     """Flatten a key/value pair into the passed-in dictionary."""
     if not util.is_picklable(k, v):
         return data
     if type(k) not in types.StringTypes:
         try:
             k = repr(k)
         except:
             k = unicode(k)
     data[k] = self.flatten(v)
     return data
示例#4
0
 def _flatten_key_value_pair(self, k, v, data):
     """Flatten a key/value pair into the passed-in dictionary."""
     if not util.is_picklable(k, v):
         return data
     if not isinstance(k, str):
         try:
             k = repr(k)
         except:
             k = str(k)
     data[k] = self.flatten(v)
     return data
示例#5
0
 def _flatten_key_value_pair(self, k, v, data):
     """Flatten a key/value pair into the passed-in dictionary."""
     if not util.is_picklable(k, v):
         return data
     if not isinstance(k, (str, unicode)):
         if self.keys:
             k = tags.JSON_KEY + encode(
                 k, reset=False, keys=True, context=self, backend=self.backend, make_refs=self.make_refs
             )
         else:
             try:
                 k = repr(k)
             except:
                 k = unicode(k)
     data[k] = self._flatten(v)
     return data
示例#6
0
    def _flatten_key_value_pair(self, k, v, data):
        """Flatten a key/value pair into the passed-in dictionary."""
        if not util.is_picklable(k, v):
            return data
        if self.keys:
            if not isinstance(k, (str, unicode)) or k.startswith(tags.JSON_KEY):
                k = self._escape_key(k)
        else:
            if not isinstance(k, (str, unicode)):
                try:
                    k = repr(k)
                except:
                    k = unicode(k)

        data[k] = self._flatten(v)
        return data
示例#7
0
 def _flatten_key_value_pair(self, k, v, data):
     """Flatten a key/value pair into the passed-in dictionary."""
     if not util.is_picklable(k, v):
         return data
     if not isinstance(k, (str, unicode)):
         if self.keys:
             k = tags.JSON_KEY + encode(k,
                                        reset=False, keys=True,
                                        context=self, backend=self.backend,
                                        make_refs=self.make_refs)
         else:
             try:
                 k = repr(k)
             except:
                 k = unicode(k)
     data[k] = self._flatten(v)
     return data
示例#8
0
    def _flatten_key_value_pair(self, k, v, data):
        """Flatten a key/value pair into the passed-in dictionary."""
        if not util.is_picklable(k, v):
            return data
        if self.keys:
            if not isinstance(k, (str, unicode)) or k.startswith(tags.JSON_KEY):
                k = self._escape_key(k)
        else:
            if k is None:
                k = 'null'  # for compatibility with common json encoders

            if self.numeric_keys and isinstance(k, numeric_types):
                pass
            elif not isinstance(k, (str, unicode)):
                k = self.flatten(k)

        data[k] = self._flatten(v)
        return data
示例#9
0
    def _flatten_key_value_pair(self, k, v, data):
        """Flatten a key/value pair into the passed-in dictionary."""
        if not util.is_picklable(k, v):
            return data
        if self.keys:
            if not isinstance(k, (str, unicode)) or k.startswith(tags.JSON_KEY):
                k = self._escape_key(k)
        else:
            if k is None:
                k = 'null'  # for compatibility with common json encoders

            if self.numeric_keys and isinstance(k, numeric_types):
                pass
            elif not isinstance(k, (str, unicode)):
                try:
                    k = repr(k)
                except:
                    k = unicode(k)

        data[k] = self._flatten(v)
        return data