Skip to content

Commit

Permalink
kimchi: Renaming project from pump to kimchi
Browse files Browse the repository at this point in the history
  • Loading branch information
warrenspe committed Oct 8, 2016
1 parent 560cd31 commit 9e1ebcf
Show file tree
Hide file tree
Showing 35 changed files with 102 additions and 99 deletions.
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions pump/headers/pump.h → kimchi/headers/kimchi.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __PUMP_H
#define __PUMP_H 1
#ifndef __KIMCHI_H
#define __KIMCHI_H 1

///
// Serializable Type Definitions
Expand Down Expand Up @@ -74,13 +74,13 @@
#include "utils/serialize.c"


// pump.c Function Prototypes
static PyObject *deflate(PyObject *, PyObject *);
static PyObject *inflate(PyObject *, PyObject *);
// kimchi.c Function Prototypes
static PyObject *dumps(PyObject *, PyObject *);
static PyObject *loads(PyObject *, PyObject *);
#if PY_MAJOR_VERSION == 2
void initpump(void);
void initkimchi(void);
#else
PyMODINIT_FUNC PyInit_pump(void);
PyMODINIT_FUNC PyInit_kimchi(void);
#endif

#endif
2 changes: 1 addition & 1 deletion pump/headers/serialize.h → kimchi/headers/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ PyObject *deserialize(UserBuffer *);

// Note, we do not include utils/serialize.c here because it requires all of our serializers to be defined, while
// this file is included before them as they could in turn require access to the serialize and deserialize functions
// Thusly, utils/serialize.c is included in headers/pump.h
// Thusly, utils/serialize.c is included near the end of headers/kimchi.h
File renamed without changes.
42 changes: 21 additions & 21 deletions pump/pump.c → kimchi/kimchi.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* pump.c: A library used to serialize/deserialize certain python objects.
* kimchi.c: A library used to serialize/deserialize certain python objects.
* Copyright (C) 2016 Warren Spencer [email protected]
* This program is free software: you can redistribute it and/or modify
Expand All @@ -22,7 +22,7 @@
* [Type][Size][Serialization]
*
* Type: 1 byte.
* Bitflag representing what type was serialized here. See pump.h for type definitions.
* Bitflag representing what type was serialized here. See headers/kimchi.h for type definitions.
*
* Size: X bytes.
* The number of bytes the size field consumes is determined by the first byte which has its first bit set to 1.
Expand All @@ -42,18 +42,18 @@
/* DevNote: To extend this library with the capability to serialize further objects, the following steps must be taken.
* Follow the existing conventions in place in each of the files when making changes.
*
* 1. Add a new entry to pump/headers/pump.h: Type Definitions.
* 2. Add an entry to if block chain in pump/utils/types.c discerning whether a generic python object is of your type.
* 3. Add cases to the switches in pump/utils/serialize.c to serialize and deserialize objects of your type.
* 4. Add a new file to pump/serializers/ to serialize & deserialize your type.
* 1. Add a new entry to kimchi/headers/kimchi.h: Type Definitions.
* 2. Add an entry to if block chain in kimchi/utils/types.c discerning whether a generic python object is of your type.
* 3. Add cases to the switches in kimchi/utils/serialize.c to serialize and deserialize objects of your type.
* 4. Add a new file to kimchi/serializers/ to serialize & deserialize your type.
* Ensure that the Python Object returned from your deserialization has a ref count of 1.
* 5. Add a new unit test for your type to the pump/tests/ directory.
* 5. Add a new unit test for your type to the kimchi/tests/ directory.
* It will be automatically included in the unit tests.
*/

#include "headers/pump.h"
#include "headers/kimchi.h"

