diff options
author | INADA Naoki <songofacandy@gmail.com> | 2013-10-17 08:44:25 +0900 |
---|---|---|
committer | INADA Naoki <songofacandy@gmail.com> | 2013-10-17 08:44:25 +0900 |
commit | 171c5381135bdfc6db154100ad5a9913955408a7 (patch) | |
tree | ea47f538fd263e11e2a077e7ce56a170cd8ce55f | |
parent | da12e177a31445492795f4003bbe0328645325b2 (diff) | |
download | msgpack-python-171c5381135bdfc6db154100ad5a9913955408a7.tar.gz |
refactoring.
-rw-r--r-- | msgpack/__init__.py | 22 | ||||
-rw-r--r-- | msgpack/_packer.pyx | 27 | ||||
-rw-r--r-- | msgpack/fallback.py | 17 |
3 files changed, 21 insertions, 45 deletions
diff --git a/msgpack/__init__.py b/msgpack/__init__.py index 77f6b81..5ce531e 100644 --- a/msgpack/__init__.py +++ b/msgpack/__init__.py @@ -4,14 +4,32 @@ from msgpack.exceptions import * import os if os.environ.get('MSGPACK_PUREPYTHON'): - from msgpack.fallback import pack, packb, Packer, unpack, unpackb, Unpacker + from msgpack.fallback import Packer, unpack, unpackb, Unpacker else: try: - from msgpack._packer import pack, packb, Packer + from msgpack._packer import Packer from msgpack._unpacker import unpack, unpackb, Unpacker except ImportError: from msgpack.fallback import pack, packb, Packer, unpack, unpackb, Unpacker + +def pack(o, stream, **kwargs): + """ + Pack object `o` and write it to `stream` + + See :class:`Packer` for options. + """ + packer = Packer(**kwargs) + stream.write(packer.pack(o)) + +def packb(o, **kwargs): + """ + Pack object `o` and return packed bytes + + See :class:`Packer` for options. + """ + return Packer(**kwargs).pack(o) + # alias for compatibility to simplejson/marshal/pickle. load = unpack loads = unpackb diff --git a/msgpack/_packer.pyx b/msgpack/_packer.pyx index b9ae505..7082445 100644 --- a/msgpack/_packer.pyx +++ b/msgpack/_packer.pyx @@ -13,6 +13,7 @@ cdef extern from "pack.h": char* buf size_t length size_t buf_size + bint use_bin_type int msgpack_pack_int(msgpack_packer* pk, int d) int msgpack_pack_nil(msgpack_packer* pk) @@ -68,7 +69,6 @@ cdef class Packer(object): cdef char *encoding cdef char *unicode_errors cdef bool use_float - cdef bool use_bin_type cdef bint autoreset def __cinit__(self): @@ -254,28 +254,3 @@ cdef class Packer(object): def bytes(self): """Return buffer content.""" return PyBytes_FromStringAndSize(self.pk.buf, self.pk.length) - - -def pack(object o, object stream, - default=None, str encoding='utf-8', str unicode_errors='strict', - bint use_single_float=False, bint use_bin_type=False): - """ - pack an object `o` and write it to stream) - - See :class:`Packer` for options. - """ - packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors, - use_single_float=use_single_float, use_bin_type=use_bin_type) - stream.write(packer.pack(o)) - -def packb(object o, - default=None, str encoding='utf-8', str unicode_errors='strict', - bint use_single_float=False, bint use_bin_type=False): - """ - pack o and return packed bytes - - See :class:`Packer` for options. - """ - packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors, - use_single_float=use_single_float, use_bin_type=use_bin_type) - return packer.pack(o) diff --git a/msgpack/fallback.py b/msgpack/fallback.py index 8f9d646..3bf0489 100644 --- a/msgpack/fallback.py +++ b/msgpack/fallback.py @@ -60,23 +60,6 @@ TYPE_RAW = 3 DEFAULT_RECURSE_LIMIT=511 -def pack(o, stream, **kwargs): - """ - Pack object `o` and write it to `stream` - - See :class:`Packer` for options. - """ - packer = Packer(**kwargs) - stream.write(packer.pack(o)) - -def packb(o, **kwargs): - """ - Pack object `o` and return packed bytes - - See :class:`Packer` for options. - """ - return Packer(**kwargs).pack(o) - def unpack(stream, **kwargs): """ Unpack an object from `stream`. |