Belle II Software development
|
Public Member Functions | |
def | __init__ (self, auto=None, length=None, offset=None, **kwargs) |
def | __new__ (cls, auto=None, length=None, offset=None, **kwargs) |
def | __iadd__ (self, bs) |
def | __copy__ (self) |
def | __setitem__ (self, key, value) |
def | __delitem__ (self, key) |
def | __ilshift__ (self, n) |
def | __irshift__ (self, n) |
def | __imul__ (self, n) |
def | __ior__ (self, bs) |
def | __iand__ (self, bs) |
def | __ixor__ (self, bs) |
def | replace (self, old, new, start=None, end=None, count=None, bytealigned=None) |
def | insert (self, bs, pos=None) |
def | overwrite (self, bs, pos=None) |
def | append (self, bs) |
def | prepend (self, bs) |
def | reverse (self, start=None, end=None) |
def | set (self, value, pos=None) |
def | invert (self, pos=None) |
def | ror (self, bits, start=None, end=None) |
def | rol (self, bits, start=None, end=None) |
def | byteswap (self, fmt=None, start=None, end=None, repeat=True) |
def | clear (self) |
def | copy (self) |
Protected Attributes | |
_pos | |
Properties | |
property | int |
property | uint |
property | float |
property | intbe |
property | uintbe |
property | floatbe |
property | intle |
property | uintle |
property | floatle |
property | intne |
property | uintne |
property | floatne |
property | ue |
property | se |
property | uie |
property | sie |
property | hex |
property | bin |
property | oct |
property | bool |
property | bytes |
Static Private Attributes | |
tuple | __slots__ = () |
None | __hash__ = None |
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.
Definition at line 2949 of file bitstring.py.
def __init__ | ( | self, | |
auto = None , |
|||
length = None , |
|||
offset = None , |
|||
** | kwargs | ||
) |
Either specify an 'auto' initialiser: auto -- a string of comma separated tokens, an integer, a file object, a bytearray, a boolean iterable or another bitstring. Or initialise via **kwargs with one (and only one) of: bytes -- raw data as a string, for example read from a binary file. bin -- binary string representation, e.g. '0b001010'. hex -- hexadecimal string representation, e.g. '0x2ef' oct -- octal string representation, e.g. '0o777'. uint -- an unsigned integer. int -- a signed integer. float -- a floating point number. uintbe -- an unsigned big-endian whole byte integer. intbe -- a signed big-endian whole byte integer. floatbe - a big-endian floating point number. uintle -- an unsigned little-endian whole byte integer. intle -- a signed little-endian whole byte integer. floatle -- a little-endian floating point number. uintne -- an unsigned native-endian whole byte integer. intne -- a signed native-endian whole byte integer. floatne -- a native-endian floating point number. se -- a signed exponential-Golomb code. ue -- an unsigned exponential-Golomb code. sie -- a signed interleaved exponential-Golomb code. uie -- an unsigned interleaved exponential-Golomb code. bool -- a boolean (True or False). filename -- a file which will be opened in binary read-only mode. Other keyword arguments: length -- length of the bitstring in bits, if needed and appropriate. It must be supplied for all integer and float initialisers. offset -- bit offset to the data. These offset bits are ignored and this is intended for use when initialising using 'bytes' or 'filename'.
Reimplemented from Bits.
Reimplemented in BitStream.
Definition at line 3025 of file bitstring.py.
def __copy__ | ( | self | ) |
Return a new copy of the BitArray.
Reimplemented from Bits.
Reimplemented in BitStream.
Definition at line 3081 of file bitstring.py.
def __delitem__ | ( | self, | |
key | |||
) |
Delete item or range. Indices are in units of the step parameter (default 1 bit). Stepping is used to specify the number of bits in each item. >>> a = BitArray('0x001122') >>> del a[1:2:8] >>> print a 0x0022
Definition at line 3200 of file bitstring.py.
def __iadd__ | ( | self, | |
bs | |||
) |
Append bs to current bitstring. Return self. bs -- the bitstring to append.
Definition at line 3072 of file bitstring.py.
def __iand__ | ( | self, | |
bs | |||
) |
Definition at line 3297 of file bitstring.py.
def __ilshift__ | ( | self, | |
n | |||
) |
Shift bits by n to the left in place. Return self. n -- the number of bits to shift. Must be >= 0.
Definition at line 3249 of file bitstring.py.
def __imul__ | ( | self, | |
n | |||
) |
Concatenate n copies of self in place. Return self. Called for expressions of the form 'a *= 3'. n -- The number of concatenations. Must be >= 0.
Definition at line 3279 of file bitstring.py.
def __ior__ | ( | self, | |
bs | |||
) |
Definition at line 3290 of file bitstring.py.
def __irshift__ | ( | self, | |
n | |||
) |
Shift bits by n to the right in place. Return self. n -- the number of bits to shift. Must be >= 0.
Definition at line 3264 of file bitstring.py.
def __ixor__ | ( | self, | |
bs | |||
) |
Definition at line 3304 of file bitstring.py.
def __new__ | ( | cls, | |
auto = None , |
|||
length = None , |
|||
offset = None , |
|||
** | kwargs | ||
) |
Reimplemented from Bits.
Definition at line 3066 of file bitstring.py.
def __setitem__ | ( | self, | |
key, | |||
value | |||
) |
Set item or range to new value. Indices are in units of the step parameter (default 1 bit). Stepping is used to specify the number of bits in each item. If the length of the bitstring is changed then pos will be moved to after the inserted section, otherwise it will remain unchanged. >>> s = BitArray('0xff') >>> s[0:1:4] = '0xe' >>> print s '0xef' >>> s[4:4] = '0x00' >>> print s '0xe00f'
Definition at line 3092 of file bitstring.py.
def append | ( | self, | |
bs | |||
) |
Append a bitstring to the current bitstring. bs -- The bitstring to append.
Definition at line 3430 of file bitstring.py.
def byteswap | ( | self, | |
fmt = None , |
|||
start = None , |
|||
end = None , |
|||
repeat = True |
|||
) |
Change the endianness in-place. Return number of repeats of fmt done. fmt -- A compact structure string, an integer number of bytes or an iterable of integers. Defaults to 0, which byte reverses the whole bitstring. 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.
Definition at line 3566 of file bitstring.py.
def clear | ( | self | ) |
Remove all bits, reset to zero length.
Definition at line 3626 of file bitstring.py.
def copy | ( | self | ) |
Return a copy of the bitstring.
Definition at line 3630 of file bitstring.py.
def insert | ( | self, | |
bs, | |||
pos = None |
|||
) |
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.
Definition at line 3378 of file bitstring.py.
def invert | ( | self, | |
pos = None |
|||
) |
Invert one or many bits from 0 to 1 or vice versa. pos -- Either a single bit position or an iterable of bit positions. Negative numbers are treated in the same way as slice indices. Raises IndexError if pos < -self.len or pos >= self.len.
Definition at line 3499 of file bitstring.py.
def overwrite | ( | self, | |
bs, | |||
pos = None |
|||
) |
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
Definition at line 3403 of file bitstring.py.
def prepend | ( | self, | |
bs | |||
) |
Prepend a bitstring to the current bitstring. bs -- The bitstring to prepend.
Reimplemented in BitStream.
Definition at line 3440 of file bitstring.py.
def replace | ( | self, | |
old, | |||
new, | |||
start = None , |
|||
end = None , |
|||
count = None , |
|||
bytealigned = None |
|||
) |
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. end -- Any occurrences that finish after this will not be replaced. Defaults to self.len. count -- The maximum number of replacements to make. Defaults to replace all occurrences. bytealigned -- If True replacements will only be made on byte boundaries. Raises ValueError if old is empty or if start or end are out of range.
Definition at line 3311 of file bitstring.py.
def reverse | ( | self, | |
start = None , |
|||
end = None |
|||
) |
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.
Definition at line 3449 of file bitstring.py.
def rol | ( | self, | |
bits, | |||
start = None , |
|||
end = None |
|||
) |
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.
Definition at line 3544 of file bitstring.py.
def ror | ( | self, | |
bits, | |||
start = None , |
|||
end = None |
|||
) |
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.
Definition at line 3522 of file bitstring.py.
def set | ( | self, | |
value, | |||
pos = None |
|||
) |
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.
Definition at line 3469 of file bitstring.py.
|
staticprivate |
Definition at line 3023 of file bitstring.py.
|
staticprivate |
Definition at line 3020 of file bitstring.py.
|
protected |
Definition at line 3371 of file bitstring.py.
|
static |
Definition at line 3685 of file bitstring.py.
|
static |
Definition at line 3691 of file bitstring.py.
|
static |
Definition at line 3694 of file bitstring.py.
|
static |
Definition at line 3640 of file bitstring.py.
|
static |
Definition at line 3649 of file bitstring.py.
|
static |
Definition at line 3658 of file bitstring.py.
|
static |
Definition at line 3667 of file bitstring.py.
|
static |
Definition at line 3682 of file bitstring.py.
|
static |
Definition at line 3634 of file bitstring.py.
|
static |
Definition at line 3643 of file bitstring.py.
|
static |
Definition at line 3652 of file bitstring.py.
|
static |
Definition at line 3661 of file bitstring.py.
|
static |
Definition at line 3688 of file bitstring.py.
|
static |
Definition at line 3673 of file bitstring.py.
|
static |
Definition at line 3679 of file bitstring.py.
|
static |
Definition at line 3670 of file bitstring.py.
|
static |
Definition at line 3676 of file bitstring.py.
|
static |
Definition at line 3637 of file bitstring.py.
|
static |
Definition at line 3646 of file bitstring.py.
|
static |
Definition at line 3655 of file bitstring.py.
|
static |
Definition at line 3664 of file bitstring.py.