Skip to content

Commit 328369e

Browse files
committed
pep8 friendly.
1 parent 4cde7f0 commit 328369e

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

msgpack/fallback.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Fallback pure Python implementation of msgpack
1+
"""Fallback pure Python implementation of msgpack"""
22

33
import sys
44
import array
@@ -49,11 +49,11 @@ def getvalue(self):
4949
def pack(o, stream, default=None, encoding='utf-8', unicode_errors='strict'):
5050
""" Pack object `o` and write it to `stream` """
5151
packer = Packer(default=default, encoding=encoding,
52-
unicode_errors=unicode_errors)
52+
unicode_errors=unicode_errors)
5353
stream.write(packer.pack(o))
5454

5555
def packb(o, default=None, encoding='utf-8', unicode_errors='struct',
56-
use_single_float=False):
56+
use_single_float=False):
5757
""" Pack object `o` and return packed bytes """
5858
packer = Packer(default=default,
5959
encoding=encoding,
@@ -62,28 +62,30 @@ def packb(o, default=None, encoding='utf-8', unicode_errors='struct',
6262
return packer.pack(o)
6363

6464
def unpack(stream, object_hook=None, list_hook=None, use_list=True,
65-
encoding=None, unicode_errors='strict',
66-
object_pairs_hook=None):
65+
encoding=None, unicode_errors='strict',
66+
object_pairs_hook=None):
6767
""" Unpack an object from `stream`.
6868
6969
Raises `ExtraData` when `stream` has extra bytes. """
7070
unpacker = Unpacker(stream, object_hook=object_hook, list_hook=list_hook,
71-
use_list=use_list, encoding=encoding, unicode_errors=unicode_errors,
72-
object_pairs_hook=object_pairs_hook)
71+
use_list=use_list,
72+
encoding=encoding, unicode_errors=unicode_errors,
73+
object_pairs_hook=object_pairs_hook)
7374
ret = unpacker._fb_unpack()
7475
if unpacker._fb_got_extradata():
7576
raise ExtraData(ret, unpacker._fb_get_extradata())
7677
return ret
7778

