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

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

        Certain Structures fields do not map precisely to JSON schema types or
        formats.
        """
        return json.dumps(cls.for_jsonschema())
Esempio n. 3
0
def to_json(model, gottago=wholelist(), encode=True, sort_keys=False, **kw):
    field_converter = lambda f, v: f.for_json(v)
    model_converter = lambda m: to_json(m, encode=False, sort_keys=sort_keys)

    data = apply_shape(model.__class__, model, field_converter, model_converter, gottago, **kw)

    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 models.
     """
     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 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 models.
     """
     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. 6
0
def to_json(model, gottago=wholelist(), encode=True, sort_keys=False, **kw):
    field_converter = lambda f, v: f.for_json(v)
    model_converter = lambda m: to_json(m, encode=False, sort_keys=sort_keys)

    data = apply_shape(model.__class__, model, field_converter,
                       model_converter, gottago, **kw)

    if encode:
        return json.dumps(data, sort_keys=sort_keys)
    else:
        return data
Esempio n. 7
0
def make_safe_json(cls, model_or_dict, role, encode=True, sort_keys=False, **kw):
    field_converter = lambda f, v: f.for_json(v)
    model_converter = lambda m: make_safe_json(m.__class__, m, role, encode=False, sort_keys=sort_keys)

    gottago = lambda k, v: True
    if role in cls._options.roles:
        gottago = cls._options.roles[role]

    data = apply_shape(cls, model_or_dict, field_converter, model_converter, gottago, **kw)

    if encode:
        return json.dumps(data, sort_keys=sort_keys)
    else:
        return data
Esempio n. 8
0
    def make_json_publicsafe(cls, model_dict_or_dicts, encode=True,
                             sort_keys=False):
        field_converter = lambda f, v: cls._fields[f].for_json(v)
        model_encoder = lambda m: m.to_json(encode=False)
        model_converter = lambda m: m.make_json_publicsafe(m, encode=False,
                                                           sort_keys=sort_keys)
        field_list = cls._public_fields
        white_list = True

        safed = cls.make_safe(model_dict_or_dicts, field_converter,
                              model_converter, model_encoder,
                              field_list=field_list, white_list=white_list)
        if encode:
            return json.dumps(safed, sort_keys=sort_keys)
        else:
            return safed
Esempio n. 9
0
    def make_json_publicsafe(cls,
                             model_dict_or_dicts,
                             encode=True,
                             sort_keys=False):
        field_converter = lambda f, v: cls._fields[f].for_json(v)
        model_encoder = lambda m: m.to_json(encode=False)
        model_converter = lambda m: m.make_json_publicsafe(
            m, encode=False, sort_keys=sort_keys)
        field_list = cls._public_fields
        white_list = True

        safed = cls.make_safe(model_dict_or_dicts,
                              field_converter,
                              model_converter,
                              model_encoder,
                              field_list=field_list,
                              white_list=white_list)
        if encode:
            return json.dumps(safed, sort_keys=sort_keys)
        else:
            return safed
Esempio n. 10
0
def make_safe_json(cls,
                   model_or_dict,
                   role,
                   encode=True,
                   sort_keys=False,
                   **kw):
    field_converter = lambda f, v: f.for_json(v)
    model_converter = lambda m: make_safe_json(
        m.__class__, m, role, encode=False, sort_keys=sort_keys)

    gottago = lambda k, v: True
    if role in cls._options.roles:
        gottago = cls._options.roles[role]

    data = apply_shape(cls, model_or_dict, field_converter, model_converter,
                       gottago, **kw)

    if encode:
        return json.dumps(data, sort_keys=sort_keys)
    else:
        return data