Changeset 1577 for pykota/trunk
- Timestamp:
- 06/29/04 01:11:26 (20 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/pdlanalyzer.py
r1576 r1577 22 22 # 23 23 # $Log$ 24 # Revision 1.21 2004/06/28 23:11:26 jalet 25 # Code de-factorization in PCLXL parser 26 # 24 27 # Revision 1.20 2004/06/28 22:38:41 jalet 25 28 # Increased speed by a factor of 2 in PCLXL parser … … 264 267 # raise PDLAnalyzerError, "PCLXL (aka PCL6) is not supported yet." 265 268 self.infile = infile 266 self. islittleendian= None269 self.endianness = None 267 270 found = 0 268 271 while not found : … … 333 336 return 0 334 337 335 def handleArray(self, itemsize) :336 """Handles arrays."""338 def array_8(self) : 339 """Handles byte arrays.""" 337 340 pos = self.pos 338 341 datatype = self.minfile[pos] … … 346 349 sarraysize = self.minfile[pos:posl] 347 350 self.pos = posl 348 if self.islittleendian :349 fmt = "<"350 else :351 fmt = ">"352 351 if length == 1 : 353 fmt += "B"352 return struct.unpack(self.endianness + "B", sarraysize)[0] 354 353 elif length == 2 : 355 fmt += "H"354 return struct.unpack(self.endianness + "H", sarraysize)[0] 356 355 elif length == 4 : 357 fmt += "I"356 return struct.unpack(self.endianness + "I", sarraysize)[0] 358 357 else : 359 358 raise PDLAnalyzerError, "Error on array size at %s" % self.pos 360 arraysize = struct.unpack(fmt, sarraysize)[0]361 return arraysize * itemsize362 363 def array_8(self) :364 """Handles byte arrays."""365 return self.handleArray(1)366 359 367 360 def array_16(self) : 368 361 """Handles byte arrays.""" 369 return self.handleArray(2) 362 pos = self.pos 363 datatype = self.minfile[pos] 364 pos += 1 365 length = self.tags[ord(datatype)] 366 if callable(length) : 367 self.pos = pos 368 length = length() 369 pos = self.pos 370 posl = pos + length 371 sarraysize = self.minfile[pos:posl] 372 self.pos = posl 373 if length == 1 : 374 return 2 * struct.unpack(self.endianness + "B", sarraysize)[0] 375 elif length == 2 : 376 return 2 * struct.unpack(self.endianness + "H", sarraysize)[0] 377 elif length == 4 : 378 return 2 * struct.unpack(self.endianness + "I", sarraysize)[0] 379 else : 380 raise PDLAnalyzerError, "Error on array size at %s" % self.pos 370 381 371 382 def array_32(self) : 372 383 """Handles byte arrays.""" 373 return self.handleArray(4) 384 pos = self.pos 385 datatype = self.minfile[pos] 386 pos += 1 387 length = self.tags[ord(datatype)] 388 if callable(length) : 389 self.pos = pos 390 length = length() 391 pos = self.pos 392 posl = pos + length 393 sarraysize = self.minfile[pos:posl] 394 self.pos = posl 395 if length == 1 : 396 return 4 * struct.unpack(self.endianness + "B", sarraysize)[0] 397 elif length == 2 : 398 return 4 * struct.unpack(self.endianness + "H", sarraysize)[0] 399 elif length == 4 : 400 return 4 * struct.unpack(self.endianness + "I", sarraysize)[0] 401 else : 402 raise PDLAnalyzerError, "Error on array size at %s" % self.pos 374 403 375 404 def embeddedDataSmall(self) : … … 382 411 def embeddedData(self) : 383 412 """Handle normal amounts of data.""" 384 if self.islittleendian : 385 fmt = "<I" 386 else : 387 fmt = ">I" 413 fmt = self.endianness + "I" 388 414 pos = self.pos 389 415 pos4 = pos + 4 … … 394 420 def littleEndian(self) : 395 421 """Toggles to little endianness.""" 396 self. islittleendian = 1# little endian422 self.endianness = "<" # little endian 397 423 return 0 398 424 399 425 def bigEndian(self) : 400 426 """Toggles to big endianness.""" 401 self. islittleendian = 0# big endian427 self.endianness = ">" # big endian 402 428 return 0 403 429 … … 586 612 587 613 if __name__ == "__main__" : 588 main() 614 main()