7879
def unpackb(packed, object_hook=None, list_hook=None, use_list=True,
79-
encoding=None, unicode_errors='strict',
80-
object_pairs_hook=None):
80+
encoding=None, unicode_errors='strict',
81+
object_pairs_hook=None):
8182
""" Unpack an object from `packed`.
8283
8384
Raises `ExtraData` when `packed` contains extra bytes. """
8485
unpacker = Unpacker(None, object_hook=object_hook, list_hook=list_hook,
85-
use_list=use_list, encoding=encoding, unicode_errors=unicode_errors,
86-
object_pairs_hook=object_pairs_hook)
86+
use_list=use_list,
87+
encoding=encoding, unicode_errors=unicode_errors,
88+
object_pairs_hook=object_pairs_hook)
8789
unpacker.feed(packed)
8890
ret = unpacker._fb_unpack()
8991
if unpacker._fb_got_extradata():
@@ -141,8 +143,8 @@ class Unpacker(object):
141143
"""
142144

143145
def __init__(self, file_like=None, read_size=0, use_list=True,
144-
object_hook=None, object_pairs_hook=None, list_hook=None,
145-
encoding=None, unicode_errors='strict', max_buffer_size=0):
146+
object_hook=None, object_pairs_hook=None, list_hook=None,
147+
encoding=None, unicode_errors='strict', max_buffer_size=0):
146148
if file_like is None:
147149
self._fb_feeding = True
148150
else:
@@ -174,8 +176,8 @@ def __init__(self, file_like=None, read_size=0, use_list=True,
174176
if object_pairs_hook is not None and not callable(object_pairs_hook):
175177
raise ValueError('`object_pairs_hook` is not callable')
176178
if object_hook is not None and object_pairs_hook is not None:
177-
raise ValueError("object_pairs_hook and object_hook are mutually "+
178-
"exclusive")
179+
raise ValueError("object_pairs_hook and object_hook are mutually "
180+
"exclusive")
179181

180182
def feed(self, next_bytes):
181183
if isinstance(next_bytes, array.array):
@@ -394,7 +396,7 @@ def read_map_header(self, write_bytes=None):
394396

395397
class Packer(object):
396398
def __init__(self, default=None, encoding='utf-8', unicode_errors='strict',
397-
use_single_float=False, autoreset=True):
399+
use_single_float=False, autoreset=True):
398400
self.use_float = use_single_float
399401
self.autoreset = autoreset
400402
self.encoding = encoding
@@ -404,6 +406,7 @@ def __init__(self, default=None, encoding='utf-8', unicode_errors='strict',
404406
if not callable(default):
405407
raise TypeError("default must be callable")
406408
self._default = default
409+
407410
def _pack(self, obj, nest_limit=DEFAULT_RECURSE_LIMIT):
408411
if nest_limit < 0:
409412
raise PackValueError("recursion limit exceeded")
@@ -461,10 +464,11 @@ def _pack(self, obj, nest_limit=DEFAULT_RECURSE_LIMIT):
461464
return
462465
if isinstance(obj, dict):
463466
return self._fb_pack_map_pairs(len(obj), obj.iteritems(),
464-
nest_limit - 1)
467+
nest_limit - 1)
465468
if self._default is not None:
466469
return self._pack(self._default(obj), nest_limit - 1)
467470
raise TypeError("Cannot serialize %r" % obj)
471+
468472
def pack(self, obj):
469473
self._pack(obj)
470474
ret = self.buffer.getvalue()
@@ -473,6 +477,7 @@ def pack(self, obj):
473477
elif USING_STRINGBUILDER:
474478
self.buffer = StringIO(ret)
475479
return ret
480+
476481
def pack_map_pairs(self, pairs):
477482
self._fb_pack_map_pairs(len(pairs), pairs)
478483
ret = self.buffer.getvalue()
@@ -481,6 +486,7 @@ def pack_map_pairs(self, pairs):
481486
elif USING_STRINGBUILDER:
482487
self.buffer = StringIO(ret)
483488
return ret
489+
484490
def pack_array_header(self, n):
485491
self._fb_pack_array_header(n)
486492
ret = self.buffer.getvalue()
@@ -489,6 +495,7 @@ def pack_array_header(self, n):
489495
elif USING_STRINGBUILDER:
490496
self.buffer = StringIO(ret)
491497
return ret
498+
492499
def pack_map_header(self, n):
493500
self._fb_pack_map_header(n)
494501
ret = self.buffer.getvalue()
@@ -497,6 +504,7 @@ def pack_map_header(self, n):
497504
elif USING_STRINGBUILDER:
498505
self.buffer = StringIO(ret)
499506
return ret
507+
500508
def _fb_pack_array_header(self, n):
501509
if n <= 0x0f:
502510
return self.buffer.write(chr(0x90 + n))
@@ -505,6 +513,7 @@ def _fb_pack_array_header(self, n):
505513
if n <= 0xffffffff:
506514
return self.buffer.write(struct.pack(">BI", 0xdd, n))
507515
raise PackValueError("Array is too large")
516+
508517
def _fb_pack_map_header(self, n):
509518
if n <= 0x0f:
510519
return self.buffer.write(chr(0x80 + n))
@@ -513,12 +522,15 @@ def _fb_pack_map_header(self, n):
513522
if n <= 0xffffffff:
514523
return self.buffer.write(struct.pack(">BI", 0xdf, n))
515524
raise PackValueError("Dict is too large")
525+
516526
def _fb_pack_map_pairs(self, n, pairs, nest_limit=DEFAULT_RECURSE_LIMIT):
517527
self._fb_pack_map_header(n)
518528
for (k, v) in pairs:
519529
self._pack(k, nest_limit - 1)
520530
self._pack(v, nest_limit - 1)
531+
521532
def bytes(self):
522533
return self.buffer.getvalue()
534+
523535
def reset(self):
524536
self.buffer = StringIO()

0 commit comments

Comments
 (0)