237 if header == b'bplist0': |
237 if header == b'bplist0': |
238 return True |
238 return True |
239 else: |
239 else: |
240 return False |
240 return False |
241 |
241 |
242 PlistTrailer = namedtuple('PlistTrailer', |
242 PlistTrailer = namedtuple( |
|
243 'PlistTrailer', |
243 'offsetSize, objectRefSize, offsetCount, topLevelObjectNumber,' |
244 'offsetSize, objectRefSize, offsetCount, topLevelObjectNumber,' |
244 ' offsetTableOffset') |
245 ' offsetTableOffset') |
245 PlistByteCounts = namedtuple('PlistByteCounts', |
246 PlistByteCounts = namedtuple( |
|
247 'PlistByteCounts', |
246 'nullBytes, boolBytes, intBytes, realBytes, dateBytes, dataBytes,' |
248 'nullBytes, boolBytes, intBytes, realBytes, dateBytes, dataBytes,' |
247 ' stringBytes, uidBytes, arrayBytes, setBytes, dictBytes') |
249 ' stringBytes, uidBytes, arrayBytes, setBytes, dictBytes') |
248 |
250 |
249 |
251 |
250 class PlistReader(object): |
252 class PlistReader(object): |
506 Private method to read an ASCII encoded string. |
508 Private method to read an ASCII encoded string. |
507 |
509 |
508 @param length length of the string (integer) |
510 @param length length of the string (integer) |
509 @return ASCII encoded string |
511 @return ASCII encoded string |
510 """ |
512 """ |
511 result = str(unpack("!{0}s".format(length), |
513 result = str(unpack( |
|
514 "!{0}s".format(length), |
512 self.contents[self.currentOffset:self.currentOffset + length])[0], |
515 self.contents[self.currentOffset:self.currentOffset + length])[0], |
513 encoding="ascii") |
516 encoding="ascii") |
514 self.currentOffset += length |
517 self.currentOffset += length |
515 return result |
518 return result |
516 |
519 |
533 Private method to read a date. |
536 Private method to read a date. |
534 |
537 |
535 @return date object (datetime.datetime) |
538 @return date object (datetime.datetime) |
536 """ |
539 """ |
537 global apple_reference_date_offset |
540 global apple_reference_date_offset |
538 result = unpack(">d", |
541 result = unpack( |
|
542 ">d", |
539 self.contents[self.currentOffset:self.currentOffset + 8])[0] |
543 self.contents[self.currentOffset:self.currentOffset + 8])[0] |
540 result = datetime.datetime.utcfromtimestamp( |
544 result = datetime.datetime.utcfromtimestamp( |
541 result + apple_reference_date_offset) |
545 result + apple_reference_date_offset) |
542 self.currentOffset += 8 |
546 self.currentOffset += 8 |
543 return result |
547 return result |