@@ -65,8 +65,8 @@ cdef class Packer(object):
65
65
self .pk.buf_size = buf_size
66
66
self .pk.length = 0
67
67
68
- def __init__ (self , default = None , encoding = ' utf-8' , unicode_errors = ' strict' , use_float = False ):
69
- self .use_float = use_float
68
+ def __init__ (self , default = None , encoding = ' utf-8' , unicode_errors = ' strict' , use_single_float = False ):
69
+ self .use_float = use_single_float
70
70
if default is not None :
71
71
if not PyCallable_Check(default):
72
72
raise TypeError (" default must be a callable." )
@@ -177,10 +177,11 @@ def pack(object o, object stream, default=None, encoding='utf-8', unicode_errors
177
177
packer = Packer(default = default, encoding = encoding, unicode_errors = unicode_errors)
178
178
stream.write(packer.pack(o))
179
179
180
- def packb (object o , default = None , encoding = ' utf-8' , unicode_errors = ' strict' ):
180
+ def packb (object o , default = None , encoding = ' utf-8' , unicode_errors = ' strict' , use_single_float = False ):
181
181
"""
182
182
pack o and return packed bytes."""
183
- packer = Packer(default = default, encoding = encoding, unicode_errors = unicode_errors)
183
+ packer = Packer(default = default, encoding = encoding, unicode_errors = unicode_errors,
184
+ use_single_float = use_single_float)
184
185
return packer.pack(o)
185
186
186
187
@@ -286,8 +287,8 @@ cdef class Unpacker(object):
286
287
287
288
`unicode_errors` is used for decoding bytes.
288
289
289
- `max_buffer_size` limits size of data waiting unpacked. 0 means unlimited
290
- (default).
290
+ `max_buffer_size` limits size of data waiting unpacked.
291
+ 0 means system's INT_MAX (default).
291
292
Raises `BufferFull` exception when it is insufficient.
292
293
You shoud set this parameter when unpacking data from untrasted source.
293
294
@@ -340,11 +341,11 @@ cdef class Unpacker(object):
340
341
raise ValueError (" `file_like.read` must be a callable." )
341
342
if not max_buffer_size:
342
343
max_buffer_size = INT_MAX
344
+ if read_size > max_buffer_size:
345
+ raise ValueError (" read_size should be less or equal to max_buffer_size" )
343
346
if not read_size:
344
347
read_size = min (max_buffer_size, 1024 ** 2 )
345
348
self .max_buffer_size = max_buffer_size
346
- if read_size > max_buffer_size:
347
- raise ValueError (" read_size should be less or equal to max_buffer_size" )
348
349
self .read_size = read_size
349
350
self .buf = < char * > malloc(read_size)
350
351
if self .buf == NULL :
@@ -427,18 +428,15 @@ cdef class Unpacker(object):
427
428
self .buf_size = buf_size
428
429
self .buf_tail = tail + _buf_len
429
430
430
- # prepare self.buf from file_like
431
- cdef fill_buffer(self ):
432
- if self .file_like is not None :
433
- next_bytes = self .file_like_read(
434
- max (self .read_size,
435
- self .max_buffer_size - (self .buf_tail - self .buf_head)
436
- ))
437
- if next_bytes:
438
- self .append_buffer(PyBytes_AsString(next_bytes),
439
- PyBytes_Size(next_bytes))
440
- else :
441
- self .file_like = None
431
+ cdef read_from_file(self ):
432
+ next_bytes = self .file_like_read(
433
+ min (self .read_size,
434
+ self .max_buffer_size - (self .buf_tail - self .buf_head)
435
+ ))
436
+ if next_bytes:
437
+ self .append_buffer(PyBytes_AsString(next_bytes), PyBytes_Size(next_bytes))
438
+ else :
439
+ self .file_like = None
442
440
443
441
cpdef _unpack(self , bool construct):
444
442
cdef int ret
@@ -448,7 +446,7 @@ cdef class Unpacker(object):
448
446
return
449
447
elif ret == 0 :
450
448
if self .file_like is not None :
451
- self .fill_buffer ()
449
+ self .read_from_file ()
452
450
continue
453
451
raise StopIteration (" No more unpack data." )
454
452
else :
0 commit comments