ujson.c
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2011-2012, ESN Social Software AB and Jonas Tarnstrom
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007     * Redistributions of source code must retain the above copyright
00008       notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright
00010       notice, this list of conditions and the following disclaimer in the
00011       documentation and/or other materials provided with the distribution.
00012     * Neither the name of the ESN Social Software AB nor the
00013       names of its contributors may be used to endorse or promote products
00014       derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL ESN SOCIAL SOFTWARE AB OR JONAS TARNSTROM BE LIABLE 
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Portions of code from:
00028 MODP_ASCII - Ascii transformations (upper/lower, etc)
00029 http://code.google.com/p/stringencoders/
00030 Copyright (c) 2007  Nick Galbreath -- nickg [at] modp [dot] com. All rights reserved.
00031 
00032 */
00033 
00034 #include "py_defines.h"
00035 #include "version.h"
00036 
00037 /* objToJSON */
00038 PyObject* objToJSON(PyObject* self, PyObject *args, PyObject *kwargs);
00039 void initObjToJSON(void);
00040 
00041 /* JSONToObj */
00042 PyObject* JSONToObj(PyObject* self, PyObject *arg);
00043 
00044 /* objToJSONFile */
00045 PyObject* objToJSONFile(PyObject* self, PyObject *args, PyObject *kwargs);
00046 
00047 /* JSONFileToObj */
00048 PyObject* JSONFileToObj(PyObject* self, PyObject *file);
00049 
00050 
00051 static PyMethodDef ujsonMethods[] = {
00052     {"encode", (PyCFunction) objToJSON, METH_VARARGS | METH_KEYWORDS, "Converts arbitrary object recursivly into JSON. Use ensure_ascii=false to output UTF-8. Pass in double_precision to alter the maximum digit precision with doubles"},
00053     {"decode", (PyCFunction) JSONToObj, METH_O, "Converts JSON as string to dict object structure"},
00054     {"dumps", (PyCFunction) objToJSON, METH_VARARGS | METH_KEYWORDS,  "Converts arbitrary object recursivly into JSON. Use ensure_ascii=false to output UTF-8"},
00055     {"loads", (PyCFunction) JSONToObj, METH_O,  "Converts JSON as string to dict object structure"},
00056     {"dump", (PyCFunction) objToJSONFile, METH_VARARGS | METH_KEYWORDS, "Converts arbitrary object recursively into JSON file. Use ensure_ascii=false to output UTF-8"},
00057     {"load", (PyCFunction) JSONFileToObj, METH_O, "Converts JSON as file to dict object structure"},
00058     {NULL, NULL, 0, NULL}       /* Sentinel */
00059 };
00060 
00061 #if PY_MAJOR_VERSION >= 3
00062 
00063 static struct PyModuleDef moduledef = {
00064     PyModuleDef_HEAD_INIT,
00065     "ujson",
00066     0,              /* m_doc */
00067     -1,             /* m_size */
00068     ujsonMethods,   /* m_methods */
00069     NULL,           /* m_reload */
00070     NULL,           /* m_traverse */
00071     NULL,           /* m_clear */
00072     NULL            /* m_free */
00073 };
00074 
00075 #define PYMODINITFUNC       PyObject *PyInit_ujson(void)
00076 #define PYMODULE_CREATE()   PyModule_Create(&moduledef)
00077 #define MODINITERROR        return NULL
00078 
00079 #else
00080 
00081 #define PYMODINITFUNC       PyMODINIT_FUNC initujson(void)
00082 #define PYMODULE_CREATE()   Py_InitModule("ujson", ujsonMethods)
00083 #define MODINITERROR        return
00084 
00085 #endif
00086 
00087 PYMODINITFUNC
00088 {
00089     PyObject *module;
00090     PyObject *version_string;
00091 
00092     initObjToJSON();   
00093     module = PYMODULE_CREATE();
00094 
00095     if (module == NULL)
00096     {
00097         MODINITERROR;
00098     }
00099 
00100     version_string = PyString_FromString (UJSON_VERSION);
00101     PyModule_AddObject (module, "__version__", version_string);
00102 
00103 #if PY_MAJOR_VERSION >= 3
00104     return module;
00105 #endif
00106 }


rosbridge_library
Author(s): Jonathan Mace
autogenerated on Thu Jan 2 2014 11:53:35