Beispiel #1
0
 def __init__(self, encoding=None, object_hook=None, parse_float=None,
              parse_int=None, parse_constant=None, strict=True,
              object_pairs_hook=None):
    json.JSONDecoder.__init__(self, encoding, object_hook, parse_float, parse_int, parse_constant, strict, object_pairs_hook)
    self.parse_string = custom_parse_string
    #self.scan_once = make_scanner(self)  # using C-based variant does not work
    self.scan_once = py_make_scanner(self)
Beispiel #2
0
def extended_json_decoder():
    '''Return a decoder for the superset of JSON understood by the
    upatch function.

    The exact nature of this superset is documented in the manpage for
    json_patch(1).  Briefly, the string ``...`` is accepted where
    standard JSON expects a ``{<property name>}: {<object>}``
    construction, and the string ``...``, optionally followed by a
    number in parentheses, is accepted where standard JSON expects an
    array element.

    The superset is implemented by parsing ``...`` in JSON objects as
    a key/value pair ``Ellipsis: True`` in the resulting dictionary,
    and ``...({num}){?}`` as a subsequence of ``{num}`` ``Ellipsis``
    objects, or one ellipsis object if ``({num})`` is not present.

    Examples:

    >>> dec = extended_json_decoder()
    >>> (dec.decode('{"foo": "bar",...,"baz": "quux"}') ==
    ...  {"foo": "bar", "baz": "quux", Ellipsis: True})
    True
    >>> dec.decode('[...]')
    [Ellipsis]
    >>> dec.decode('["foo",...(3),"bar"]')
    [u'foo', Ellipsis, Ellipsis, Ellipsis, u'bar']
    '''
    dec = decoder.JSONDecoder()
    dec.parse_object = _JSONObject
    dec.parse_array = _JSONArray
    dec.scan_once = scanner.py_make_scanner(dec)
    return dec
Beispiel #3
0
    def __init__(self, name="", *args, **kwargs):
        super(Decoder, self).__init__(*args, **kwargs)

        def wrap_obj_parser(parser, node_type):
            def internal(o_and_start, *args, **kwargs):
                o, start = o_and_start
                r, end = parser(o_and_start, *args, **kwargs)

                start_line, start_col = linecol(o, start)
                end_line, end_col = linecol(o, end)
                start_mark = Mark(name, start, start_line, start_col, o, start)
                end_mark = Mark(name, end, end_line, end_col, o, start)

                return node_type(r, start_mark, end_mark), end
            return internal

        def wrap_parser(parser, node_type):
            def internal(o, start, *args, **kwargs):
                r, end = parser(o, start, *args, **kwargs)

                start_line, start_col = linecol(o, start)
                end_line, end_col = linecol(o, end)
                start_mark = Mark(name, start, start_line, start_col, o, start)
                end_mark = Mark(name, end, end_line, end_col, o, start)

                return node_type(r, start_mark, end_mark), end
            return internal

        self.parse_string = wrap_parser(self.parse_string, unicode_node)
        self.parse_array = wrap_obj_parser(self.parse_array, list_node)
        self.parse_object = wrap_obj_parser(self.parse_object,
                                            ordered_dict_node)

        # Not thread safe, but need to patch this for loading marks onto object
        # keys.
        json.decoder.scanstring = self.parse_string

        # Need to hook the python scanner because the C scanner doesn't have
        # a hookable method to parse_string.
        self.scan_once = py_make_scanner(self)
Beispiel #4
0
	def __init__(self, *arguments, **keywords):
		JSONDecoder.__init__(self, *arguments, **keywords)
		self.parse_object=vscript_parse_object
		self.parse_array=vscript_parse_array
		self.scan_once=py_make_scanner(self)
 def __init__(self, **kwargs):
     json.JSONDecoder.__init__(self, object_hook=_from_json, **kwargs)
     # Use the custom JSONArray
     self.parse_array = self.JSONArray
     # Use the python implemenation of the scanner
     self.scan_once = py_make_scanner(self) 
        def __init__(self, *args, **kwargs):
            json.JSONDecoder.__init__(self, *args, **kwargs)
            self.parse_string = _parse_string

            # we need to recreate the internal scan function ..
            self.scan_once = scanner.py_make_scanner(self)
Beispiel #7
0
        def __init__(self, *args, **kwargs):
            _myjson.JSONDecoder.__init__(self, *args, **kwargs)

            # reset scanner to python-based one using python scanstring
            self.parse_string = decoder.py_scanstring
            self.scan_once = scanner.py_make_scanner(self)
Beispiel #8
0
    def __init__(self, *args, **kwargs):
        json.JSONDecoder.__init__(self, *args, **kwargs)
        self.parse_string = _parse_string

        # we need to recreate the internal scan function ..
        self.scan_once = scanner.py_make_scanner(self)
Beispiel #9
0
        def __init__(self, *args, **kwargs):
            _myjson.JSONDecoder.__init__(self, *args, **kwargs)

            # reset scanner to python-based one using python scanstring
            self.parse_string = decoder.py_scanstring
            self.scan_once = scanner.py_make_scanner(self)
 def __init__(self, *args, **kwargs):
     super(ForgivingDecoder, self).__init__(*args, **kwargs)
     self.parse_string = forgiving_scanstring
     self.scan_once = py_make_scanner(self)