💾 Archived View for tris.fyi › pydoc › plistlib captured on 2023-01-29 at 03:27:12. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2022-07-16)
-=-=-=-=-=-=-
plistlib.py -- a tool to generate and parse MacOSX .plist files. The property list (.plist) file format is a simple XML pickle supporting basic object types, like dictionaries, lists, numbers and strings. Usually the top level object is a dictionary. To write out a plist file, use the dump(value, file) function. 'value' is the top level object, 'file' is a (writable) file object. To parse a plist from a file, use the load(file) function, with a (readable) file object as the only argument. It returns the top level object (again, usually a dictionary). To work with plist data in bytes objects, you can use loads() and dumps(). Values can be strings, integers, floats, booleans, tuples, lists, dictionaries (but only with string keys), Data, bytes, bytearray, or datetime.datetime objects. Generate Plist example: pl = dict( aString = "Doodah", aList = ["A", "B", 12, 32.1, [1, 2, 3]], aFloat = 0.1, anInt = 728, aDict = dict( anotherString = "<hello & hi there!>", aUnicodeValue = "M\xe4ssig, Ma\xdf", aTrueValue = True, aFalseValue = False, ), someData = b"<binary gunk>", someMoreData = b"<lots of binary gunk>" * 10, aDate = datetime.datetime.fromtimestamp(time.mktime(time.gmtime())), ) with open(fileName, 'wb') as fp: dump(pl, fp) Parse Plist example: with open(fileName, 'rb') as fp: pl = load(fp) print(pl["aKey"])
Buffered I/O implementation using an in-memory bytes buffer.
close(self, /) Disable all I/O operations.
detach(self, /) Disconnect this buffer from its underlying raw stream and return it. After the raw stream has been detached, the buffer is in an unusable state.
fileno(self, /) Returns underlying file descriptor if one exists. OSError is raised if the IO object does not use a file descriptor.
flush(self, /) Does nothing.
getbuffer(self, /) Get a read-write view over the contents of the BytesIO object.
getvalue(self, /) Retrieve the entire contents of the BytesIO object.
isatty(self, /) Always returns False. BytesIO objects are not connected to a TTY-like device.
read(self, size=-1, /) Read at most size bytes, returned as a bytes object. If the size argument is negative, read until EOF is reached. Return an empty bytes object at EOF.
read1(self, size=-1, /) Read at most size bytes, returned as a bytes object. If the size argument is negative or omitted, read until EOF is reached. Return an empty bytes object at EOF.
readable(self, /) Returns True if the IO object can be read.
readinto(self, buffer, /) Read bytes into buffer. Returns number of bytes read (0 for EOF), or None if the object is set not to block and has no data to read.
readinto1(self, buffer, /)
readline(self, size=-1, /) Next line from the file, as a bytes object. Retain newline. A non-negative size argument limits the maximum number of bytes to return (an incomplete line may be returned then). Return an empty bytes object at EOF.
readlines(self, size=None, /) List of bytes objects, each a line from the file. Call readline() repeatedly and return a list of the lines so read. The optional size argument, if given, is an approximate bound on the total number of bytes in the lines returned.
seek(self, pos, whence=0, /) Change stream position. Seek to byte offset pos relative to position indicated by whence: 0 Start of stream (the default). pos should be >= 0; 1 Current position - pos may be negative; 2 End of stream - pos usually negative. Returns the new absolute position.
seekable(self, /) Returns True if the IO object can be seeked.
tell(self, /) Current file position, an integer.
truncate(self, size=None, /) Truncate the file to at most size bytes. Size defaults to the current file position, as returned by tell(). The current file position is unchanged. Returns the new size.
writable(self, /) Returns True if the IO object can be written.
write(self, b, /) Write bytes to file. Return the number of bytes written.
writelines(self, lines, /) Write lines to the file. Note that newlines are not added. lines can be any iterable object producing bytes-like objects. This is equivalent to calling write() for each element.
closed = <attribute 'closed' of '_io.BytesIO' objects> True if the file is closed.
with_traceback(...) Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.
args = <attribute 'args' of 'BaseException' objects>
An enumeration.
FMT_BINARY = <PlistFormat.FMT_BINARY: 2>
FMT_XML = <PlistFormat.FMT_XML: 1>
name = <types.DynamicClassAttribute object at 0x7f75e3bec2e0> The name of the Enum member.
value = <types.DynamicClassAttribute object at 0x7f75e3bec2b0> The value of the Enum member.
ParserCreate(...) Return a new XML parser object.
dump(value, fp, *, fmt=<PlistFormat.FMT_XML: 1>, sort_keys=True, skipkeys=False) Write 'value' to a .plist file. 'fp' should be a writable, binary file object.
dumps(value, *, fmt=<PlistFormat.FMT_XML: 1>, skipkeys=False, sort_keys=True) Return a bytes object with the contents for a .plist file.
load(fp, *, fmt=None, dict_type=<class 'dict'>) Read a .plist file. 'fp' should be a readable and binary file object. Return the unpacked root object (which usually is a dictionary).
loads(value, *, fmt=None, dict_type=<class 'dict'>) Read a .plist file from a bytes object. Return the unpacked root object (which usually is a dictionary).
FMT_BINARY = <PlistFormat.FMT_BINARY: 2>
FMT_XML = <PlistFormat.FMT_XML: 1>
PLISTHEADER = b'<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n'