API¶
The primary sphobjinv
API consists of two pairs of functions:
readfile()
/writefile()
– Read/write files from/to disk asbytes
, for proper behavior ofzlib
(de)compression.encode()
/decode()
– Encode/decode the object data read from disk.
Also exposed are two re.compile()
patterns, potentially useful in parsing
decoded data only:
p_comments
– Retrieves the #-prefixed comment linesp_data
– Retrieves all lines not prefixed by #
The normal workflow would be:
Import the module; e.g.:
>>> import sphobjinv as soiRead the desired file data (compressed or uncompressed) with
readfile()
:>>> fd = soi.readfile('/path/to/file')Decode [or encode] the file data with
decode()
[orencode()
]:>>> data = soi.decode(fd)Write the desired file with
writefile()
, or otherwise use the resultingbytes
data:>>> len(soi.p_data.findall(data)) # e.g., retrieve the number of object entries 6319 >>> soi.writefile('/path/to/new/file', data)
Members
-
decode
(bstr)¶ Decode a version 2
intersphinx
objects.inv
bytestring.The #-prefixed comment lines are left unchanged, whereas the
zlib
-compressed data lines are uncompressed to plaintext.Parameters: bstr – bytes
– Binary string containing an encodedobjects.inv
file.Returns: out_b – bytes
– Decoded binary string containing the plaintextobjects.inv
content.
-
encode
(bstr)¶ Encode a version 2
intersphinx
objects.inv
bytestring.The #-prefixed comment lines are left unchanged, whereas the plaintext data lines are compressed with
zlib
.Parameters: bstr – bytes
– Binary string containing the decoded contents of anobjects.inv
file.Returns: out_b – bytes
– Binary string containing the encodedobjects.inv
content.
-
p_comments
= re.compile(b'^#.*$', re.MULTILINE)¶ Bytestring regex pattern for comment lines in decoded
objects.inv
files
-
p_data
= re.compile(b'^[^#].*$', re.MULTILINE)¶ Bytestring regex pattern for data lines in decoded
objects.inv
files
-
readfile
(path, cmdline=False)¶ Read file contents and return as binary string.
Parameters: Returns: b –
bytes
– Binary contents of the indicated file.