static PyObject *deflate(PyObject *self, PyObject *args) {
static PyObject *dumps(PyObject *self, PyObject *args) {
/* API function which serializes a python object.
*
* Inputs: self - Unused. The required `self` parameter of any python-visible function.
Expand All @@ -80,13 +80,13 @@ static PyObject *deflate(PyObject *self, PyObject *args) {
return obj;
}

static PyObject *inflate(PyObject *self, PyObject *args) {
static PyObject *loads(PyObject *self, PyObject *args) {
/* API function which deserializes a python object.
*
* Inputs: self - Unused. The required `self` parameter of any python-visible function.
* args - Positional arguments passed to the function.
*
* Outputs: A copy of the original Python object serialized by the deflate function, or NULL if an error occurs.
* Outputs: A copy of the original Python object serialized by the dumps function, or NULL if an error occurs.
*/

PyObject *obj;
Expand All @@ -108,31 +108,31 @@ static PyObject *inflate(PyObject *self, PyObject *args) {
return obj;
}

static PyMethodDef pumpMethods[] = {
{"deflate", (PyCFunction) deflate, METH_VARARGS, "Serialize a python object as a string."},
{"inflate", (PyCFunction) inflate, METH_VARARGS, "Deserialize a string as a python object."},
static PyMethodDef kimchiMethods[] = {
{"dumps", (PyCFunction) dumps, METH_VARARGS, "Serialize a python object as a string."},
{"loads", (PyCFunction) loads, METH_VARARGS, "Deserialize a string as a python object."},
{NULL, NULL, 0, NULL} /* sentinel */
};

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef pumpDef = {
static struct PyModuleDef kimchiDef = {
PyModuleDef_HEAD_INIT,
"pump",
"kimchi",
"Provides serialization capabilities for most built in objects",
-1,
pumpMethods,
kimchiMethods,
NULL,
NULL,
NULL,
NULL
};

PyMODINIT_FUNC PyInit_pump(void) {
return PyModule_Create(&pumpDef);
PyMODINIT_FUNC PyInit_kimchi(void) {
return PyModule_Create(&kimchiDef);
}

#else
void initpump(void) {
Py_InitModule("pump", pumpMethods);
void initkimchi(void) {
Py_InitModule("kimchi", kimchiMethods);
}
#endif
4 changes: 2 additions & 2 deletions pump/serializers/bool.c → kimchi/serializers/bool.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* bool.c: A file containing functions used by pump.c to serialize Python Booleans.
* bool.c: A file containing functions used by kimchi.c to serialize Python Booleans.
* Copyright (C) 2016 Warren Spencer [email protected]
* This program is free software: you can redistribute it and/or modify
Expand All @@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "headers/pump.h"
#include "headers/kimchi.h"

// Function Prototypes
int serializeBool(char **, unsigned long long *);
Expand Down
4 changes: 2 additions & 2 deletions pump/serializers/bytes.c → kimchi/serializers/bytes.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* bytes.c: A file containing functions used by pump.c to serialize `bytes` objects and Python2 strings.
* bytes.c: A file containing functions used by kimchi.c to serialize `bytes` objects and Python2 strings.
* Copyright (C) 2016 Warren Spencer [email protected]
* This program is free software: you can redistribute it and/or modify
Expand All @@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "headers/pump.h"
#include "headers/kimchi.h"

// Function prototypes
int serializeBytes(PyObject *, char **, unsigned long long *);
Expand Down
4 changes: 2 additions & 2 deletions pump/serializers/dict.c → kimchi/serializers/dict.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* dict.c: A file containing functions used by pump.c to serialize Python Dictionaries.
* dict.c: A file containing functions used by kimchi.c to serialize Python Dictionaries.
* Copyright (C) 2016 Warren Spencer [email protected]
* This program is free software: you can redistribute it and/or modify
Expand All @@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "headers/pump.h"
#include "headers/kimchi.h"

// Function Prototypes
int serializeDict(PyObject *, char **, unsigned long long *);
Expand Down
4 changes: 2 additions & 2 deletions pump/serializers/float.c → kimchi/serializers/float.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* float.c: A file containing functions used by pump.c to serialize floats.
* float.c: A file containing functions used by kimchi.c to serialize floats.
* Copyright (C) 2016 Warren Spencer [email protected]
* This program is free software: you can redistribute it and/or modify
Expand All @@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "headers/pump.h"
#include "headers/kimchi.h"

// Function Prototypes
int serializeFloat(PyObject *, char **, unsigned long long *);
Expand Down
4 changes: 2 additions & 2 deletions pump/serializers/int.c → kimchi/serializers/int.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* int.c: A file containing functions used by pump.c to serialize integers.
* int.c: A file containing functions used by kimchi.c to serialize integers.
* Copyright (C) 2016 Warren Spencer [email protected]
* This program is free software: you can redistribute it and/or modify
Expand All @@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "headers/pump.h"
#include "headers/kimchi.h"

// Function Prototypes
static unsigned long long _numBytesToSerialize(unsigned long long);
Expand Down
4 changes: 2 additions & 2 deletions pump/serializers/list.c → kimchi/serializers/list.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* list.c: A file containing functions used by pump.c to serialize Python Lists.
* list.c: A file containing functions used by kimchi.c to serialize Python Lists.
* Copyright (C) 2016 Warren Spencer [email protected]
* This program is free software: you can redistribute it and/or modify
Expand All @@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "headers/pump.h"
#include "headers/kimchi.h"

// Function Prototypes
static void _freeSerializeListBuffers(char **, unsigned long long *, unsigned long long);
Expand Down
4 changes: 2 additions & 2 deletions pump/serializers/long.c → kimchi/serializers/long.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* long.c: A file containing functions used by pump.c to serialize longs.
* long.c: A file containing functions used by kimchi.c to serialize longs.
* Copyright (C) 2016 Warren Spencer [email protected]
* This program is free software: you can redistribute it and/or modify
Expand All @@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "headers/pump.h"
#include "headers/kimchi.h"
#include "longintrepr.h"

// Function Prototypes
Expand Down
4 changes: 2 additions & 2 deletions pump/serializers/none.c → kimchi/serializers/none.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* none.c: A file containing functions used by pump.c to serialize Python None's.
* none.c: A file containing functions used by kimchi.c to serialize Python None's.
* Copyright (C) 2016 Warren Spencer [email protected]
* This program is free software: you can redistribute it and/or modify
Expand All @@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "headers/pump.h"
#include "headers/kimchi.h"

// Function Prototypes
int serializeNone(char **, unsigned long long *);
Expand Down
4 changes: 2 additions & 2 deletions pump/serializers/set.c → kimchi/serializers/set.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* set.c: A file containing functions used by pump.c to serialize Python Sets and FrozenSets.
* set.c: A file containing functions used by kimchi.c to serialize Python Sets and FrozenSets.
* Copyright (C) 2016 Warren Spencer [email protected]
* This program is free software: you can redistribute it and/or modify
Expand All @@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "headers/pump.h"
#include "headers/kimchi.h"

// Function Prototypes
static void _freeSerializeSetBuffers(char **, unsigned long long *, unsigned long long, PyObject *);
Expand Down
4 changes: 2 additions & 2 deletions pump/serializers/tuple.c → kimchi/serializers/tuple.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* tuple.c: A file containing functions used by pump.c to serialize Python Tuples.
* tuple.c: A file containing functions used by kimchi.c to serialize Python Tuples.
* Copyright (C) 2016 Warren Spencer [email protected]
* This program is free software: you can redistribute it and/or modify
Expand All @@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "headers/pump.h"
#include "headers/kimchi.h"

// Function Prototypes
static void _freeSerializeTupleBuffers(char **, unsigned long long *, unsigned long long);
Expand Down
4 changes: 2 additions & 2 deletions pump/serializers/unicode.c → kimchi/serializers/unicode.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* unicode.c: A file containing functions used by pump.c to serialize unicode strings.
* unicode.c: A file containing functions used by kimchi.c to serialize unicode strings.
* Copyright (C) 2016 Warren Spencer [email protected]
* This program is free software: you can redistribute it and/or modify
Expand All @@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "headers/pump.h"
#include "headers/kimchi.h"

// Function prototypes
int serializeUnicode(PyObject *, char **, unsigned long long *);
Expand Down
26 changes: 13 additions & 13 deletions pump/tests/__init__.py → kimchi/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
sys.path.append('..')

# Projet imports
import pump
import kimchi

# Python 2 & 3 compatibility
if sys.version_info.major >= 3:
Expand All @@ -24,47 +24,47 @@
TEST_DIR = os.path.split(os.path.dirname(os.path.realpath(__file__)))[-1]
PICKLE_CMP = 0

class PumpTestCase(unittest.TestCase):
class KimchiTestCase(unittest.TestCase):

def __test(self, obj, ser, deser):
serName = ser.__name__
deserName = deser.__name__

try:
before = time.time()
deflated = ser(obj)
dumped = ser(obj)
serElapsed = time.time() - before
except Exception as e:
self.fail("Error in (%s) serializing %s:\n%s" % (serName, repr(obj), str(e)))

try:
before = time.time()
inflated = deser(deflated)
loaded = deser(dumped)
deserElapsed = time.time() - before
except Exception as e:
self.fail("Error in (%s) deserializing %s (serialized: %r):\n%s"
% (deserName, repr(obj), repr(deflated), str(e)))
if obj != inflated:
self.fail("%s != %s; using %s, %s" % (repr(obj), repr(inflated), serName, deserName))
% (deserName, repr(obj), repr(dumped), str(e)))
if obj != loaded:
self.fail("%s != %s; using %s, %s" % (repr(obj), repr(loaded), serName, deserName))

return serElapsed, deserElapsed, len(deflated)
return serElapsed, deserElapsed, len(dumped)


def _test(self, toTest):
for obj in toTest:
pumpSerElapsed, pumpDeserElapsed, pumpSerializedSize = self.__test(obj, pump.deflate, pump.inflate)
kimSerElapsed, kimDeserElapsed, kimSerializedSize = self.__test(obj, kimchi.dumps, kimchi.loads)
if PICKLE_CMP:
pickleSerElapsed, pickleDeserElapsed, pickleSerializedSize = self.__test(obj, pickle.dumps, pickle.loads)
print("\n".join(("",
"%s:" % repr(obj)[:125],
"Time to serialize:",
" pump: %s" % pumpSerElapsed,
" kimchi: %s" % kimSerElapsed,
" pickle: %s" % pickleSerElapsed,
"Time to deserialize:",
" pump: %s" % pumpDeserElapsed,
" kimchi: %s" % kimDeserElapsed,
" pickle: %s" % pickleDeserElapsed,
"Serialization length:",
" pump: %s" % pumpSerializedSize,
" kimchi: %s" % kimSerializedSize,
" pickle: %s" % pickleSerializedSize
)))

Expand Down Expand Up @@ -96,7 +96,7 @@ def _runSuite(testSuite, verbosity):
def main():
global PICKLE_CMP

parser = argparse.ArgumentParser(description="Execute pump Unit Tests")
parser = argparse.ArgumentParser(description="Execute kimchi Unit Tests")
parser.add_argument("testFiles", nargs="*")
parser.add_argument("--verbosity", nargs="?", choices=['1', '2'], default=1)
args = parser.parse_args()
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions pump/tests/test_bool.py → kimchi/tests/test_bool.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Project imports
import pump
import kimchi
import tests

class TestBool(tests.PumpTestCase):
class TestBool(tests.KimchiTestCase):

def testBool(self):
toTest = [
Expand Down
Loading

0 comments on commit 9e1ebcf

Please sign in to comment.