[Python-modules-commits] [ujson] 01/02: Imported Upstream version 1.33

Sandro Tosi morph at moszumanska.debian.org
Mon Jun 29 20:19:12 UTC 2015


This is an automated email from the git hooks/post-receive script.

morph pushed a commit to branch master
in repository ujson.

commit 628970a053837ab149cfdecd022b5913c8e0d06b
Author: Sandro Tosi <morph at debian.org>
Date:   Mon Jun 29 16:19:59 2015 -0400

    Imported Upstream version 1.33
---
 MANIFEST.in                         |    9 +
 PKG-INFO                            |  189 ++
 README.rst                          |  168 ++
 lib/ultrajson.h                     |  310 ++++
 lib/ultrajsondec.c                  |  897 ++++++++++
 lib/ultrajsonenc.c                  |  924 ++++++++++
 python/JSONtoObj.c                  |  245 +++
 python/objToJSON.c                  |  939 ++++++++++
 python/py_defines.h                 |   52 +
 python/ujson.c                      |  112 ++
 python/version.h                    |   38 +
 setup.cfg                           |    5 +
 setup.py                            |   77 +
 tests/sample.json                   | 3315 +++++++++++++++++++++++++++++++++++
 tests/tests.py                      |  986 +++++++++++
 ujson.egg-info/PKG-INFO             |  189 ++
 ujson.egg-info/SOURCES.txt          |   22 +
 ujson.egg-info/dependency_links.txt |    1 +
 ujson.egg-info/top_level.txt        |    1 +
 19 files changed, 8479 insertions(+)

diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..275e06a
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,9 @@
+include README.rst
+include MANIFEST.in
+include setup.py
+include tests/tests.py
+include tests/sample.json
+include lib/*.c
+include lib/*.h
+include python/*.c
+include python/*.h
\ No newline at end of file
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..56b5c5d
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,189 @@
+Metadata-Version: 1.0
+Name: ujson
+Version: 1.33
+Summary: Ultra fast JSON encoder and decoder for Python
+Home-page: http://www.esn.me
+Author: Jonas Tarnstrom
+Author-email: jonas.tarnstrom at esn.me
+License: BSD License
+Download-URL: http://github.com/esnme/ultrajson
+Description: UltraJSON
+        =============
+        UltraJSON is an ultra fast JSON encoder and decoder written in pure C with bindings for Python 2.5+ and 3.
+        
+        For a more painless day to day C/C++ JSON decoder experience please checkout ujson4c_, based on UltraJSON.
+        
+        .. _ujson4c: http://github.com/esnme/ujson4c/
+        
+        | Please checkout the rest of the projects in the Ultra series:
+        | http://github.com/esnme/ultramemcache
+        | http://github.com/esnme/ultramysql
+        
+        To install it just run Pip as usual::
+        
+            $ pip install ujson
+        
+        ============
+        Usage
+        ============
+        May be used as a drop in replacement for most other JSON parsers for Python::
+        
+            >>> import ujson
+            >>> ujson.dumps([{"key": "value"}, 81, True])
+            '[{"key":"value"},81,true]'
+            >>> ujson.loads("""[{"key": "value"}, 81, true]""")
+            [{u'key': u'value'}, 81, True]
+            
+        ~~~~~~~~~~~~~~~
+        Encoder options
+        ~~~~~~~~~~~~~~~    
+        encode_html_chars
+        -----------------
+        Used to enable special encoding of "unsafe" HTML characters into safer Unicode sequences. Default is false::
+        
+            >>> ujson.dumps("<script>John&Doe", encode_html_chars=True)
+            '"\\u003cscript\\u003eJohn\\u0026Doe"'
+        
+        ensure_ascii
+        -------------
+        Limits output to ASCII and escapes all extended characters above 127. Default is true. If your end format supports UTF-8 setting this option to false is highly recommended to save space::
+        
+            >>> ujson.dumps(u"\xe5\xe4\xf6")
+            '"\\u00e5\\u00e4\\u00f6"'
+            >>> ujson.dumps(u"\xe5\xe4\xf6", ensure_ascii=False)
+            '"\xc3\xa5\xc3\xa4\xc3\xb6"'
+        
+        double_precision
+        ----------------
+        Controls how many decimals to encode for double or decimal values. Default is 9::
+        
+            >>> ujson.dumps(math.pi)
+            '3.1415926536'
+            >>> ujson.dumps(math.pi, double_precision=1)
+            '3.1'
+            >>> ujson.dumps(math.pi, double_precision=0)
+            '3'
+            >>> ujson.dumps(math.pi, double_precision=4)
+            '3.1416'
+            
+        ~~~~~~~~~~~~~~~~
+        Decoders options
+        ~~~~~~~~~~~~~~~~    
+        precise_float
+        -------------
+        Set to enable usage of higher precision (strtod) function when decoding string to double values. Default is to use fast but less precise builtin functionality::
+        
+            >>> ujson.loads("4.56")
+            4.5600000000000005
+            >>> ujson.loads("4.56", precise_float=True)
+            4.5599999999999996
+        
+            
+        ============
+        Benchmarks
+        ============
+        *UltraJSON* calls/sec compared to three other popular JSON parsers with performance gain specified below each.
+        
+        ~~~~~~~~~~~~~
+        Test machine:
+        ~~~~~~~~~~~~~
+        Linux version 2.6.32-131.0.15.el6.x86_64
+        
+        ~~~~~~~~~
+        Versions:
+        ~~~~~~~~~
+        
+        - ujson: 1.21
+        - simplejson: 2.6.2
+        - cjson: 1.05
+        - yajl: 0.3.5
+        - Python: Python 2.6.6 (r266:84292, Jul 20 2011, 10:22:43)
+        
+        
+        +-----------------------------------------+--------+------------+--------+---------+
+        |                                         | ujson  | simplejson | cjson  | yajl    |
+        +=========================================+========+============+========+=========+
+        | Array with 256 utf-8 strings            |        |            |        |         |
+        +-----------------------------------------+--------+------------+--------+---------+
+        | Encode                                  | 4090,74|    899,39  |83,86   | 3189,86 |
+        +-----------------------------------------+--------+------------+--------+---------+
+        |                                         |        |       4,55 |48,78   | 1,28    |
+        +-----------------------------------------+--------+------------+--------+---------+
+        | Decode                                  | 863,29 |     586,15 |201,61  | 352,48  |
+        +-----------------------------------------+--------+------------+--------+---------+
+        |                                         |        |      1,47  | 4,28   | 2,45    |
+        +-----------------------------------------+--------+------------+--------+---------+
+        | Medium complex object                   |        |            |        |         |
+        +-----------------------------------------+--------+------------+--------+---------+
+        | Encode                                  | 9750,37|   1377,15  |1512,06 | 3341,91 |
+        +-----------------------------------------+--------+------------+--------+---------+
+        |                                         |        |     7,08   | 6,45   | 2,92    |
+        +-----------------------------------------+--------+------------+--------+---------+
+        | Decode                                  | 5576,75|   4247,16  | 3587,83| 2850,13 |
+        +-----------------------------------------+--------+------------+--------+---------+
+        |                                         |        |        1,31|   1,55 |   1,96  |
+        +-----------------------------------------+--------+------------+--------+---------+
+        | Array with 256 strings                  |        |            |        |         |
+        +-----------------------------------------+--------+------------+--------+---------+
+        | Encode                                  |17998,01|  12954,46  |8715,02 | 15924,35|
+        +-----------------------------------------+--------+------------+--------+---------+
+        |                                         |        |        1,39|    2,07|    1,13 |
+        +-----------------------------------------+--------+------------+--------+---------+
+        | Decode                                  |14540,71|  19696,13  |14908,46| 9547,14 |
+        +-----------------------------------------+--------+------------+--------+---------+
+        |                                         |        |       0,74 |   0,98 |   1,52  |
+        +-----------------------------------------+--------+------------+--------+---------+
+        | Array with 256 doubles                  |        |            |        |         |
+        +-----------------------------------------+--------+------------+--------+---------+
+        | Encode                                  | 2185,20|   1466,87  | 1956,99| 3421,10 |
+        +-----------------------------------------+--------+------------+--------+---------+
+        |                                         |        |        1,49|   1,12 |  0,64   |
+        +-----------------------------------------+--------+------------+--------+---------+
+        | Decode                                  |16062,01|  8990,50   | 9743,40|8331,74  |
+        +-----------------------------------------+--------+------------+--------+---------+
+        |                                         |        |        1,79|    1,65|   1,93  |
+        +-----------------------------------------+--------+------------+--------+---------+
+        | Array with 256 True values              |        |            |        |         |
+        +-----------------------------------------+--------+------------+--------+---------+
+        | Encode                                  |69767,60|  25202,56  |41145,99|64330,76 |
+        +-----------------------------------------+--------+------------+--------+---------+
+        |                                         |        |       2,77 |  1,70  |  1,08   |
+        +-----------------------------------------+--------+------------+--------+---------+
+        |Decode                                   |91416,02|  56439,97  |54918,09| 42786,02|
+        +-----------------------------------------+--------+------------+--------+---------+
+        |                                         |        |        1,62|   1,66 |  2,14   |
+        +-----------------------------------------+--------+------------+--------+---------+
+        | Array with 256 dict{string, int} pairs  |        |            |        |         |
+        +-----------------------------------------+--------+------------+--------+---------+
+        |                                         |        |            |        |         |
+        +-----------------------------------------+--------+------------+--------+---------+
+        | Encode                                  |11307,54|   1830,45  | 2720,90| 7725,56 |
+        +-----------------------------------------+--------+------------+--------+---------+
+        |                                         |        |        6,18|   4,16 |  1,46   |
+        +-----------------------------------------+--------+------------+--------+---------+
+        | Decode                                  |8695,94 |  7572,89   | 6076,71|5231,32  |
+        +-----------------------------------------+--------+------------+--------+---------+
+        |                                         |        |        1,15|    1,43|   1,66  |
+        +-----------------------------------------+--------+------------+--------+---------+
+        | Dict with 256 arrays with 256 dict      |        |            |        |         |
+        +-----------------------------------------+--------+------------+--------+---------+
+        | Encode                                  | 37,76  |    4,88    | 10,49  | 27,62   |
+        +-----------------------------------------+--------+------------+--------+---------+
+        |                                         |        |        7,74|    3,60| 1,37    |
+        +-----------------------------------------+--------+------------+--------+---------+
+        |Decode                                   |  17,70 |    15,56   | 11,25  | 12,00   |
+        +-----------------------------------------+--------+------------+--------+---------+
+        |                                         |        |        1,14|    1,57|    1,47 |
+        +-----------------------------------------+--------+------------+--------+---------+
+        
+Platform: any
+Classifier: Development Status :: 5 - Production/Stable
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: BSD License
+Classifier: Programming Language :: C
+Classifier: Programming Language :: Python :: 2.4
+Classifier: Programming Language :: Python :: 2.5
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.2
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..67a3a63
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,168 @@
+UltraJSON
+=============
+UltraJSON is an ultra fast JSON encoder and decoder written in pure C with bindings for Python 2.5+ and 3.
+
+For a more painless day to day C/C++ JSON decoder experience please checkout ujson4c_, based on UltraJSON.
+
+.. _ujson4c: http://github.com/esnme/ujson4c/
+
+| Please checkout the rest of the projects in the Ultra series:
+| http://github.com/esnme/ultramemcache
+| http://github.com/esnme/ultramysql
+
+To install it just run Pip as usual::
+
+    $ pip install ujson
+
+============
+Usage
+============
+May be used as a drop in replacement for most other JSON parsers for Python::
+
+    >>> import ujson
+    >>> ujson.dumps([{"key": "value"}, 81, True])
+    '[{"key":"value"},81,true]'
+    >>> ujson.loads("""[{"key": "value"}, 81, true]""")
+    [{u'key': u'value'}, 81, True]
+    
+~~~~~~~~~~~~~~~
+Encoder options
+~~~~~~~~~~~~~~~    
+encode_html_chars
+-----------------
+Used to enable special encoding of "unsafe" HTML characters into safer Unicode sequences. Default is false::
+
+    >>> ujson.dumps("<script>John&Doe", encode_html_chars=True)
+    '"\\u003cscript\\u003eJohn\\u0026Doe"'
+
+ensure_ascii
+-------------
+Limits output to ASCII and escapes all extended characters above 127. Default is true. If your end format supports UTF-8 setting this option to false is highly recommended to save space::
+
+    >>> ujson.dumps(u"\xe5\xe4\xf6")
+    '"\\u00e5\\u00e4\\u00f6"'
+    >>> ujson.dumps(u"\xe5\xe4\xf6", ensure_ascii=False)
+    '"\xc3\xa5\xc3\xa4\xc3\xb6"'
+
+double_precision
+----------------
+Controls how many decimals to encode for double or decimal values. Default is 9::
+
+    >>> ujson.dumps(math.pi)
+    '3.1415926536'
+    >>> ujson.dumps(math.pi, double_precision=1)
+    '3.1'
+    >>> ujson.dumps(math.pi, double_precision=0)
+    '3'
+    >>> ujson.dumps(math.pi, double_precision=4)
+    '3.1416'
+    
+~~~~~~~~~~~~~~~~
+Decoders options
+~~~~~~~~~~~~~~~~    
+precise_float
+-------------
+Set to enable usage of higher precision (strtod) function when decoding string to double values. Default is to use fast but less precise builtin functionality::
+
+    >>> ujson.loads("4.56")
+    4.5600000000000005
+    >>> ujson.loads("4.56", precise_float=True)
+    4.5599999999999996
+
+    
+============
+Benchmarks
+============
+*UltraJSON* calls/sec compared to three other popular JSON parsers with performance gain specified below each.
+
+~~~~~~~~~~~~~
+Test machine:
+~~~~~~~~~~~~~
+Linux version 2.6.32-131.0.15.el6.x86_64
+
+~~~~~~~~~
+Versions:
+~~~~~~~~~
+
+- ujson: 1.21
+- simplejson: 2.6.2
+- cjson: 1.05
+- yajl: 0.3.5
+- Python: Python 2.6.6 (r266:84292, Jul 20 2011, 10:22:43)
+
+
++-----------------------------------------+--------+------------+--------+---------+
+|                                         | ujson  | simplejson | cjson  | yajl    |
++=========================================+========+============+========+=========+
+| Array with 256 utf-8 strings            |        |            |        |         |
++-----------------------------------------+--------+------------+--------+---------+
+| Encode                                  | 4090,74|    899,39  |83,86   | 3189,86 |
++-----------------------------------------+--------+------------+--------+---------+
+|                                         |        |       4,55 |48,78   | 1,28    |
++-----------------------------------------+--------+------------+--------+---------+
+| Decode                                  | 863,29 |     586,15 |201,61  | 352,48  |
++-----------------------------------------+--------+------------+--------+---------+
+|                                         |        |      1,47  | 4,28   | 2,45    |
++-----------------------------------------+--------+------------+--------+---------+
+| Medium complex object                   |        |            |        |         |
++-----------------------------------------+--------+------------+--------+---------+
+| Encode                                  | 9750,37|   1377,15  |1512,06 | 3341,91 |
++-----------------------------------------+--------+------------+--------+---------+
+|                                         |        |     7,08   | 6,45   | 2,92    |
++-----------------------------------------+--------+------------+--------+---------+
+| Decode                                  | 5576,75|   4247,16  | 3587,83| 2850,13 |
++-----------------------------------------+--------+------------+--------+---------+
+|                                         |        |        1,31|   1,55 |   1,96  |
++-----------------------------------------+--------+------------+--------+---------+
+| Array with 256 strings                  |        |            |        |         |
++-----------------------------------------+--------+------------+--------+---------+
+| Encode                                  |17998,01|  12954,46  |8715,02 | 15924,35|
++-----------------------------------------+--------+------------+--------+---------+
+|                                         |        |        1,39|    2,07|    1,13 |
++-----------------------------------------+--------+------------+--------+---------+
+| Decode                                  |14540,71|  19696,13  |14908,46| 9547,14 |
++-----------------------------------------+--------+------------+--------+---------+
+|                                         |        |       0,74 |   0,98 |   1,52  |
++-----------------------------------------+--------+------------+--------+---------+
+| Array with 256 doubles                  |        |            |        |         |
++-----------------------------------------+--------+------------+--------+---------+
+| Encode                                  | 2185,20|   1466,87  | 1956,99| 3421,10 |
++-----------------------------------------+--------+------------+--------+---------+
+|                                         |        |        1,49|   1,12 |  0,64   |
++-----------------------------------------+--------+------------+--------+---------+
+| Decode                                  |16062,01|  8990,50   | 9743,40|8331,74  |
++-----------------------------------------+--------+------------+--------+---------+
+|                                         |        |        1,79|    1,65|   1,93  |
++-----------------------------------------+--------+------------+--------+---------+
+| Array with 256 True values              |        |            |        |         |
++-----------------------------------------+--------+------------+--------+---------+
+| Encode                                  |69767,60|  25202,56  |41145,99|64330,76 |
++-----------------------------------------+--------+------------+--------+---------+
+|                                         |        |       2,77 |  1,70  |  1,08   |
++-----------------------------------------+--------+------------+--------+---------+
+|Decode                                   |91416,02|  56439,97  |54918,09| 42786,02|
++-----------------------------------------+--------+------------+--------+---------+
+|                                         |        |        1,62|   1,66 |  2,14   |
++-----------------------------------------+--------+------------+--------+---------+
+| Array with 256 dict{string, int} pairs  |        |            |        |         |
++-----------------------------------------+--------+------------+--------+---------+
+|                                         |        |            |        |         |
++-----------------------------------------+--------+------------+--------+---------+
+| Encode                                  |11307,54|   1830,45  | 2720,90| 7725,56 |
++-----------------------------------------+--------+------------+--------+---------+
+|                                         |        |        6,18|   4,16 |  1,46   |
++-----------------------------------------+--------+------------+--------+---------+
+| Decode                                  |8695,94 |  7572,89   | 6076,71|5231,32  |
++-----------------------------------------+--------+------------+--------+---------+
+|                                         |        |        1,15|    1,43|   1,66  |
++-----------------------------------------+--------+------------+--------+---------+
+| Dict with 256 arrays with 256 dict      |        |            |        |         |
++-----------------------------------------+--------+------------+--------+---------+
+| Encode                                  | 37,76  |    4,88    | 10,49  | 27,62   |
++-----------------------------------------+--------+------------+--------+---------+
+|                                         |        |        7,74|    3,60| 1,37    |
++-----------------------------------------+--------+------------+--------+---------+
+|Decode                                   |  17,70 |    15,56   | 11,25  | 12,00   |
++-----------------------------------------+--------+------------+--------+---------+
+|                                         |        |        1,14|    1,57|    1,47 |
++-----------------------------------------+--------+------------+--------+---------+
diff --git a/lib/ultrajson.h b/lib/ultrajson.h
new file mode 100644
index 0000000..787cd4c
--- /dev/null
+++ b/lib/ultrajson.h
@@ -0,0 +1,310 @@
+/*
+Copyright (c) 2011-2013, ESN Social Software AB and Jonas Tarnstrom
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+    * Neither the name of the ESN Social Software AB nor the
+      names of its contributors may be used to endorse or promote products
+      derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL ESN SOCIAL SOFTWARE AB OR JONAS TARNSTROM BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+Portions of code from MODP_ASCII - Ascii transformations (upper/lower, etc)
+http://code.google.com/p/stringencoders/
+Copyright (c) 2007  Nick Galbreath -- nickg [at] modp [dot] com. All rights reserved.
+
+Numeric decoder derived from from TCL library
+http://www.opensource.apple.com/source/tcl/tcl-14/tcl/license.terms
+ * Copyright (c) 1988-1993 The Regents of the University of California.
+ * Copyright (c) 1994 Sun Microsystems, Inc.
+*/
+
+/*
+Ultra fast JSON encoder and decoder
+Developed by Jonas Tarnstrom (jonas at esn.me).
+
+Encoder notes:
+------------------
+
+:: Cyclic references ::
+Cyclic referenced objects are not detected.
+Set JSONObjectEncoder.recursionMax to suitable value or make sure input object
+tree doesn't have cyclic references.
+
+*/
+
+#ifndef __ULTRAJSON_H__
+#define __ULTRAJSON_H__
+
+#include <stdio.h>
+#include <wchar.h>
+
+// Don't output any extra whitespaces when encoding
+#define JSON_NO_EXTRA_WHITESPACE
+
+// Max decimals to encode double floating point numbers with
+#ifndef JSON_DOUBLE_MAX_DECIMALS
+#define JSON_DOUBLE_MAX_DECIMALS 15
+#endif
+
+// Max recursion depth, default for encoder
+#ifndef JSON_MAX_RECURSION_DEPTH
+#define JSON_MAX_RECURSION_DEPTH 1024
+#endif
+
+// Max recursion depth, default for decoder
+#ifndef JSON_MAX_OBJECT_DEPTH
+#define JSON_MAX_OBJECT_DEPTH 1024
+#endif
+
+/*
+Dictates and limits how much stack space for buffers UltraJSON will use before resorting to provided heap functions */
+#ifndef JSON_MAX_STACK_BUFFER_SIZE
+#define JSON_MAX_STACK_BUFFER_SIZE 131072
+#endif
+
+#ifdef _WIN32
+
+typedef __int64 JSINT64;
+typedef unsigned __int64 JSUINT64;
+
+typedef __int32 JSINT32;
+typedef unsigned __int32 JSUINT32;
+typedef unsigned __int8 JSUINT8;
+typedef unsigned __int16 JSUTF16;
+typedef unsigned __int32 JSUTF32;
+typedef __int64 JSLONG;
+
+#define EXPORTFUNCTION __declspec(dllexport)
+
+#define FASTCALL_MSVC __fastcall
+#define FASTCALL_ATTR
+#define INLINE_PREFIX __inline
+
+#else
+
+#include <stdint.h>
+typedef int64_t JSINT64;
+typedef uint64_t JSUINT64;
+
+typedef int32_t JSINT32;
+typedef uint32_t JSUINT32;
+
+#define FASTCALL_MSVC
+
+#if !defined __x86_64__
+#define FASTCALL_ATTR __attribute__((fastcall))
+#else
+#define FASTCALL_ATTR
+#endif
+
+#define INLINE_PREFIX inline
+
+typedef uint8_t JSUINT8;
+typedef uint16_t JSUTF16;
+typedef uint32_t JSUTF32;
+
+typedef int64_t JSLONG;
+
+#define EXPORTFUNCTION
+#endif
+
+#if !(defined(__LITTLE_ENDIAN__) || defined(__BIG_ENDIAN__))
+
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#define __LITTLE_ENDIAN__
+#else
+
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+#define __BIG_ENDIAN__
+#endif
+
+#endif
+
+#endif
+
+#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
+#error "Endianess not supported"
+#endif
+
+enum JSTYPES
+{
+  JT_NULL,        // NULL
+  JT_TRUE,        //boolean true
+  JT_FALSE,       //boolean false
+  JT_INT,         //(JSINT32 (signed 32-bit))
+  JT_LONG,        //(JSINT64 (signed 64-bit))
+  JT_DOUBLE,    //(double)
+  JT_UTF8,        //(char 8-bit)
+  JT_ARRAY,       // Array structure
+  JT_OBJECT,    // Key/Value structure
+  JT_INVALID,    // Internal, do not return nor expect
+};
+
+typedef void * JSOBJ;
+typedef void * JSITER;
+
+typedef struct __JSONTypeContext
+{
+  int type;
+  void *prv;
+} JSONTypeContext;
+
+/*
+Function pointer declarations, suitable for implementing UltraJSON */
+typedef void (*JSPFN_ITERBEGIN)(JSOBJ obj, JSONTypeContext *tc);
+typedef int (*JSPFN_ITERNEXT)(JSOBJ obj, JSONTypeContext *tc);
+typedef void (*JSPFN_ITEREND)(JSOBJ obj, JSONTypeContext *tc);
+typedef JSOBJ (*JSPFN_ITERGETVALUE)(JSOBJ obj, JSONTypeContext *tc);
+typedef char *(*JSPFN_ITERGETNAME)(JSOBJ obj, JSONTypeContext *tc, size_t *outLen);
+typedef void *(*JSPFN_MALLOC)(size_t size);
+typedef void (*JSPFN_FREE)(void *pptr);
+typedef void *(*JSPFN_REALLOC)(void *base, size_t size);
+
+typedef struct __JSONObjectEncoder
+{
+  void (*beginTypeContext)(JSOBJ obj, JSONTypeContext *tc);
+  void (*endTypeContext)(JSOBJ obj, JSONTypeContext *tc);
+  const char *(*getStringValue)(JSOBJ obj, JSONTypeContext *tc, size_t *_outLen);
+  JSINT64 (*getLongValue)(JSOBJ obj, JSONTypeContext *tc);
+  JSINT32 (*getIntValue)(JSOBJ obj, JSONTypeContext *tc);
+  double (*getDoubleValue)(JSOBJ obj, JSONTypeContext *tc);
+
+  /*
+  Begin iteration of an iteratable object (JS_ARRAY or JS_OBJECT)
+  Implementor should setup iteration state in ti->prv
+  */
+  JSPFN_ITERBEGIN iterBegin;
+
+  /*
+  Retrieve next object in an iteration. Should return 0 to indicate iteration has reached end or 1 if there are more items.
+  Implementor is responsible for keeping state of the iteration. Use ti->prv fields for this
+  */
+  JSPFN_ITERNEXT iterNext;
+
+  /*
+  Ends the iteration of an iteratable object.
+  Any iteration state stored in ti->prv can be freed here
+  */
+  JSPFN_ITEREND iterEnd;
+
+  /*
+  Returns a reference to the value object of an iterator
+  The is responsible for the life-cycle of the returned string. Use iterNext/iterEnd and ti->prv to keep track of current object
+  */
+  JSPFN_ITERGETVALUE iterGetValue;
+
+  /*
+  Return name of iterator.
+  The is responsible for the life-cycle of the returned string. Use iterNext/iterEnd and ti->prv to keep track of current object
+  */
+  JSPFN_ITERGETNAME iterGetName;
+
+  /*
+  Release a value as indicated by setting ti->release = 1 in the previous getValue call.
+  The ti->prv array should contain the necessary context to release the value
+  */
+  void (*releaseObject)(JSOBJ obj);
+
+  /* Library functions
+  Set to NULL to use STDLIB malloc,realloc,free */
+  JSPFN_MALLOC malloc;
+  JSPFN_REALLOC realloc;
+  JSPFN_FREE free;
+
+  /*
+  Configuration for max recursion, set to 0 to use default (see JSON_MAX_RECURSION_DEPTH)*/
+  int recursionMax;
+
+  /*
+  Configuration for max decimals of double floating poiunt numbers to encode (0-9) */
+  int doublePrecision;
+
+  /*
+  If true output will be ASCII with all characters above 127 encoded as \uXXXX. If false output will be UTF-8 or what ever charset strings are brought as */
+  int forceASCII;
+
+  /*
+  If true, '<', '>', and '&' characters will be encoded as \u003c, \u003e, and \u0026, respectively. If false, no special encoding will be used. */
+  int encodeHTMLChars;
+
+  /*
+  Set to an error message if error occured */
+  const char *errorMsg;
+  JSOBJ errorObj;
+
+  /* Buffer stuff */
+  char *start;
+  char *offset;
+  char *end;
+  int heap;
+  int level;
+
+} JSONObjectEncoder;
+
+
+/*
+Encode an object structure into JSON.
+
+Arguments:
+obj - An anonymous type representing the object
+enc - Function definitions for querying JSOBJ type
+buffer - Preallocated buffer to store result in. If NULL function allocates own buffer
+cbBuffer - Length of buffer (ignored if buffer is NULL)
+
+Returns:
+Encoded JSON object as a null terminated char string.
+
+NOTE:
+If the supplied buffer wasn't enough to hold the result the function will allocate a new buffer.
+Life cycle of the provided buffer must still be handled by caller.
+
+If the return value doesn't equal the specified buffer caller must release the memory using
+JSONObjectEncoder.free or free() as specified when calling this function.
+*/
+EXPORTFUNCTION char *JSON_EncodeObject(JSOBJ obj, JSONObjectEncoder *enc, char *buffer, size_t cbBuffer);
+
+
+
+typedef struct __JSONObjectDecoder
+{
+  JSOBJ (*newString)(void *prv, wchar_t *start, wchar_t *end);
+  void (*objectAddKey)(void *prv, JSOBJ obj, JSOBJ name, JSOBJ value);
+  void (*arrayAddItem)(void *prv, JSOBJ obj, JSOBJ value);
+  JSOBJ (*newTrue)(void *prv);
+  JSOBJ (*newFalse)(void *prv);
+  JSOBJ (*newNull)(void *prv);
+  JSOBJ (*newObject)(void *prv);
+  JSOBJ (*newArray)(void *prv);
+  JSOBJ (*newInt)(void *prv, JSINT32 value);
+  JSOBJ (*newLong)(void *prv, JSINT64 value);
+  JSOBJ (*newDouble)(void *prv, double value);
+  void (*releaseObject)(void *prv, JSOBJ obj);
+  JSPFN_MALLOC malloc;
+  JSPFN_FREE free;
+  JSPFN_REALLOC realloc;
+  char *errorStr;
+  char *errorOffset;
+  int preciseFloat;
+  void *prv;
+} JSONObjectDecoder;
+
+EXPORTFUNCTION JSOBJ JSON_DecodeObject(JSONObjectDecoder *dec, const char *buffer, size_t cbBuffer);
+
+#endif
diff --git a/lib/ultrajsondec.c b/lib/ultrajsondec.c
new file mode 100644
index 0000000..c344341
--- /dev/null
+++ b/lib/ultrajsondec.c
@@ -0,0 +1,897 @@
+/*
+Copyright (c) 2011-2013, ESN Social Software AB and Jonas Tarnstrom
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+* Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+* Neither the name of the ESN Social Software AB nor the
+names of its contributors may be used to endorse or promote products
+derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL ESN SOCIAL SOFTWARE AB OR JONAS TARNSTROM BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+Portions of code from MODP_ASCII - Ascii transformations (upper/lower, etc)
+http://code.google.com/p/stringencoders/
+Copyright (c) 2007  Nick Galbreath -- nickg [at] modp [dot] com. All rights reserved.
+
+Numeric decoder derived from from TCL library
+http://www.opensource.apple.com/source/tcl/tcl-14/tcl/license.terms
+* Copyright (c) 1988-1993 The Regents of the University of California.
+* Copyright (c) 1994 Sun Microsystems, Inc.
+*/
+
+#include "ultrajson.h"
+#include <math.h>
+#include <assert.h>
+#include <string.h>
+#include <limits.h>
+#include <wchar.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#ifndef TRUE
+#define TRUE 1
+#define FALSE 0
+#endif
+#ifndef NULL
+#define NULL 0
+#endif
+
+struct DecoderState
+{
+  char *start;
+  char *end;
+  wchar_t *escStart;
+  wchar_t *escEnd;
+  int escHeap;
+  int lastType;
+  JSUINT32 objDepth;
+  void *prv;
+  JSONObjectDecoder *dec;
+};
+
+JSOBJ FASTCALL_MSVC decode_any( struct DecoderState *ds) FASTCALL_ATTR;
+typedef JSOBJ (*PFN_DECODER)( struct DecoderState *ds);
+
+static JSOBJ SetError( struct DecoderState *ds, int offset, const char *message)
+{
+  ds->dec->errorOffset = ds->start + offset;
+  ds->dec->errorStr = (char *) message;
+  return NULL;
+}
+
+static void ClearError( struct DecoderState *ds)
+{
+  ds->dec->errorOffset = 0;
+  ds->dec->errorStr = NULL;
+}
+
+double createDouble(double intNeg, double intValue, double frcValue, int frcDecimalCount)
+{
+  static const double g_pow10[] = {1.0, 0.1, 0.01, 0.001, 0.0001, 0.00001, 0.000001,0.0000001, 0.00000001, 0.000000001, 0.0000000001, 0.00000000001, 0.000000000001, 0.0000000000001, 0.00000000000001, 0.000000000000001};
+  return (intValue + (frcValue * g_pow10[frcDecimalCount])) * intNeg;
+}
+
+FASTCALL_ATTR JSOBJ FASTCALL_MSVC decodePreciseFloat(struct DecoderState *ds)
+{
+  char *end;
+  double value;
+  errno = 0;
+
+  value = strtod(ds->start, &end);
+
+  if (errno == ERANGE)
+  {
+    return SetError(ds, -1, "Range error when decoding numeric as double");
+  }
+
+  ds->start = end;
+  return ds->dec->newDouble(ds->prv, value);
+}
+
+FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric (struct DecoderState *ds)
+{
+  int intNeg = 1;
+  int mantSize = 0;
+  JSUINT64 intValue;
+  int chr;
+  int decimalCount = 0;
+  double frcValue = 0.0;
+  double expNeg;
+  double expValue;
+  char *offset = ds->start;
+
+  JSUINT64 overflowLimit = LLONG_MAX;
+
+  if (*(offset) == '-')
+  {
+    offset ++;
+    intNeg = -1;
+    overflowLimit = LLONG_MIN;
+  }
+
+  // Scan integer part
+  intValue = 0;
+
+  while (1)
+  {
+    chr = (int) (unsigned char) *(offset);
+
+    switch (chr)
+    {
+      case '0':
+      case '1':
+      case '2':
+      case '3':
+      case '4':
+      case '5':
+      case '6':
+      case '7':
+      case '8':
+      case '9':
+      {
+        //FIXME: Check for arithemtic overflow here
+        //PERF: Don't do 64-bit arithmetic here unless we know we have to
+        intValue = intValue * 10ULL + (JSLONG) (chr - 48);
+
+        if (intValue > overflowLimit)
+        {
+          return SetError(ds, -1, overflowLimit == LLONG_MAX ? "Value is too big" : "Value is too small");
+        }
+
+        offset ++;
+        mantSize ++;
+        break;
+      }
+      case '.':
+      {
+        offset ++;
+        goto DECODE_FRACTION;
+        break;
+      }
+      case 'e':
+      case 'E':
+      {
+        offset ++;
+        goto DECODE_EXPONENT;
+        break;
+      }
+
+      default:
+      {
+        goto BREAK_INT_LOOP;
+        break;
+      }
+    }
+  }
+
+BREAK_INT_LOOP:
+
+  ds->lastType = JT_INT;
+  ds->start = offset;
+
+  if ((intValue >> 31))
+  {
+    return ds->dec->newLong(ds->prv, (JSINT64) (intValue * (JSINT64) intNeg));
+  }
+  else
+  {
+    return ds->dec->newInt(ds->prv, (JSINT32) (intValue * intNeg));
+  }
+
+DECODE_FRACTION:
+
+  if (ds->dec->preciseFloat)
+  {
+    return decodePreciseFloat(ds);
+  }
+
+  // Scan fraction part
+  frcValue = 0.0;
+  for (;;)
+  {
+    chr = (int) (unsigned char) *(offset);
+
+    switch (chr)
+    {
+      case '0':
+      case '1':
+      case '2':
+      case '3':
+      case '4':
+      case '5':
+      case '6':
+      case '7':
+      case '8':
+      case '9':
+      {
+        if (decimalCount < JSON_DOUBLE_MAX_DECIMALS)
+        {
+          frcValue = frcValue * 10.0 + (double) (chr - 48);
+          decimalCount ++;
+        }
+        offset ++;
+        break;
+      }
+      case 'e':
+      case 'E':
+      {
+        offset ++;
+        goto DECODE_EXPONENT;
+        break;
+      }
+      default:
+      {
+        goto BREAK_FRC_LOOP;
+      }
+    }
+  }
+
+BREAK_FRC_LOOP:
+  //FIXME: Check for arithemtic overflow here
+  ds->lastType = JT_DOUBLE;
+  ds->start = offset;
+  return ds->dec->newDouble (ds->prv, createDouble( (double) intNeg, (double) intValue, frcValue, decimalCount));
+
+DECODE_EXPONENT:
+  if (ds->dec->preciseFloat)
+  {
+    return decodePreciseFloat(ds);
+  }
+
+  expNeg = 1.0;
+
+  if (*(offset) == '-')
+  {
+    expNeg = -1.0;
+    offset ++;
+  }
+  else
+  if (*(offset) == '+')
+  {
... 7623 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/ujson.git



More information about the Python-modules-commits mailing list