Skip to content

Commit 5abb73e

Browse files
committed
Merge pull request #119 from msabramo/patch-1
README.rst: Add code-blocks
2 parents 87b493b + 2b4a815 commit 5abb73e

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

README.rst

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ It is non-string binary like Python 3's ``bytes``.
5252
To use *bin* type for packing ``bytes``, pass ``use_bin_type=True`` to
5353
packer argument.
5454

55+
.. code-block:: pycon
56+
5557
>>> import msgpack
5658
>>> packed = msgpack.packb([b'spam', u'egg'], use_bin_type=True)
5759
>>> msgpack.unpackb(packed, encoding='utf-8')
@@ -62,6 +64,8 @@ binary can be unpacked by unpackers supporting msgpack-2.0.
6264

6365
To use *ext* type, pass ``msgpack.ExtType`` object to packer.
6466

67+
.. code-block:: pycon
68+
6569
>>> import msgpack
6670
>>> packed = msgpack.packb(msgpack.ExtType(42, b'xyzzy'))
6771
>>> msgpack.unpackb(packed)
@@ -95,15 +99,17 @@ msgpack provides ``dumps`` and ``loads`` as alias for compatibility with
9599
``pack`` and ``dump`` packs to file-like object.
96100
``unpack`` and ``load`` unpacks from file-like object.
97101

98-
::
102+
.. code-block:: pycon
99103
100104
>>> import msgpack
101105
>>> msgpack.packb([1, 2, 3])
102106
'\x93\x01\x02\x03'
103107
>>> msgpack.unpackb(_)
104108
[1, 2, 3]
105109
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
107113
108114
>>> msgpack.unpackb(b'\x93\x01\x02\x03', use_list=False)
109115
(1, 2, 3)
@@ -119,7 +125,7 @@ Streaming unpacking
119125
``Unpacker`` is a "streaming unpacker". It unpacks multiple objects from one
120126
stream (or from bytes provided through its ``feed`` method).
121127

122-
::
128+
.. code-block:: python
123129
124130
import msgpack
125131
from io import BytesIO
@@ -141,7 +147,7 @@ Packing/unpacking of custom data type
141147
It is also possible to pack/unpack custom data types. Here is an example for
142148
``datetime.datetime``.
143149

144-
::
150+
.. code-block:: python
145151
146152
import datetime
147153
@@ -175,6 +181,8 @@ Extended types
175181

176182
It is also possible to pack/unpack custom data types using the msgpack 2.0 feature.
177183

184+
.. code-block:: pycon
185+
178186
>>> import msgpack
179187
>>> import array
180188
>>> def default(obj):
@@ -209,7 +217,7 @@ in a map, can be unpacked or skipped individually.
209217
Each of these methods may optionally write the packed data it reads to a
210218
callback function:
211219

212-
::
220+
.. code-block:: python
213221
214222
from io import BytesIO
215223

0 commit comments

Comments
 (0)