Example #1
0
def _get_loads(strict=STRICT):
    if not strict:
        try:
            from simplejson import loads
        except ImportError:
            from json import loads
        return loads

    from json import decoder
    res = decoder.c_scanstring('"str"', 1)
    if type(res[0]) is unicode:
        from json import loads
        return loads

    import json as _myjson
    from json import scanner

    class MyJSONDecoder(_myjson.JSONDecoder):
        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 loads(s, *args, **kwargs):
        if 'cls' not in kwargs:
            kwargs['cls'] = MyJSONDecoder
        return _myjson.loads(s, *args, **kwargs)

    return loads
Example #2
0
File: pjson.py Project: csm/paisley
def _get_loads(strict=STRICT):
    if not strict:
        try:
            from simplejson import loads
        except ImportError:
            from json import loads
        return loads

    from json import decoder
    res = decoder.c_scanstring('"str"', 1)
    if type(res[0]) is unicode:
        from json import loads
        return loads

    import json as _myjson
    from json import scanner

    class MyJSONDecoder(_myjson.JSONDecoder):

        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 loads(s, *args, **kwargs):
        if 'cls' not in kwargs:
            kwargs['cls'] = MyJSONDecoder
        return _myjson.loads(s, *args, **kwargs)

    return loads
def parse_string(*args):
    s, pos = c_scanstring and c_scanstring(*args) or py_scanstring(*args)
    try:
        dt = DateTime(s)
        if str(dt) == s:
            return dt, pos
    except (DateError, SyntaxError, TimeError):
        pass
    return s, pos
Example #4
0
def _get_loads(strict=STRICT):
    if not strict:
        try:
            from simplejson import loads
        except ImportError:
            from json import loads
        return loads

    # If we don't have json, we can only fall back to simplejson, non-strict
    try:
        from json import decoder
    except ImportError:
        global STRICT
        STRICT = False
        from simplejson import loads
        return loads
    try:
        res = decoder.c_scanstring('"str"', 1)
    except TypeError:
        # github issue #33: pypy may not have c_scanstring
        res = decoder.scanstring('"str"', 1)

    if type(res[0]) is unicode:
        from json import loads
        return loads

    import json as _myjson
    from json import scanner

    class MyJSONDecoder(_myjson.JSONDecoder):

        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 loads(s, *args, **kwargs):
        if 'cls' not in kwargs:
            kwargs['cls'] = MyJSONDecoder
        return _myjson.loads(s, *args, **kwargs)

    return loads
Example #5
0
def _get_loads(strict=STRICT):
    if not strict:
        try:
            from simplejson import loads
        except ImportError:
            from json import loads
        return loads

    # If we don't have json, we can only fall back to simplejson, non-strict
    try:
        from json import decoder
    except ImportError:
        global STRICT
        STRICT = False
        from simplejson import loads
        return loads
    try:
        res = decoder.c_scanstring('"str"', 1)
    except TypeError:
        # github issue #33: pypy may not have c_scanstring
        res = decoder.scanstring('"str"', 1)

    if type(res[0]) is unicode:
        from json import loads
        return loads

    import json as _myjson
    from json import scanner

    class MyJSONDecoder(_myjson.JSONDecoder):
        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 loads(s, *args, **kwargs):
        if 'cls' not in kwargs:
            kwargs['cls'] = MyJSONDecoder
        return _myjson.loads(s, *args, **kwargs)

    return loads