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

Method write

Lib/plistlib.py:660–703  ·  view source on GitHub ↗
(self, value)

Source from the content-addressed store, hash-verified

658 self._aware_datetime = aware_datetime
659
660 def write(self, value):
661
662 # Flattened object list:
663 self._objlist = []
664
665 # Mappings from object->objectid
666 # First dict has (type(object), object) as the key,
667 # second dict is used when object is not hashable and
668 # has id(object) as the key.
669 self._objtable = {}
670 self._objidtable = {}
671
672 # Create list of all objects in the plist
673 self._flatten(value)
674
675 # Size of object references in serialized containers
676 # depends on the number of objects in the plist.
677 num_objects = len(self._objlist)
678 self._object_offsets = [0]*num_objects
679 self._ref_size = _count_to_size(num_objects)
680
681 self._ref_format = _BINARY_FORMAT[self._ref_size]
682
683 # Write file header
684 self._fp.write(b'bplist00')
685
686 # Write object list
687 for obj in self._objlist:
688 self._write_object(obj)
689
690 # Write refnum->object offset table
691 top_object = self._getrefnum(value)
692 offset_table_offset = self._fp.tell()
693 offset_size = _count_to_size(offset_table_offset)
694 offset_format = '>' + _BINARY_FORMAT[offset_size] * num_objects
695 self._fp.write(struct.pack(offset_format, *self._object_offsets))
696
697 # Write trailer
698 sort_version = 0
699 trailer = (
700 sort_version, offset_size, self._ref_size, num_objects,
701 top_object, offset_table_offset
702 )
703 self._fp.write(struct.pack('>5xBBBQQQ', *trailer))
704
705 def _flatten(self, value):
706 # First check if the object is in the object table, not used for

Callers

nothing calls this directly

Calls 8

_flattenMethod · 0.95
_write_objectMethod · 0.95
_getrefnumMethod · 0.95
lenFunction · 0.85
_count_to_sizeFunction · 0.85
writeMethod · 0.45
tellMethod · 0.45
packMethod · 0.45

Tested by

no test coverage detected