MCPcopy Index your code
hub / github.com/python/cpython / _read_object

Method _read_object

Lib/plistlib.py:532–629  ·  view source on GitHub ↗

read the object by reference. May recursively read sub-objects (content of an array/dict/set)

(self, ref)

Source from the content-addressed store, hash-verified

530 return self._read_ints(n, self._ref_size)
531
532 def _read_object(self, ref):
533 """
534 read the object by reference.
535
536 May recursively read sub-objects (content of an array/dict/set)
537 """
538 result = self._objects[ref]
539 if result is not _undefined:
540 return result
541
542 offset = self._object_offsets[ref]
543 self._fp.seek(offset)
544 token = self._fp.read(1)[0]
545 tokenH, tokenL = token & 0xF0, token & 0x0F
546
547 if token == 0x00:
548 result = None
549
550 elif token == 0x08:
551 result = False
552
553 elif token == 0x09:
554 result = True
555
556 # The referenced source code also mentions URL (0x0c, 0x0d) and
557 # UUID (0x0e), but neither can be generated using the Cocoa libraries.
558
559 elif token == 0x0f:
560 result = b''
561
562 elif tokenH == 0x10: # int
563 result = int.from_bytes(self._fp.read(1 << tokenL),
564 'big', signed=tokenL >= 3)
565
566 elif token == 0x22: # real
567 result = struct.unpack('>f', self._fp.read(4))[0]
568
569 elif token == 0x23: # real
570 result = struct.unpack('>d', self._fp.read(8))[0]
571
572 elif token == 0x33: # date
573 f = struct.unpack('>d', self._fp.read(8))[0]
574 # timestamp 0 of binary plists corresponds to 1/1/2001
575 # (year of Mac OS X 10.0), instead of 1/1/1970.
576 if self._aware_datime:
577 epoch = datetime.datetime(2001, 1, 1, tzinfo=datetime.UTC)
578 else:
579 epoch = datetime.datetime(2001, 1, 1)
580 result = epoch + datetime.timedelta(seconds=f)
581
582 elif tokenH == 0x40: # data
583 s = self._get_size(tokenL)
584 result = self._read(s)
585
586 elif tokenH == 0x50: # ascii string
587 s = self._get_size(tokenL)
588 data = self._read(s)
589 result = data.decode('ascii')

Callers 1

parseMethod · 0.95

Calls 11

_get_sizeMethod · 0.95
_readMethod · 0.95
_read_refsMethod · 0.95
UIDClass · 0.85
unpackMethod · 0.80
datetimeMethod · 0.80
seekMethod · 0.45
readMethod · 0.45
decodeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected