00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "py_defines.h"
00035 #include "version.h"
00036
00037
00038 PyObject* objToJSON(PyObject* self, PyObject *args, PyObject *kwargs);
00039 void initObjToJSON(void);
00040
00041
00042 PyObject* JSONToObj(PyObject* self, PyObject *arg);
00043
00044
00045 PyObject* objToJSONFile(PyObject* self, PyObject *args, PyObject *kwargs);
00046
00047
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}
00059 };
00060
00061 #if PY_MAJOR_VERSION >= 3
00062
00063 static struct PyModuleDef moduledef = {
00064 PyModuleDef_HEAD_INIT,
00065 "ujson",
00066 0,
00067 -1,
00068 ujsonMethods,
00069 NULL,
00070 NULL,
00071 NULL,
00072 NULL
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 }