Esempio n. 1
0
    def to_jsonschema(cls):
        """Returns a representation of this DictShield class as a JSON schema.
        If certain fields are marked public, only those fields will be
        represented in the schema.

        Certain DictShield fields do not map precisely to JSON schema types or
        formats.
        """
        return json.dumps(cls.for_jsonschema())
Esempio n. 2
0
    def to_jsonschema(cls):
        """Returns a representation of this DictShield class as a JSON schema.
        If certain fields are marked public, only those fields will be
        represented in the schema.

        Certain DictShield fields do not map precisely to JSON schema types or
        formats.
        """
        return json.dumps(cls.for_jsonschema())
Esempio n. 3
0
 def to_json(self, encode=True, sort_keys=False):
     """Return data prepared for JSON. By default, it returns a JSON encoded
     string, but disabling the encoding to prevent double encoding with
     embedded documents.
     """
     fun = lambda f, v: f.for_json(v)
     data = self._to_fields(fun)
     if encode:
         return json.dumps(data, sort_keys=sort_keys)
     else:
         return data
Esempio n. 4
0
 def to_json(self, encode=True, sort_keys=False):
     """Return data prepared for JSON. By default, it returns a JSON encoded
     string, but disabling the encoding to prevent double encoding with
     embedded documents.
     """
     fun = lambda f, v: f.for_json(v)
     data = self._to_fields(fun)
     if encode:
         return json.dumps(data, sort_keys=sort_keys)
     else:
         return data
Esempio n. 5
0
    def make_json_publicsafe(cls, doc_dict_or_dicts, encode=True,
                             sort_keys=False):
        field_converter = lambda f, v: cls._fields[f].for_json(v)
        doc_encoder = lambda d: d.to_json(encode=False)
        doc_converter = lambda d: d.make_json_publicsafe(d, encode=False,
                                                         sort_keys=sort_keys)
        field_list = cls._public_fields
        white_list = True

        safed = cls.make_safe(doc_dict_or_dicts, field_converter,
                              doc_converter, doc_encoder,
                              field_list=field_list, white_list=white_list)
        if encode:
            return json.dumps(safed, sort_keys=sort_keys)
        else:
            return safed
Esempio n. 6
0
    def make_json_publicsafe(cls,
                             doc_dict_or_dicts,
                             encode=True,
                             sort_keys=False):
        field_converter = lambda f, v: cls._fields[f].for_json(v)
        doc_encoder = lambda d: d.to_json(encode=False)
        doc_converter = lambda d: d.make_json_publicsafe(
            d, encode=False, sort_keys=sort_keys)
        field_list = cls._public_fields
        white_list = True

        safed = cls.make_safe(doc_dict_or_dicts,
                              field_converter,
                              doc_converter,
                              doc_encoder,
                              field_list=field_list,
                              white_list=white_list)
        if encode:
            return json.dumps(safed, sort_keys=sort_keys)
        else:
            return safed