Beispiel #1
0
    def __init__(self, app=None, validator=None, mime_type=None,
                                        ignore_uncap=False,
                                        # DictDocument specific
                                        ignore_wrappers=True,
                                        complex_as=dict,
                                        ordered=False,
                                        # YamlDocument specific
                                        safe=True, **kwargs):

        HierDictDocument.__init__(self, app, validator, mime_type, ignore_uncap,
                                           ignore_wrappers, complex_as, ordered)

        self._from_string_handlers[Double] = lambda cls, val: val
        self._from_string_handlers[Boolean] = lambda cls, val: val
        self._from_string_handlers[Integer] = lambda cls, val: val

        self._to_string_handlers[Double] = lambda cls, val: val
        self._to_string_handlers[Boolean] = lambda cls, val: val
        self._to_string_handlers[Integer] = lambda cls, val: val

        self.in_kwargs = dict(kwargs)
        self.out_kwargs = dict(kwargs)

        self.in_kwargs['Loader'] = Loader
        self.out_kwargs['Dumper'] =  Dumper
        if safe:
            self.in_kwargs['Loader'] = SafeLoader
            self.out_kwargs['Dumper'] =  SafeDumper

        if not 'indent' in self.out_kwargs:
            self.out_kwargs['indent'] = 4

        if not 'default_flow_style' in self.out_kwargs:
            self.out_kwargs['default_flow_style'] = False
Beispiel #2
0
    def __init__(self, app=None, validator=None, mime_type=None,
                        ignore_uncap=False,
                        # DictDocument specific
                        ignore_wrappers=True, complex_as=dict, ordered=False):

        HierDictDocument.__init__(self, app, validator, mime_type, ignore_uncap,
                                           ignore_wrappers, complex_as, ordered)

        self._from_string_handlers[Double] = lambda cls, val: val
        self._from_string_handlers[Boolean] = lambda cls, val: val
        self._from_string_handlers[Integer] = lambda cls, val: val

        self._to_string_handlers[Double] = lambda cls, val: val
        self._to_string_handlers[Boolean] = lambda cls, val: val
        self._to_string_handlers[Integer] = lambda cls, val: val
Beispiel #3
0
    def __init__(self, app=None, validator=None, mime_type=None,
                        ignore_uncap=False,
                        # DictDocument specific
                        ignore_wrappers=True, complex_as=dict, ordered=False):

        HierDictDocument.__init__(self, app, validator, mime_type, ignore_uncap,
                                           ignore_wrappers, complex_as, ordered)

        self._from_string_handlers[Double] = lambda cls, val: val
        self._from_string_handlers[Boolean] = lambda cls, val: val
        self._from_string_handlers[Integer] = lambda cls, val: val

        self._to_string_handlers[Double] = lambda cls, val: val
        self._to_string_handlers[Boolean] = lambda cls, val: val
        self._to_string_handlers[Integer] = lambda cls, val: val
Beispiel #4
0
    def __init__(
            self,
            app=None,
            validator=None,
            mime_type=None,
            ignore_uncap=False,
            # DictDocument specific
            ignore_wrappers=True,
            complex_as=dict,
            ordered=False,
            default_string_encoding=None,
            **kwargs):

        super(JsonDocument,
              self).__init__(app, validator, mime_type, ignore_uncap,
                             ignore_wrappers, complex_as, ordered)

        # this is needed when we're overriding a regular instance attribute
        # with a property.
        self.__message = HierDictDocument.__getattribute__(self, 'message')

        self._from_string_handlers[Double] = lambda cls, val: val
        self._from_string_handlers[Boolean] = lambda cls, val: val
        self._from_string_handlers[Integer] = lambda cls, val: val

        self._to_string_handlers[Double] = lambda cls, val: val
        self._to_string_handlers[Boolean] = lambda cls, val: val
        self._to_string_handlers[Integer] = lambda cls, val: val

        self.default_string_encoding = default_string_encoding
        self.kwargs = kwargs
Beispiel #5
0
    def __init__(
            self,
            app=None,
            validator=None,
            mime_type=None,
            ignore_uncap=False,
            # DictDocument specific
            ignore_wrappers=True,
            complex_as=dict,
            ordered=False,
            default_string_encoding=None,
            polymorphic=False,
            **kwargs):

        super(JsonDocument,
              self).__init__(app, validator, mime_type, ignore_uncap,
                             ignore_wrappers, complex_as, ordered, polymorphic)

        # this is needed when we're overriding a regular instance attribute
        # with a property.
        self.__message = HierDictDocument.__getattribute__(self, 'message')

        self._from_unicode_handlers[Double] = self._ret
        self._from_unicode_handlers[Boolean] = self._ret
        self._from_unicode_handlers[Integer] = self._ret

        self._to_unicode_handlers[Double] = self._ret
        self._to_unicode_handlers[Boolean] = self._ret
        self._to_unicode_handlers[Integer] = self._ret

        self.default_string_encoding = default_string_encoding
        self.kwargs = kwargs
Beispiel #6
0
    def __init__(
            self,
            app=None,
            validator=None,
            mime_type=None,
            ignore_uncap=False,
            # DictDocument specific
            ignore_wrappers=True,
            complex_as=dict,
            ordered=False,
            # YamlDocument specific
            safe=True,
            **kwargs):

        HierDictDocument.__init__(self, app, validator, mime_type,
                                  ignore_uncap, ignore_wrappers, complex_as,
                                  ordered)

        self._from_string_handlers[Double] = lambda cls, val: val
        self._from_string_handlers[Boolean] = lambda cls, val: val
        self._from_string_handlers[Integer] = lambda cls, val: val

        self._to_string_handlers[Double] = lambda cls, val: val
        self._to_string_handlers[Boolean] = lambda cls, val: val
        self._to_string_handlers[Integer] = lambda cls, val: val

        self.in_kwargs = dict(kwargs)
        self.out_kwargs = dict(kwargs)

        self.in_kwargs['Loader'] = Loader
        self.out_kwargs['Dumper'] = Dumper
        if safe:
            self.in_kwargs['Loader'] = SafeLoader
            self.out_kwargs['Dumper'] = SafeDumper

        if not 'indent' in self.out_kwargs:
            self.out_kwargs['indent'] = 4

        if not 'default_flow_style' in self.out_kwargs:
            self.out_kwargs['default_flow_style'] = False
Beispiel #7
0
def get_object_as_dict(o, cls, wrapper_name=None, skip_depth=0):
    if skip_depth == 0: # FIXME: ???
        return list(HierDictDocument._object_to_doc(cls, o, wrapper_name, skip_depth))[0]
    else:
        return HierDictDocument._object_to_doc(cls, o, wrapper_name, skip_depth)
Beispiel #8
0
def get_dict_as_object(d, cls, skip_depth=0):
    if issubclass(cls, Array):
        d = list(d.values())[0] # FIXME: Hack!

    return HierDictDocument._doc_to_object(cls, d, skip_depth)