@@ -52,6 +52,8 @@ It is non-string binary like Python 3's ``bytes``.
52
52
To use *bin * type for packing ``bytes ``, pass ``use_bin_type=True `` to
53
53
packer argument.
54
54
55
+ .. code-block :: pycon
56
+
55
57
>>> import msgpack
56
58
>>> packed = msgpack.packb([b'spam', u'egg'], use_bin_type=True)
57
59
>>> msgpack.unpackb(packed, encoding='utf-8')
@@ -62,6 +64,8 @@ binary can be unpacked by unpackers supporting msgpack-2.0.
62
64
63
65
To use *ext * type, pass ``msgpack.ExtType `` object to packer.
64
66
67
+ .. code-block :: pycon
68
+
65
69
>>> import msgpack
66
70
>>> packed = msgpack.packb(msgpack.ExtType(42, b'xyzzy'))
67
71
>>> msgpack.unpackb(packed)
@@ -95,15 +99,17 @@ msgpack provides ``dumps`` and ``loads`` as alias for compatibility with
95
99
``pack `` and ``dump `` packs to file-like object.
96
100
``unpack `` and ``load `` unpacks from file-like object.
97
101
98
- ::
102
+ .. code-block :: pycon
99
103
100
104
>>> import msgpack
101
105
>>> msgpack.packb([1, 2, 3])
102
106
'\x93\x01\x02\x03'
103
107
>>> msgpack.unpackb(_)
104
108
[1, 2, 3]
105
109
106
- ``unpack `` unpacks msgpack's array to Python's list, but can unpack to tuple::
110
+ ``unpack `` unpacks msgpack's array to Python's list, but can unpack to tuple:
111
+
112
+ .. code-block :: pycon
107
113
108
114
>>> msgpack.unpackb(b'\x93\x01\x02\x03', use_list=False)
109
115
(1, 2, 3)
@@ -119,7 +125,7 @@ Streaming unpacking
119
125
``Unpacker `` is a "streaming unpacker". It unpacks multiple objects from one
120
126
stream (or from bytes provided through its ``feed `` method).
121
127
122
- ::
128
+ .. code-block :: python
123
129
124
130
import msgpack
125
131
from io import BytesIO
@@ -141,7 +147,7 @@ Packing/unpacking of custom data type
141
147
It is also possible to pack/unpack custom data types. Here is an example for
142
148
``datetime.datetime ``.
143
149
144
- ::
150
+ .. code-block :: python
145
151
146
152
import datetime
147
153
@@ -175,6 +181,8 @@ Extended types
175
181
176
182
It is also possible to pack/unpack custom data types using the msgpack 2.0 feature.
177
183
184
+ .. code-block :: pycon
185
+
178
186
>>> import msgpack
179
187
>>> import array
180
188
>>> def default(obj):
@@ -209,7 +217,7 @@ in a map, can be unpacked or skipped individually.
209
217
Each of these methods may optionally write the packed data it reads to a
210
218
callback function:
211
219
212
- ::
220
+ .. code-block :: python
213
221
214
222
from io import BytesIO
215
223
0 commit comments