From 171c5381135bdfc6db154100ad5a9913955408a7 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Thu, 17 Oct 2013 08:44:25 +0900 Subject: refactoring. --- msgpack/__init__.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'msgpack/__init__.py') 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 -- cgit v1.2.1 From 85eaff344b74092ccf076ba2465e9bdb1537409b Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Thu, 17 Oct 2013 09:15:19 +0900 Subject: Add bin type support for fallback Unpacker. --- msgpack/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'msgpack/__init__.py') diff --git a/msgpack/__init__.py b/msgpack/__init__.py index 5ce531e..7f0519e 100644 --- a/msgpack/__init__.py +++ b/msgpack/__init__.py @@ -10,7 +10,7 @@ else: from msgpack._packer import Packer from msgpack._unpacker import unpack, unpackb, Unpacker except ImportError: - from msgpack.fallback import pack, packb, Packer, unpack, unpackb, Unpacker + from msgpack.fallback import Packer, unpack, unpackb, Unpacker def pack(o, stream, **kwargs): -- cgit v1.2.1 From d9439204c77a0ab58248c0b78237f16c4496647c Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Thu, 17 Oct 2013 11:29:36 +0900 Subject: Add ext type support to fallback.Unpacker. --- msgpack/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'msgpack/__init__.py') diff --git a/msgpack/__init__.py b/msgpack/__init__.py index 7f0519e..79107b6 100644 --- a/msgpack/__init__.py +++ b/msgpack/__init__.py @@ -2,6 +2,10 @@ from msgpack._version import version from msgpack.exceptions import * +from collections import namedtuple + +ExtType = namedtuple('ExtType', 'code data') + import os if os.environ.get('MSGPACK_PUREPYTHON'): from msgpack.fallback import Packer, unpack, unpackb, Unpacker -- cgit v1.2.1