How to use the bitstring.bitarray.BitArray function in bitstring

To help you get started, we’ve selected a few bitstring examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scott-griffiths / bitstring / bitstring / bitarray.py View on Github external
def __new__(cls, auto=None, length=None, offset=None, **kwargs):
        x = object.__new__(BitArray)
        y = bits.Bits.__new__(BitArray, auto, length, offset, **kwargs)
        x._datastore = y._datastore
        return x
github scott-griffiths / bitstring / bitstring / bitarray.py View on Github external
def __copy__(self):
        """Return a new copy of the BitArray."""
        s_copy = BitArray()
        if not isinstance(self._datastore, ByteStore):
            # Let them both point to the same (invariant) array.
            # If either gets modified then at that point they'll be read into memory.
            s_copy._datastore = self._datastore
        else:
            s_copy._datastore = copy.copy(self._datastore)
        return s_copy
github scott-griffiths / bitstring / bitstring / bitstream.py View on Github external
# Let them both point to the same (invariant) array.
            # If either gets modified then at that point they'll be read into memory.
            s_copy._datastore = self._datastore
        else:
            s_copy._datastore = ByteStore(self._datastore._rawarray[:],
                                          self._datastore.bitlength,
                                          self._datastore.offset)
        return s_copy

    def prepend(self, bs):
        # Docstring follows. This method is needed to get the bit position right.
        bs = self._converttobitstring(bs)
        self._prepend(bs)
        self._pos += bs.len

    prepend.__doc__ = bitarray.BitArray.prepend.__doc__


def pack(fmt, *values, **kwargs):
    """Pack the values according to the format string and return a new BitStream.

    fmt -- A single string or a list of strings with comma separated tokens
           describing how to create the 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.

    Token examples: 'int:12'    : 12 bits as a signed integer
                    'uint:8'    : 8 bits as an unsigned integer
                    'float:64'  : 8 bytes as a big-endian float
                    'intbe:16'  : 2 bytes as a big-endian signed integer
                    'uintbe:16' : 2 bytes as a big-endian unsigned integer
github scott-griffiths / bitstring / bitstring / bitstream.py View on Github external
#!/usr/bin/env python

import bitstring
import bitstring.constbitstream as constbitstream
import bitstring.bitarray as bitarray
from bitstring.bitstore import ByteStore

# Hack for Python 3
try:
    xrange
except NameError:
    xrange = range
    basestring = str

class BitStream(constbitstream.ConstBitStream, bitarray.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.
github scott-griffiths / bitstring / bitstring / bitarray.py View on Github external
def __new__(cls, auto=None, length=None, offset=None, **kwargs):
        x = object.__new__(BitArray)
        y = bits.Bits.__new__(BitArray, auto, length, offset, **kwargs)
        x._datastore = y._datastore
        return x