@@ -8,6 +8,10 @@ MessagePack for Python
8
8
9
9
.. image :: https://secure.travis-ci.org/msgpack/msgpack-python.png
10
10
:target: https://travis-ci.org/#!/msgpack/msgpack-python
11
+
12
+ .. image :: https://pypip.in/version/msgpack-python/badge.svg
13
+ :target: https://pypi.python.org/pypi/msgpack-python/
14
+ :alt: Latest Version
11
15
12
16
What's this
13
17
------------
@@ -52,6 +56,8 @@ It is non-string binary like Python 3's ``bytes``.
52
56
To use *bin * type for packing ``bytes ``, pass ``use_bin_type=True `` to
53
57
packer argument.
54
58
59
+ .. code-block :: pycon
60
+
55
61
>>> import msgpack
56
62
>>> packed = msgpack.packb([b'spam', u'egg'], use_bin_type=True)
57
63
>>> msgpack.unpackb(packed, encoding='utf-8')
@@ -62,6 +68,8 @@ binary can be unpacked by unpackers supporting msgpack-2.0.
62
68
63
69
To use *ext * type, pass ``msgpack.ExtType `` object to packer.
64
70
71
+ .. code-block :: pycon
72
+
65
73
>>> import msgpack
66
74
>>> packed = msgpack.packb(msgpack.ExtType(42, b'xyzzy'))
67
75
>>> msgpack.unpackb(packed)
@@ -95,15 +103,17 @@ msgpack provides ``dumps`` and ``loads`` as alias for compatibility with
95
103
``pack `` and ``dump `` packs to file-like object.
96
104
``unpack `` and ``load `` unpacks from file-like object.
97
105
98
- ::
106
+ .. code-block :: pycon
99
107
100
108
>>> import msgpack
101
109
>>> msgpack.packb([1, 2, 3])
102
110
'\x93\x01\x02\x03'
103
111
>>> msgpack.unpackb(_)
104
112
[1, 2, 3]
105
113
106
- ``unpack `` unpacks msgpack's array to Python's list, but can unpack to tuple::
114
+ ``unpack `` unpacks msgpack's array to Python's list, but can unpack to tuple:
115
+
116
+ .. code-block :: pycon
107
117
108
118
>>> msgpack.unpackb(b'\x93\x01\x02\x03', use_list=False)
109
119
(1, 2, 3)
@@ -119,7 +129,7 @@ Streaming unpacking
119
129
``Unpacker `` is a "streaming unpacker". It unpacks multiple objects from one
120
130
stream (or from bytes provided through its ``feed `` method).
121
131
122
- ::
132
+ .. code-block :: python
123
133
124
134
import msgpack
125
135
from io import BytesIO
@@ -141,7 +151,7 @@ Packing/unpacking of custom data type
141
151
It is also possible to pack/unpack custom data types. Here is an example for
142
152
``datetime.datetime ``.
143
153
144
- ::
154
+ .. code-block :: python
145
155
146
156
import datetime
147
157
@@ -175,6 +185,8 @@ Extended types
175
185
176
186
It is also possible to pack/unpack custom data types using the msgpack 2.0 feature.
177
187
188
+ .. code-block :: pycon
189
+
178
190
>>> import msgpack
179
191
>>> import array
180
192
>>> def default(obj):
@@ -209,7 +221,7 @@ in a map, can be unpacked or skipped individually.
209
221
Each of these methods may optionally write the packed data it reads to a
210
222
callback function:
211
223
212
- ::
224
+ .. code-block :: python
213
225
214
226
from io import BytesIO
215
227
0 commit comments