MCPcopy Index your code
hub / github.com/RustPython/RustPython / _read_object

Method _read_object

Lib/plistlib.py:539–636  ·  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

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

Callers 1

parseMethod · 0.95

Calls 12

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

Tested by

no test coverage detected