This package defines classes that simplify bit-wise creation, manipulation and interpretation of data.
Classes:
Bits – An immutable container for binary data. BitArray – A mutable container for binary data. ConstBitStream – An immutable container with streaming methods. BitStream – A mutable container with streaming methods.
Bits (base class)/ + mutating methods / + streaming methods
/ BitArray ConstBitStream /
- /
- /
BitStream
Functions:
pack – Create a BitStream from a format string.
Exceptions:
Error – Module exception base class. CreationError – Error during creation. InterpretError – Inappropriate interpretation of binary data. ByteAlignError – Whole byte position or length needed. ReadError – Reading or peeking past the end of a bitstring.
http://python-bitstring.googlecode.com
Bases: bytestag.lib._bitstring.Bits
A container or stream holding an immutable sequence of bits.
For a mutable container use the BitStream class instead.
Methods inherited from Bits:
all() – Check if all specified bits are set to 1 or 0. any() – Check if any of specified bits are set to 1 or 0. count() – Count the number of bits set to 1 or 0. cut() – Create generator of constant sized chunks. endswith() – Return whether the bitstring ends with a sub-string. find() – Find a sub-bitstring in the current bitstring. findall() – Find all occurrences of a sub-bitstring in the current bitstring. join() – Join bitstrings together using current bitstring. rfind() – Seek backwards to find a sub-bitstring. split() – Create generator of chunks split by a delimiter. startswith() – Return whether the bitstring starts with a sub-bitstring. tobytes() – Return bitstring as bytes, padding if needed. tofile() – Write bitstring to file, padding if needed. unpack() – Interpret bits using format string.
Other methods:
bytealign() – Align to next byte boundary. peek() – Peek at and interpret next bits as a single item. peeklist() – Peek at and interpret next bits as a list of items. read() – Read and interpret next bits as a single item. readlist() – Read and interpret next bits as a list of items.
Special methods:
Also available are the operators [], ==, !=, +, *, ~, <<, >>, &, |, ^.
Properties:
bin – The bitstring as a binary string. bool – For single bit bitstrings, interpret as True or False. bytepos – The current byte position in the bitstring. bytes – The bitstring as a bytes object. float – Interpret as a floating point number. floatbe – Interpret as a big-endian floating point number. floatle – Interpret as a little-endian floating point number. floatne – Interpret as a native-endian floating point number. hex – The bitstring as a hexadecimal string. int – Interpret as a two’s complement signed integer. intbe – Interpret as a big-endian signed integer. intle – Interpret as a little-endian signed integer. intne – Interpret as a native-endian signed integer. len – Length of the bitstring in bits. oct – The bitstring as an octal string. pos – The current bit position in the bitstring. se – Interpret as a signed exponential-Golomb code. ue – Interpret as an unsigned exponential-Golomb code. sie – Interpret as a signed interleaved exponential-Golomb code. uie – Interpret as an unsigned interleaved exponential-Golomb code. uint – Interpret as a two’s complement unsigned integer. uintbe – Interpret as a big-endian unsigned integer. uintle – Interpret as a little-endian unsigned integer. uintne – Interpret as a native-endian unsigned integer.
The position in the bitstring in bits. Read and write.
Align to next byte and return number of skipped bits.
Raises ValueError if the end of the bitstring is reached before aligning to the next byte.
The position in the bitstring in bytes. Read and write.
Find first occurrence of substring bs.
Returns a single item tuple with the bit position if found, or an empty tuple if not found. The bit position (pos property) will also be set to the start of the substring if it is found.
bs – The bitstring to find. start – The bit position to start the search. Defaults to 0. end – The bit position one past the last bit to search.
Defaults to self.len.
Raises ValueError if bs is empty, if start < 0, if end > self.len or if end < start.
>>> BitArray('0xc3e').find('0b1111')
(6,)
Interpret next bits according to format string and return result.
fmt – Token string describing how to interpret the next bits.
The position in the bitstring is not changed. If not enough bits are available then all bits to the end of the bitstring will be used.
Raises ReadError if not enough bits are available. Raises ValueError if the format is not understood.
See the docstring for ‘read’ for token examples.
Interpret next bits according to format string(s) and return list.
The position in the bitstring is not changed. If not enough bits are available then all bits to the end of the bitstring will be used.
Raises ReadError if not enough bits are available. Raises ValueError if the format is not understood.
See the docstring for ‘read’ for token examples.
The position in the bitstring in bits. Read and write.
Interpret next bits according to the format string and return result.
fmt – Token string describing how to interpret the next bits.
fmt may also be an integer, which will be treated like the ‘bits’ token.
The position in the bitstring is advanced to after the read items.
Raises ReadError if not enough bits are available. Raises ValueError if the format is not understood.
Interpret next bits according to format string(s) and return list.
The position in the bitstring is advanced to after the read items.
Raises ReadError is not enough bits are available. Raises ValueError if the format is not understood.
See the docstring for ‘read’ for token examples.
>>> h, b1, b2 = s.readlist('hex:20, bin:5, bin:3')
>>> i, bs1, bs2 = s.readlist(['uint:12', 10, 10])
Read up to and including next occurrence of bs and return result.
bs – The bitstring to find. An integer is not permitted. bytealigned – If True the bitstring will only be
found on byte boundaries.
Raises ValueError if bs is empty. Raises ReadError if bs is not found.
Find final occurrence of substring bs.
Returns a single item tuple with the bit position if found, or an empty tuple if not found. The bit position (pos property) will also be set to the start of the substring if it is found.
bs – The bitstring to find. start – The bit position to end the reverse search. Defaults to 0. end – The bit position one past the first bit to reverse search.
Defaults to self.len.
Raises ValueError if bs is empty, if start < 0, if end > self.len or if end < start.
Bases: bytestag.lib._bitstring.ConstBitStream, bytestag.lib._bitstring.BitArray
A container or stream holding a mutable sequence of bits
Subclass of the ConstBitStream and BitArray classes. Inherits all of their methods.
Methods:
all() – Check if all specified bits are set to 1 or 0. any() – Check if any of specified bits are set to 1 or 0. append() – Append a bitstring. bytealign() – Align to next byte boundary. byteswap() – Change byte endianness in-place. count() – Count the number of bits set to 1 or 0. cut() – Create generator of constant sized chunks. endswith() – Return whether the bitstring ends with a sub-string. find() – Find a sub-bitstring in the current bitstring. findall() – Find all occurrences of a sub-bitstring in the current bitstring. insert() – Insert a bitstring. invert() – Flip bit(s) between one and zero. join() – Join bitstrings together using current bitstring. overwrite() – Overwrite a section with a new bitstring. peek() – Peek at and interpret next bits as a single item. peeklist() – Peek at and interpret next bits as a list of items. prepend() – Prepend a bitstring. read() – Read and interpret next bits as a single item. readlist() – Read and interpret next bits as a list of items. replace() – Replace occurrences of one bitstring with another. reverse() – Reverse bits in-place. rfind() – Seek backwards to find a sub-bitstring. rol() – Rotate bits to the left. ror() – Rotate bits to the right. set() – Set bit(s) to 1 or 0. split() – Create generator of chunks split by a delimiter. startswith() – Return whether the bitstring starts with a sub-bitstring. tobytes() – Return bitstring as bytes, padding if needed. tofile() – Write bitstring to file, padding if needed. unpack() – Interpret bits using format string.
Special methods:
Mutating operators are available: [], <<=, >>=, +=, *=, &=, |= and ^= in addition to [], ==, !=, +, *, ~, <<, >>, &, | and ^.
Properties:
bin – The bitstring as a binary string. bool – For single bit bitstrings, interpret as True or False. bytepos – The current byte position in the bitstring. bytes – The bitstring as a bytes object. float – Interpret as a floating point number. floatbe – Interpret as a big-endian floating point number. floatle – Interpret as a little-endian floating point number. floatne – Interpret as a native-endian floating point number. hex – The bitstring as a hexadecimal string. int – Interpret as a two’s complement signed integer. intbe – Interpret as a big-endian signed integer. intle – Interpret as a little-endian signed integer. intne – Interpret as a native-endian signed integer. len – Length of the bitstring in bits. oct – The bitstring as an octal string. pos – The current bit position in the bitstring. se – Interpret as a signed exponential-Golomb code. ue – Interpret as an unsigned exponential-Golomb code. sie – Interpret as a signed interleaved exponential-Golomb code. uie – Interpret as an unsigned interleaved exponential-Golomb code. uint – Interpret as a two’s complement unsigned integer. uintbe – Interpret as a big-endian unsigned integer. uintle – Interpret as a little-endian unsigned integer. uintne – Interpret as a native-endian unsigned integer.
Bases: bytestag.lib._bitstring.Bits
A container holding a mutable sequence of bits.
Subclass of the immutable Bits class. Inherits all of its methods (except __hash__) and adds mutating methods.
Mutating methods:
append() – Append a bitstring. byteswap() – Change byte endianness in-place. insert() – Insert a bitstring. invert() – Flip bit(s) between one and zero. overwrite() – Overwrite a section with a new bitstring. prepend() – Prepend a bitstring. replace() – Replace occurrences of one bitstring with another. reverse() – Reverse bits in-place. rol() – Rotate bits to the left. ror() – Rotate bits to the right. set() – Set bit(s) to 1 or 0.
Methods inherited from Bits:
all() – Check if all specified bits are set to 1 or 0. any() – Check if any of specified bits are set to 1 or 0. count() – Count the number of bits set to 1 or 0. cut() – Create generator of constant sized chunks. endswith() – Return whether the bitstring ends with a sub-string. find() – Find a sub-bitstring in the current bitstring. findall() – Find all occurrences of a sub-bitstring in the current bitstring. join() – Join bitstrings together using current bitstring. rfind() – Seek backwards to find a sub-bitstring. split() – Create generator of chunks split by a delimiter. startswith() – Return whether the bitstring starts with a sub-bitstring. tobytes() – Return bitstring as bytes, padding if needed. tofile() – Write bitstring to file, padding if needed. unpack() – Interpret bits using format string.
Special methods:
Mutating operators are available: [], <<=, >>=, +=, *=, &=, |= and ^= in addition to the inherited [], ==, !=, +, *, ~, <<, >>, &, | and ^.
Properties:
bin – The bitstring as a binary string. bool – For single bit bitstrings, interpret as True or False. bytepos – The current byte position in the bitstring. bytes – The bitstring as a bytes object. float – Interpret as a floating point number. floatbe – Interpret as a big-endian floating point number. floatle – Interpret as a little-endian floating point number. floatne – Interpret as a native-endian floating point number. hex – The bitstring as a hexadecimal string. int – Interpret as a two’s complement signed integer. intbe – Interpret as a big-endian signed integer. intle – Interpret as a little-endian signed integer. intne – Interpret as a native-endian signed integer. len – Length of the bitstring in bits. oct – The bitstring as an octal string. pos – The current bit position in the bitstring. se – Interpret as a signed exponential-Golomb code. ue – Interpret as an unsigned exponential-Golomb code. sie – Interpret as a signed interleaved exponential-Golomb code. uie – Interpret as an unsigned interleaved exponential-Golomb code. uint – Interpret as a two’s complement unsigned integer. uintbe – Interpret as a big-endian unsigned integer. uintle – Interpret as a little-endian unsigned integer. uintne – Interpret as a native-endian unsigned integer.
The bitstring as a binary string. Read and write.
The bitstring as a bool (True or False). Read and write.
The bitstring as a ordinary string. Read and write.
Change the endianness in-place. Return number of repeats of fmt done.
start – Start bit position, defaults to 0. end – End bit position, defaults to self.len. repeat – If True (the default) the byte swapping pattern is repeated
as much as possible.
The bitstring as a floating point number. Read and write.
The bitstring as a big-endian floating point number. Read and write.
The bitstring as a little-endian floating point number. Read and write.
The bitstring as a native-endian floating point number. Read and write.
The bitstring as a hexadecimal string. Read and write.
Insert bs at bit position pos.
bs – The bitstring to insert. pos – The bit position to insert at.
Raises ValueError if pos < 0 or pos > self.len.
The bitstring as a two’s complement signed int. Read and write.
The bitstring as a two’s complement big-endian signed int. Read and write.
The bitstring as a two’s complement little-endian signed int. Read and write.
The bitstring as a two’s complement native-endian signed int. Read and write.
Invert one or many bits from 0 to 1 or vice versa.
Raises IndexError if pos < -self.len or pos >= self.len.
The bitstring as an octal string. Read and write.
Overwrite with bs at bit position pos.
bs – The bitstring to overwrite with. pos – The bit position to begin overwriting from.
Raises ValueError if pos < 0 or pos + bs.len > self.len
Replace all occurrences of old with new in place.
Returns number of replacements made.
old – The bitstring to replace. new – The replacement bitstring. start – Any occurrences that start before this will not be replaced.
Defaults to 0.
Raises ValueError if old is empty or if start or end are out of range.
Reverse bits in-place.
start – Position of first bit to reverse. Defaults to 0. end – One past the position of the last bit to reverse.
Defaults to self.len.
Using on an empty bitstring will have no effect.
Raises ValueError if start < 0, end > self.len or end < start.
Rotate bits to the left in-place.
bits – The number of bits to rotate by. start – Start of slice to rotate. Defaults to 0. end – End of slice to rotate. Defaults to self.len.
Raises ValueError if bits < 0.
Rotate bits to the right in-place.
bits – The number of bits to rotate by. start – Start of slice to rotate. Defaults to 0. end – End of slice to rotate. Defaults to self.len.
Raises ValueError if bits < 0.
The bitstring as a signed exponential-Golomb code. Read and write.
Set one or many bits to 1 or 0.
value – If True bits are set to 1, otherwise they are set to 0. pos – Either a single bit position or an iterable of bit positions.
Negative numbers are treated in the same way as slice indices. Defaults to the entire bitstring.
Raises IndexError if pos < -self.len or pos >= self.len.
The bitstring as a signed interleaved exponential-Golomb code. Read and write.
The bitstring as an unsigned exponential-Golomb code. Read and write.
The bitstring as an unsigned interleaved exponential-Golomb code. Read and write.
The bitstring as a two’s complement unsigned int. Read and write.
The bitstring as a two’s complement big-endian unsigned int. Read and write.
The bitstring as a two’s complement little-endian unsigned int. Read and write.
The bitstring as a two’s complement native-endian unsigned int. Read and write.
Bases: builtins.object
A container holding an immutable sequence of bits.
For a mutable container use the BitArray class instead.
Methods:
all() – Check if all specified bits are set to 1 or 0. any() – Check if any of specified bits are set to 1 or 0. count() – Count the number of bits set to 1 or 0. cut() – Create generator of constant sized chunks. endswith() – Return whether the bitstring ends with a sub-string. find() – Find a sub-bitstring in the current bitstring. findall() – Find all occurrences of a sub-bitstring in the current bitstring. join() – Join bitstrings together using current bitstring. rfind() – Seek backwards to find a sub-bitstring. split() – Create generator of chunks split by a delimiter. startswith() – Return whether the bitstring starts with a sub-bitstring. tobytes() – Return bitstring as bytes, padding if needed. tofile() – Write bitstring to file, padding if needed. unpack() – Interpret bits using format string.
Special methods:
Also available are the operators [], ==, !=, +, *, ~, <<, >>, &, |, ^.
Properties:
bin – The bitstring as a binary string. bool – For single bit bitstrings, interpret as True or False. bytes – The bitstring as a bytes object. float – Interpret as a floating point number. floatbe – Interpret as a big-endian floating point number. floatle – Interpret as a little-endian floating point number. floatne – Interpret as a native-endian floating point number. hex – The bitstring as a hexadecimal string. int – Interpret as a two’s complement signed integer. intbe – Interpret as a big-endian signed integer. intle – Interpret as a little-endian signed integer. intne – Interpret as a native-endian signed integer. len – Length of the bitstring in bits. oct – The bitstring as an octal string. se – Interpret as a signed exponential-Golomb code. ue – Interpret as an unsigned exponential-Golomb code. sie – Interpret as a signed interleaved exponential-Golomb code. uie – Interpret as an unsigned interleaved exponential-Golomb code. uint – Interpret as a two’s complement unsigned integer. uintbe – Interpret as a big-endian unsigned integer. uintle – Interpret as a little-endian unsigned integer. uintne – Interpret as a native-endian unsigned integer.
Return True if one or many bits are all set to value.
Return True if any of one or many bits are set to value.
The bitstring as a binary string. Read only.
The bitstring as a bool (True or False). Read only.
The bitstring as a bytes object. Read only.
Return count of total number of either zero or one bits.
>>> Bits('0xef').count(1)
7
Return bitstring generator by cutting into bits sized chunks.
bits – The size in bits of the bitstring chunks to generate. start – The bit position to start the first cut. Defaults to 0. end – The bit position one past the last bit to use in the cut.
Defaults to self.len.
Return whether the current bitstring ends with suffix.
suffix – The bitstring to search for. start – The bit position to start from. Defaults to 0. end – The bit position to end at. Defaults to self.len.
Find first occurrence of substring bs.
Returns a single item tuple with the bit position if found, or an empty tuple if not found. The bit position (pos property) will also be set to the start of the substring if it is found.
bs – The bitstring to find. start – The bit position to start the search. Defaults to 0. end – The bit position one past the last bit to search.
Defaults to self.len.
Raises ValueError if bs is empty, if start < 0, if end > self.len or if end < start.
>>> BitArray('0xc3e').find('0b1111')
(6,)
Find all occurrences of bs. Return generator of bit positions.
bs – The bitstring to find. start – The bit position to start the search. Defaults to 0. end – The bit position one past the last bit to search.
Defaults to self.len.
count – The maximum number of occurrences to find. bytealigned – If True the bitstring will only be found on
byte boundaries.
Raises ValueError if bs is empty, if start < 0, if end > self.len or if end < start.
Note that all occurrences of bs are found, even if they overlap.
The bitstring as a floating point number. Read only.
The bitstring as a big-endian floating point number. Read only.
The bitstring as a little-endian floating point number. Read only.
The bitstring as a native-endian floating point number. Read only.
The bitstring as a hexadecimal string. Read only.
The bitstring as a two’s complement signed int. Read only.
The bitstring as a two’s complement big-endian signed int. Read only.
The bitstring as a two’s complement little-endian signed int. Read only.
The bitstring as a two’s complement native-endian signed int. Read only.
Return concatenation of bitstrings joined by self.
sequence – A sequence of bitstrings.
The length of the bitstring in bits. Read only.
The length of the bitstring in bits. Read only.
The bitstring as an octal string. Read only.
Find final occurrence of substring bs.
Returns a single item tuple with the bit position if found, or an empty tuple if not found. The bit position (pos property) will also be set to the start of the substring if it is found.
bs – The bitstring to find. start – The bit position to end the reverse search. Defaults to 0. end – The bit position one past the first bit to reverse search.
Defaults to self.len.
Raises ValueError if bs is empty, if start < 0, if end > self.len or if end < start.
The bitstring as a signed exponential-Golomb code. Read only.
The bitstring as a signed interleaved exponential-Golomb code. Read only.
Return bitstring generator by splittling using a delimiter.
The first item returned is the initial bitstring before the delimiter, which may be an empty bitstring.
delimiter – The bitstring used as the divider. start – The bit position to start the split. Defaults to 0. end – The bit position one past the last bit to use in the split.
Defaults to self.len.
bytealigned – If True splits will only occur on byte boundaries.
Raises ValueError if the delimiter is empty.
Return whether the current bitstring starts with prefix.
prefix – The bitstring to search for. start – The bit position to start from. Defaults to 0. end – The bit position to end at. Defaults to self.len.
Return the bitstring as bytes, padding with zero bits if needed.
Up to seven zero bits will be added at the end to byte align.
Write the bitstring to a file object, padding with zero bits if needed.
Up to seven zero bits will be added at the end to byte align.
The bitstring as an unsigned exponential-Golomb code. Read only.
The bitstring as an unsigned interleaved exponential-Golomb code. Read only.
The bitstring as a two’s complement unsigned int. Read only.
The bitstring as a two’s complement big-endian unsigned int. Read only.
The bitstring as a two’s complement little-endian unsigned int. Read only.
The bitstring as a two’s complement native-endian unsigned int. Read only.
Interpret the whole bitstring using fmt and return list.
Raises ValueError if the format is not understood. If not enough bits are available then all bits to the end of the bitstring will be used.
See the docstring for ‘read’ for token examples.
Pack the values according to the format string and return a new BitStream.
values – Zero or more values to pack according to the format. kwargs – A dictionary or keyword-value pairs - the keywords used in the
format string will be replaced with their given value.
>>> s = pack('uint:12, bits', 100, '0xffe')
>>> t = pack(['bits', 'bin:3'], s, '111')
>>> u = pack('uint:8=a, uint:8=b, uint:55=a', a=6, b=44)
Bases: builtins.Exception
Base class for errors in the bitstring module.
Bases: bytestag.lib._bitstring.Error, builtins.IndexError
Reading or peeking past the end of a bitstring.
Bases: bytestag.lib._bitstring.Error, builtins.ValueError
Inappropriate interpretation of binary data.
Bases: bytestag.lib._bitstring.Error
Whole-byte position or length needed.
Bases: bytestag.lib._bitstring.Error, builtins.ValueError
Inappropriate argument during bitstring creation.
Determines whether a number of methods default to working only on byte boundaries.
A resource is a logical file contained within a package, or a logical subdirectory thereof. The package resource API expects resource names to have their path parts separated with /, not whatever the local path separator is. Do not use os.path operations to manipulate resource names being passed into the API.
The package resource API is designed to work with normal filesystem packages, .egg files, and unpacked .egg files. It can also work in a limited way with .zip files and with custom PEP 302 loaders that support the get_data() method.
Return an IResourceProvider for the named module or requirement
Return a current distribution object for a Requirement or string
Return name entry point of group for dist or raise ImportError
Return the entry point map for group, or the full entry map
Return the EntryPoint object for group`+`name, or None
Declare that package ‘packageName’ is a namespace package
Yield distributions accessible via path_item
Determine the default cache location
This returns the PYTHON_EGG_CACHE environment variable, if set. Otherwise, on Windows, it returns a “Python-Eggs” subdirectory of the “Application Data” directory. On all other systems, it’s “~/.python-eggs”.
Bases: builtins.object
Searchable snapshot of distributions on a search path
Find distribution best matching req and usable on working_set
This calls the find(req) method of the working_set to see if a suitable distribution is already active. (This may raise VersionConflict if an unsuitable version of the project is already active in the specified working_set.) If a suitable distribution isn’t active, this method returns the newest distribution in the environment that meets the Requirement in req. If no suitable distribution is found, and installer is supplied, then the result of calling the environment’s obtain(req, installer) method will be returned.
Is distribution dist acceptable for this environment?
The distribution must match the platform and python version requirements specified when this environment was created, or False is returned.
Obtain a distribution matching requirement (e.g. via download)
Obtain a distro that matches requirement (e.g. via download). In the base Environment class, this routine just returns installer(requirement), unless installer is None, in which case None is returned instead. This method is a hook that allows subclasses to attempt other ways of obtaining a distribution before falling back to the installer argument.
Scan search_path for distributions usable in this environment
Any distributions found are added to the environment. search_path should be a sequence of sys.path items. If not supplied, sys.path is used. Only distributions conforming to the platform/python version defined at initialization are added.
Bases: builtins.object
A collection of active distributions on sys.path (or a similar list)
Add dist to working set, associated with entry
If entry is unspecified, it defaults to the .location of dist. On exit from this routine, entry is added to the end of the working set’s .entries (if it wasn’t already present).
dist is only added to the working set if it’s for a project that doesn’t already have a distribution in the set. If it’s added, any callbacks registered with the subscribe() method will be called.
Add a path item to .entries, finding any distributions on it
find_distributions(entry,True) is used to find distributions corresponding to the path entry, and they are added. entry is always appended to .entries, even if it is already present. (This is because sys.path can contain the same value more than once, and the .entries of the sys.path WorkingSet should always equal sys.path.)
Find a distribution matching requirement req
If there is an active distribution for the requested project, this returns it as long as it meets the version requirement specified by req. But, if there is an active distribution for the project and it does not meet the req requirement, VersionConflict is raised. If there is no active distribution for the requested project, None is returned.
Find all activatable distributions in plugin_env
Example usage:
distributions, errors = working_set.find_plugins(
Environment(plugin_dirlist)
)
map(working_set.add, distributions) # add plugins+libs to sys.path
print 'Could not load', errors # display errors
The plugin_env should be an Environment instance that contains only distributions that are in the project’s “plugin directory” or directories. The full_env, if supplied, should be an Environment contains all currently-available distributions. If full_env is not supplied, one is created automatically from the WorkingSet this method is called on, which will typically mean that every directory on sys.path will be scanned for distributions.
installer is a standard installer callback as used by the resolve() method. The fallback flag indicates whether we should attempt to resolve older versions of a plugin if the newest version cannot be resolved.
This method returns a 2-tuple: (distributions, error_info), where distributions is a list of the distributions found in plugin_env that were loadable, along with any other distributions that are needed to resolve their dependencies. error_info is a dictionary mapping unloadable plugin distributions to an exception instance describing the error that occurred. Usually this will be a DistributionNotFound or VersionConflict instance.
Yield entry point objects from group matching name
If name is None, yields all entry points in group from all distributions in the working set, otherwise only ones matching both group and name are yielded (in distribution order).
Ensure that distributions matching requirements are activated
requirements must be a string or a (possibly-nested) sequence thereof, specifying the distributions and versions required. The return value is a sequence of the distributions that needed to be activated to fulfill the requirements; all relevant distributions are included, even if they were already activated in this working set.
List all distributions needed to (recursively) meet requirements
requirements must be a sequence of Requirement objects. env, if supplied, should be an Environment instance. If not supplied, it defaults to all distributions available within any entry or distribution in the working set. installer, if supplied, will be invoked with each requirement that cannot be met by an already-installed distribution; it should return a Distribution or None.
Bases: builtins.object
Manage resource extraction and packages
Delete all extracted resource files and directories, returning a list of the file and directory names that could not be successfully removed. This function does not have any concurrency protection, so it should generally only be called when the extraction path is a temporary directory exclusive to a single process. This method is not automatically called; you must call it explicitly or register it as an atexit function if you wish to ensure cleanup of a temporary directory used for extractions.
Return absolute location in cache for archive_name and names
The parent directory of the resulting path will be created if it does not already exist. archive_name should be the base filename of the enclosing egg (which may not be the name of the enclosing zipfile!), including its ”.egg” extension. names, if provided, should be a sequence of path name parts “under” the egg’s extraction location.
This method should only be called by resource providers that need to obtain an extraction location, and only for names they intend to extract, as it tracks the generated names for possible cleanup later.
Perform any platform-specific postprocessing of tempname
This is where Mac header rewrites should be done; other platforms don’t have anything special they should do.
Resource providers should call this method ONLY after successfully extracting a compressed resource. They must NOT call it on resources that are already in the filesystem.
tempname is the current (temporary) name of the file, and filename is the name it will be renamed to by the caller after this routine returns.
Return a true filesystem path for specified resource
Is the named resource an existing directory?
List the contents of the named resource directory
Return a readable file-like object for specified resource
Return specified resource as a string
Set the base path where resources will be extracted to, if needed.
If you do not call this routine before any extractions take place, the path defaults to the return value of get_default_cache(). (Which is based on the PYTHON_EGG_CACHE environment variable, with various platform-specific fallbacks. See that routine’s documentation for more details.)
Resources are extracted to subdirectories of this path based upon information given by the IResourceProvider. You may set this to a temporary directory, but then you must call cleanup_resources() to delete the extracted files when done. There is no guarantee that cleanup_resources() will be able to remove all extracted files.
(Note: you may not change the extraction path for a given resource manager once resources have been extracted, unless you first call cleanup_resources().)
Bases: builtins.object
Wrap an actual or potential sys.path entry w/metadata
Bases: builtins.object
Bases: builtins.object
Object representing an advertised importable object
Bases: builtins.Exception
Abstract base for dependency resolution errors
Bases: bytestag.lib._pkg_resources.ResolutionError
An already-installed version conflicts with the requested version
Bases: bytestag.lib._pkg_resources.ResolutionError
A requested distribution was not found
Bases: bytestag.lib._pkg_resources.ResolutionError
Distribution doesn’t have an “extra feature” of the given name
Bases: builtins.RuntimeError
An error occurred extracting a resource
The following attributes are available from instances of this exception:
Yield Requirement objects for each specification in strs
strs must be an instance of basestring, or a (possibly-nested) iterable thereof.
Convert a version string to a chronologically-sortable key
This is a rough cross between distutils’ StrictVersion and LooseVersion; if you give it versions that would work with StrictVersion, then it behaves the same; otherwise it acts like a slightly-smarter LooseVersion. It is possible to create pathological version coding schemes that will fool this parser, but they should be very rare in practice.
The returned value will be a tuple of strings. Numeric portions of the version are padded to 8 digits so they will compare numerically, but without relying on how numbers compare relative to strings. Dots are dropped, but dashes are retained. Trailing zeros between alpha segments or dashes are suppressed, so that e.g. “2.4.0” is considered the same as “2.4”. Alphanumeric parts are lower-cased.
The algorithm assumes that strings like “-” and any alpha string that alphabetically follows “final” represents a “patch level”. So, “2.4-1” is assumed to be a branch or patch of “2.4”, and therefore “2.4.1” is considered newer than “2.4-1”, which in turn is newer than “2.4”.
Strings like “a”, “b”, “c”, “alpha”, “beta”, “candidate” and so on (that come before “final” alphabetically) are assumed to be pre-release versions, so that the version “2.4” is considered newer than “2.4a1”.
Finally, to handle miscellaneous cases, the strings “pre”, “preview”, and “rc” are treated as if they were “c”, i.e. as though they were release candidates, and therefore are not as new as a version string that does not contain them, and “dev” is replaced with an ‘@’ so that it sorts lower than than any other pre-release tag.
Convert an arbitrary string to a standard distribution name
Any runs of non-alphanumeric/. characters are replaced with a single ‘-‘.
Convert an arbitrary string to a standard version string
Spaces become dots, and all other non-alphanumeric characters become dashes, with runs of multiple dashes condensed to a single dash.
Return this platform’s string for platform-specific distributions
XXX Currently this is the same as distutils.util.get_platform(), but it needs some hacks for Linux and Mac OS X.
Can code for the provided platform run on the required platform?
Returns true if either platform is None, or the platforms are equal.
XXX Needs compatibility checks for Linux and other unixy OSes.
Yield non-empty/non-comment lines of a basestring or sequence
Split a string or iterable thereof into (section,content) pairs
Each section is a stripped version of the section header (“[section]”) and each content is a list of stripped lines excluding blank lines and comment-only lines. If there are any such lines before the first section header, they’re returned in a first section of None.
Convert an arbitrary string to a standard ‘extra’ name
Any runs of non-alphanumeric characters are replaced with a single ‘_’, and the result is always lowercased.
Convert a project or version name to its filename-escaped form
Any ‘-‘ characters are currently replaced with ‘_’.
Ensure that the parent directory of path exists
Normalize a file/dir name for comparison purposes
Bases: builtins.object
Bases: bytestag.lib._pkg_resources.IMetadataProvider
An object that provides access to package resources
Return a true filesystem path for resource_name
manager must be an IResourceManager
Return a readable file-like object for resource_name
manager must be an IResourceManager
Bases: bytestag.lib._pkg_resources.EmptyProvider
Metadata handler for standalone PKG-INFO files
Usage:
metadata = FileMetadata("/path/to/PKG-INFO")
This provider rejects all data and metadata requests except for PKG-INFO, which is treated as existing, and will be the contents of the file at the provided location.
Bases: bytestag.lib._pkg_resources.DefaultProvider
Metadata provider for egg directories
Usage:
# Development eggs:
egg_info = "/path/to/PackageName.egg-info"
base_dir = os.path.dirname(egg_info)
metadata = PathMetadata(base_dir, egg_info)
dist_name = os.path.splitext(os.path.basename(egg_info))[0]
dist = Distribution(basedir,project_name=dist_name,metadata=metadata)
# Unpacked egg directories:
egg_path = "/path/to/PackageName-ver-pyver-etc.egg"
metadata = PathMetadata(egg_path, os.path.join(egg_path,'EGG-INFO'))
dist = Distribution.from_filename(egg_path, metadata=metadata)
Bases: bytestag.lib._pkg_resources.ZipProvider
Metadata provider for .egg files
Bases: bytestag.lib._pkg_resources.NullProvider
Provider that returns nothing for all requests
Bases: builtins.object
Try to implement resources and metadata for arbitrary PEP 302 loaders
Bases: bytestag.lib._pkg_resources.NullProvider
Provider based on a virtual filesystem
Bases: bytestag.lib._pkg_resources.EggProvider
Provides access to package resources in the filesystem
Bases: bytestag.lib._pkg_resources.EggProvider
Resource support for zips and eggs
Register distribution_finder to find distributions in sys.path items
importer_type is the type or class of a PEP 302 “Importer” (sys.path item handler), and distribution_finder is a callable that, passed a path item and the importer instance, yields Distribution instances found on that path item. See pkg_resources.find_on_path for an example.
Register namespace_handler to declare namespace packages
importer_type is the type or class of a PEP 302 “Importer” (sys.path item handler), and namespace_handler is a callable like this:
def namespace_handler(importer,path_entry,moduleName,module):
# return a path_entry to use for child packages
Namespace handlers are only called if the importer object has already agreed that it can handle the relevant path item, and they should only return a subpath if the module __path__ does not already contain an equivalent subpath. For an example namespace handler, see pkg_resources.file_ns_handler.
Register provider_factory to make providers for loader_type
loader_type is the type or class of a PEP 302 module.__loader__, and provider_factory is a function that, passed a module object, returns an IResourceProvider for that module.
Ensure that previously-declared namespace packages include path_item
Retrieve a PEP 302 importer for the given path item
The returned importer is cached in sys.path_importer_cache if it was newly created by a path hook.
If there is no importer, a wrapper around the basic import machinery is returned. This wrapper is never inserted into the importer cache (None is inserted instead).
The cache (or part of it) can be cleared manually if a rescan of sys.path_hooks is necessary.
alias of Environment