@@ -178,7 +178,7 @@ def __init__(self, buf, offset):
178178 self ._buf = buf
179179 self ._offset = offset
180180 self ._implicit_offset = 0
181-
181+
182182 def __repr__ (self ):
183183 return "Block(buf={!r}, offset={!r})" .format (self ._buf , self ._offset )
184184
@@ -196,10 +196,10 @@ def declare_field(self, type, name, offset=None, length=None):
196196 - `offset`: A number.
197197 - `length`: (Optional) A number. For (w)strings, length in chars.
198198 """
199- if offset == None :
199+ if offset is None :
200200 offset = self ._implicit_offset
201- if length == None :
202201
202+ if length is None :
203203 def no_length_handler ():
204204 f = getattr (self , "unpack_" + type )
205205 return f (offset )
@@ -246,11 +246,11 @@ def explicit_length_handler():
246246 self ._implicit_offset = offset + 16
247247 elif type == "binary" :
248248 self ._implicit_offset = offset + length
249- elif type == "string" and length != None :
249+ elif type == "string" and length is not None :
250250 self ._implicit_offset = offset + length
251- elif type == "wstring" and length != None :
251+ elif type == "wstring" and length is not None :
252252 self ._implicit_offset = offset + (2 * length )
253- elif "string" in type and length == None :
253+ elif "string" in type and length is None :
254254 raise ParseException ("Implicit offset not supported "
255255 "for dynamic length strings" )
256256 else :
@@ -484,12 +484,12 @@ def unpack_wstring(self, offset, length):
484484 Throws:
485485 - `UnicodeDecodeError`
486486 """
487+ start = self ._offset + offset
488+ end = self ._offset + offset + 2 * length
487489 try :
488- return bytes (self ._buf [self ._offset + offset :self ._offset + offset + \
489- 2 * length ]).decode ("utf16" )
490- except AttributeError : # already a 'str' ?
491- return bytes (self ._buf [self ._offset + offset :self ._offset + offset + \
492- 2 * length ]).decode ("utf16" )
490+ return bytes (self ._buf [start :end ]).decode ("utf16" )
491+ except AttributeError : # already a 'str' ?
492+ return bytes (self ._buf [start :end ]).decode ('utf16' )
493493
494494 def unpack_dosdate (self , offset ):
495495 """
0 commit comments