@@ -43,6 +43,7 @@ def add_to(self, arg):
4343 Obj.add_to(1) # not enough arguments
4444 Obj.add_to(1, 2) # returns 3, result is not cached
4545 """
46+
4647 def __init__ (self , func ):
4748 self .func = func
4849
@@ -82,19 +83,19 @@ def dosdate(dosdate, dostime):
8283 returns: datetime.datetime or datetime.datetime.min on error
8384 """
8485 try :
85- t = ord (dosdate [1 ]) << 8
86+ t = ord (dosdate [1 ]) << 8
8687 t |= ord (dosdate [0 ])
87- day = t & 0b0000000000011111
88+ day = t & 0b0000000000011111
8889 month = (t & 0b0000000111100000 ) >> 5
89- year = (t & 0b1111111000000000 ) >> 9
90+ year = (t & 0b1111111000000000 ) >> 9
9091 year += 1980
9192
92- t = ord (dostime [1 ]) << 8
93+ t = ord (dostime [1 ]) << 8
9394 t |= ord (dostime [0 ])
94- sec = t & 0b0000000000011111
95- sec *= 2
96- minute = (t & 0b0000011111100000 ) >> 5
97- hour = (t & 0b1111100000000000 ) >> 11
95+ sec = t & 0b0000000000011111
96+ sec *= 2
97+ minute = (t & 0b0000011111100000 ) >> 5
98+ hour = (t & 0b1111100000000000 ) >> 11
9899
99100 return datetime .datetime (year , month , day , hour , minute , sec )
100101 except :
@@ -105,7 +106,7 @@ def parse_filetime(qword):
105106 # see http://integriography.wordpress.com/2010/01/16/using-phython-to-parse-and-present-windows-64-bit-timestamps/
106107 if qword == 0 :
107108 return datetime .datetime .min
108-
109+
109110 try :
110111 return datetime .datetime .fromtimestamp (float (qword ) * 1e-7 - 11644473600 , datetime .UTC )
111112 except (ValueError , OSError ):
@@ -116,6 +117,7 @@ class BinaryParserException(Exception):
116117 """
117118 Base Exception class for binary parsing.
118119 """
120+
119121 def __init__ (self , value ):
120122 """
121123 Constructor.
@@ -137,6 +139,7 @@ class ParseException(BinaryParserException):
137139 An exception to be thrown during binary parsing, such as
138140 when an invalid header is encountered.
139141 """
142+
140143 def __init__ (self , value ):
141144 """
142145 Constructor.
@@ -169,6 +172,7 @@ class Block(object):
169172 Base class for structure blocks in binary parsing.
170173 A block is associated with a offset into a byte-string.
171174 """
175+
172176 def __init__ (self , buf , offset ):
173177 """
174178 Constructor.
@@ -201,15 +205,18 @@ def declare_field(self, type, name, offset=None, length=None):
201205 offset = self ._implicit_offset
202206
203207 if length is None :
208+
204209 def no_length_handler ():
205210 f = getattr (self , "unpack_" + type )
206211 return f (offset )
212+
207213 setattr (self , name , no_length_handler )
208214 else :
209215
210216 def explicit_length_handler ():
211217 f = getattr (self , "unpack_" + type )
212218 return f (offset , length )
219+
213220 setattr (self , name , explicit_length_handler )
214221
215222 setattr (self , "_off_" + name , offset )
@@ -252,11 +259,9 @@ def explicit_length_handler():
252259 elif type == "wstring" and length is not None :
253260 self ._implicit_offset = offset + (2 * length )
254261 elif "string" in type and length is None :
255- raise ParseException ("Implicit offset not supported "
256- "for dynamic length strings" )
262+ raise ParseException ("Implicit offset not supported " "for dynamic length strings" )
257263 else :
258- raise ParseException ("Implicit offset not supported "
259- "for type: {}" .format (type ))
264+ raise ParseException ("Implicit offset not supported " "for type: {}" .format (type ))
260265
261266 def current_field_offset (self ):
262267 return self ._implicit_offset
@@ -473,7 +478,7 @@ def unpack_string(self, offset, length):
473478 Throws:
474479 - `OverrunBufferException`
475480 """
476- return self .unpack_binary (offset , length ).decode (' ascii' )
481+ return self .unpack_binary (offset , length ).decode (" ascii" )
477482
478483 def unpack_wstring (self , offset , length ):
479484 """
@@ -490,7 +495,7 @@ def unpack_wstring(self, offset, length):
490495 try :
491496 return bytes (self ._buf [start :end ]).decode ("utf16" )
492497 except AttributeError : # already a 'str' ?
493- return bytes (self ._buf [start :end ]).decode (' utf16' )
498+ return bytes (self ._buf [start :end ]).decode (" utf16" )
494499
495500 def unpack_dosdate (self , offset ):
496501 """
@@ -503,7 +508,7 @@ def unpack_dosdate(self, offset):
503508 """
504509 try :
505510 o = self ._offset + offset
506- return dosdate (self ._buf [o : o + 2 ], self ._buf [o + 2 : o + 4 ])
511+ return dosdate (self ._buf [o : o + 2 ], self ._buf [o + 2 : o + 4 ])
507512 except struct .error :
508513 raise OverrunBufferException (o , len (self ._buf ))
509514
@@ -533,10 +538,9 @@ def unpack_systemtime(self, offset):
533538 parts = struct .unpack_from ("<HHHHHHHH" , self ._buf , o )
534539 except struct .error :
535540 raise OverrunBufferException (o , len (self ._buf ))
536- return datetime .datetime (parts [0 ], parts [1 ],
537- parts [3 ], # skip part 2 (day of week)
538- parts [4 ], parts [5 ],
539- parts [6 ], parts [7 ])
541+ return datetime .datetime (
542+ parts [0 ], parts [1 ], parts [3 ], parts [4 ], parts [5 ], parts [6 ], parts [7 ] # skip part 2 (day of week)
543+ )
540544
541545 def unpack_guid (self , offset ):
542546 """
@@ -549,18 +553,15 @@ def unpack_guid(self, offset):
549553 o = self ._offset + offset
550554
551555 try :
552- _bin = bytes (self ._buf [o : o + 16 ])
556+ _bin = bytes (self ._buf [o : o + 16 ])
553557 except IndexError :
554558 raise OverrunBufferException (o , len (self ._buf ))
555559
556560 # Yeah, this is ugly
557561 h = [_bin [i ] for i in range (len (_bin ))]
558562 return """{:02x}{:02x}{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}""" .format (
559- h [3 ], h [2 ], h [1 ], h [0 ],
560- h [5 ], h [4 ],
561- h [7 ], h [6 ],
562- h [8 ], h [9 ],
563- h [10 ], h [11 ], h [12 ], h [13 ], h [14 ], h [15 ])
563+ h [3 ], h [2 ], h [1 ], h [0 ], h [5 ], h [4 ], h [7 ], h [6 ], h [8 ], h [9 ], h [10 ], h [11 ], h [12 ], h [13 ], h [14 ], h [15 ]
564+ )
564565
565566 def absolute_offset (self , offset ):
566567 """
0 commit comments