mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #30.
This commit is contained in:
parent
8ac579e8b5
commit
ecaa9e813b
@ -128,12 +128,19 @@ class TransferBuffer(list):
|
||||
|
||||
def pack(self, val, fmt=DWORD, start=0):
|
||||
"""
|
||||
Encode C{val} and write it to buffer.
|
||||
Encode C{val} and write it to buffer. For fmt==WORD val is
|
||||
adjusted to be in the range 0 <= val < 256**2.
|
||||
|
||||
@param fmt: See U{struct<http://docs.python.org/lib/module-struct.html>}
|
||||
@param start: Position in buffer at which to write encoded data
|
||||
"""
|
||||
self[start:start+struct.calcsize(fmt)] = [ ord(i) for i in struct.pack(fmt, val) ]
|
||||
# struct.py is fussy about packing values into a WORD. The value must be
|
||||
# between 0 and 65535 or a DeprecationWarning is raised. In the future
|
||||
# this may become an error, so it's best to take care of wrapping here.
|
||||
if fmt == WORD:
|
||||
val = val % 256**2
|
||||
self[start:start+struct.calcsize(fmt)] = \
|
||||
[ ord(i) for i in struct.pack(fmt, val) ]
|
||||
|
||||
def _normalize(self):
|
||||
""" Replace negative bytes in C{self} by 256 + byte """
|
||||
|
Loading…
x
Reference in New Issue
Block a user