repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
scott-griffiths/bitstring
bitstring.py
ConstByteStore._appendstore
def _appendstore(self, store): """Join another store on to the end of this one.""" if not store.bitlength: return # Set new array offset to the number of bits in the final byte of current array. store = offsetcopy(store, (self.offset + self.bitlength) % 8) if store.of...
python
def _appendstore(self, store): """Join another store on to the end of this one.""" if not store.bitlength: return # Set new array offset to the number of bits in the final byte of current array. store = offsetcopy(store, (self.offset + self.bitlength) % 8) if store.of...
[ "def", "_appendstore", "(", "self", ",", "store", ")", ":", "if", "not", "store", ".", "bitlength", ":", "return", "# Set new array offset to the number of bits in the final byte of current array.", "store", "=", "offsetcopy", "(", "store", ",", "(", "self", ".", "o...
Join another store on to the end of this one.
[ "Join", "another", "store", "on", "to", "the", "end", "of", "this", "one", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L173-L187
train
scott-griffiths/bitstring
bitstring.py
ConstByteStore._prependstore
def _prependstore(self, store): """Join another store on to the start of this one.""" if not store.bitlength: return # Set the offset of copy of store so that it's final byte # ends in a position that matches the offset of self, # then join self on to the end of i...
python
def _prependstore(self, store): """Join another store on to the start of this one.""" if not store.bitlength: return # Set the offset of copy of store so that it's final byte # ends in a position that matches the offset of self, # then join self on to the end of i...
[ "def", "_prependstore", "(", "self", ",", "store", ")", ":", "if", "not", "store", ".", "bitlength", ":", "return", "# Set the offset of copy of store so that it's final byte", "# ends in a position that matches the offset of self,", "# then join self on to the end of it.", "stor...
Join another store on to the start of this one.
[ "Join", "another", "store", "on", "to", "the", "start", "of", "this", "one", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L189-L208
train
scott-griffiths/bitstring
bitstring.py
Bits._assertsanity
def _assertsanity(self): """Check internal self consistency as a debugging aid.""" assert self.len >= 0 assert 0 <= self._offset, "offset={0}".format(self._offset) assert (self.len + self._offset + 7) // 8 == self._datastore.bytelength + self._datastore.byteoffset return True
python
def _assertsanity(self): """Check internal self consistency as a debugging aid.""" assert self.len >= 0 assert 0 <= self._offset, "offset={0}".format(self._offset) assert (self.len + self._offset + 7) // 8 == self._datastore.bytelength + self._datastore.byteoffset return True
[ "def", "_assertsanity", "(", "self", ")", ":", "assert", "self", ".", "len", ">=", "0", "assert", "0", "<=", "self", ".", "_offset", ",", "\"offset={0}\"", ".", "format", "(", "self", ".", "_offset", ")", "assert", "(", "self", ".", "len", "+", "self...
Check internal self consistency as a debugging aid.
[ "Check", "internal", "self", "consistency", "as", "a", "debugging", "aid", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1195-L1200
train
scott-griffiths/bitstring
bitstring.py
Bits._setauto
def _setauto(self, s, length, offset): """Set bitstring from a bitstring, file, bool, integer, array, iterable or string.""" # As s can be so many different things it's important to do the checks # in the correct order, as some types are also other allowed types. # So basestring must be ...
python
def _setauto(self, s, length, offset): """Set bitstring from a bitstring, file, bool, integer, array, iterable or string.""" # As s can be so many different things it's important to do the checks # in the correct order, as some types are also other allowed types. # So basestring must be ...
[ "def", "_setauto", "(", "self", ",", "s", ",", "length", ",", "offset", ")", ":", "# As s can be so many different things it's important to do the checks", "# in the correct order, as some types are also other allowed types.", "# So basestring must be checked before Iterable", "# and b...
Set bitstring from a bitstring, file, bool, integer, array, iterable or string.
[ "Set", "bitstring", "from", "a", "bitstring", "file", "bool", "integer", "array", "iterable", "or", "string", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1245-L1297
train
scott-griffiths/bitstring
bitstring.py
Bits._setfile
def _setfile(self, filename, length, offset): """Use file as source of bits.""" source = open(filename, 'rb') if offset is None: offset = 0 if length is None: length = os.path.getsize(source.name) * 8 - offset byteoffset, offset = divmod(offset, 8) ...
python
def _setfile(self, filename, length, offset): """Use file as source of bits.""" source = open(filename, 'rb') if offset is None: offset = 0 if length is None: length = os.path.getsize(source.name) * 8 - offset byteoffset, offset = divmod(offset, 8) ...
[ "def", "_setfile", "(", "self", ",", "filename", ",", "length", ",", "offset", ")", ":", "source", "=", "open", "(", "filename", ",", "'rb'", ")", "if", "offset", "is", "None", ":", "offset", "=", "0", "if", "length", "is", "None", ":", "length", "...
Use file as source of bits.
[ "Use", "file", "as", "source", "of", "bits", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1299-L1312
train
scott-griffiths/bitstring
bitstring.py
Bits._setbytes_safe
def _setbytes_safe(self, data, length=None, offset=0): """Set the data from a string.""" data = bytearray(data) if length is None: # Use to the end of the data length = len(data)*8 - offset self._datastore = ByteStore(data, length, offset) else: ...
python
def _setbytes_safe(self, data, length=None, offset=0): """Set the data from a string.""" data = bytearray(data) if length is None: # Use to the end of the data length = len(data)*8 - offset self._datastore = ByteStore(data, length, offset) else: ...
[ "def", "_setbytes_safe", "(", "self", ",", "data", ",", "length", "=", "None", ",", "offset", "=", "0", ")", ":", "data", "=", "bytearray", "(", "data", ")", "if", "length", "is", "None", ":", "# Use to the end of the data", "length", "=", "len", "(", ...
Set the data from a string.
[ "Set", "the", "data", "from", "a", "string", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1314-L1328
train
scott-griffiths/bitstring
bitstring.py
Bits._setbytes_unsafe
def _setbytes_unsafe(self, data, length, offset): """Unchecked version of _setbytes_safe.""" self._datastore = ByteStore(data[:], length, offset) assert self._assertsanity()
python
def _setbytes_unsafe(self, data, length, offset): """Unchecked version of _setbytes_safe.""" self._datastore = ByteStore(data[:], length, offset) assert self._assertsanity()
[ "def", "_setbytes_unsafe", "(", "self", ",", "data", ",", "length", ",", "offset", ")", ":", "self", ".", "_datastore", "=", "ByteStore", "(", "data", "[", ":", "]", ",", "length", ",", "offset", ")", "assert", "self", ".", "_assertsanity", "(", ")" ]
Unchecked version of _setbytes_safe.
[ "Unchecked", "version", "of", "_setbytes_safe", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1330-L1333
train
scott-griffiths/bitstring
bitstring.py
Bits._readbytes
def _readbytes(self, length, start): """Read bytes and return them. Note that length is in bits.""" assert length % 8 == 0 assert start + length <= self.len if not (start + self._offset) % 8: return bytes(self._datastore.getbyteslice((start + self._offset) // 8, ...
python
def _readbytes(self, length, start): """Read bytes and return them. Note that length is in bits.""" assert length % 8 == 0 assert start + length <= self.len if not (start + self._offset) % 8: return bytes(self._datastore.getbyteslice((start + self._offset) // 8, ...
[ "def", "_readbytes", "(", "self", ",", "length", ",", "start", ")", ":", "assert", "length", "%", "8", "==", "0", "assert", "start", "+", "length", "<=", "self", ".", "len", "if", "not", "(", "start", "+", "self", ".", "_offset", ")", "%", "8", "...
Read bytes and return them. Note that length is in bits.
[ "Read", "bytes", "and", "return", "them", ".", "Note", "that", "length", "is", "in", "bits", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1335-L1342
train
scott-griffiths/bitstring
bitstring.py
Bits._setuint
def _setuint(self, uint, length=None): """Reset the bitstring to have given unsigned int interpretation.""" try: if length is None: # Use the whole length. Deliberately not using .len here. length = self._datastore.bitlength except AttributeError: ...
python
def _setuint(self, uint, length=None): """Reset the bitstring to have given unsigned int interpretation.""" try: if length is None: # Use the whole length. Deliberately not using .len here. length = self._datastore.bitlength except AttributeError: ...
[ "def", "_setuint", "(", "self", ",", "uint", ",", "length", "=", "None", ")", ":", "try", ":", "if", "length", "is", "None", ":", "# Use the whole length. Deliberately not using .len here.", "length", "=", "self", ".", "_datastore", ".", "bitlength", "except", ...
Reset the bitstring to have given unsigned int interpretation.
[ "Reset", "the", "bitstring", "to", "have", "given", "unsigned", "int", "interpretation", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1351-L1386
train
scott-griffiths/bitstring
bitstring.py
Bits._readuint
def _readuint(self, length, start): """Read bits and interpret as an unsigned int.""" if not length: raise InterpretError("Cannot interpret a zero length bitstring " "as an integer.") offset = self._offset startbyte = (start + offset...
python
def _readuint(self, length, start): """Read bits and interpret as an unsigned int.""" if not length: raise InterpretError("Cannot interpret a zero length bitstring " "as an integer.") offset = self._offset startbyte = (start + offset...
[ "def", "_readuint", "(", "self", ",", "length", ",", "start", ")", ":", "if", "not", "length", ":", "raise", "InterpretError", "(", "\"Cannot interpret a zero length bitstring \"", "\"as an integer.\"", ")", "offset", "=", "self", ".", "_offset", "startbyte", "=",...
Read bits and interpret as an unsigned int.
[ "Read", "bits", "and", "interpret", "as", "an", "unsigned", "int", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1388-L1404
train
scott-griffiths/bitstring
bitstring.py
Bits._setint
def _setint(self, int_, length=None): """Reset the bitstring to have given signed int interpretation.""" # If no length given, and we've previously been given a length, use it. if length is None and hasattr(self, 'len') and self.len != 0: length = self.len if length is None o...
python
def _setint(self, int_, length=None): """Reset the bitstring to have given signed int interpretation.""" # If no length given, and we've previously been given a length, use it. if length is None and hasattr(self, 'len') and self.len != 0: length = self.len if length is None o...
[ "def", "_setint", "(", "self", ",", "int_", ",", "length", "=", "None", ")", ":", "# If no length given, and we've previously been given a length, use it.", "if", "length", "is", "None", "and", "hasattr", "(", "self", ",", "'len'", ")", "and", "self", ".", "len"...
Reset the bitstring to have given signed int interpretation.
[ "Reset", "the", "bitstring", "to", "have", "given", "signed", "int", "interpretation", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1410-L1431
train
scott-griffiths/bitstring
bitstring.py
Bits._readint
def _readint(self, length, start): """Read bits and interpret as a signed int""" ui = self._readuint(length, start) if not ui >> (length - 1): # Top bit not set, number is positive return ui # Top bit is set, so number is negative tmp = (~(ui - 1)) & ((1 <...
python
def _readint(self, length, start): """Read bits and interpret as a signed int""" ui = self._readuint(length, start) if not ui >> (length - 1): # Top bit not set, number is positive return ui # Top bit is set, so number is negative tmp = (~(ui - 1)) & ((1 <...
[ "def", "_readint", "(", "self", ",", "length", ",", "start", ")", ":", "ui", "=", "self", ".", "_readuint", "(", "length", ",", "start", ")", "if", "not", "ui", ">>", "(", "length", "-", "1", ")", ":", "# Top bit not set, number is positive", "return", ...
Read bits and interpret as a signed int
[ "Read", "bits", "and", "interpret", "as", "a", "signed", "int" ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1433-L1441
train
scott-griffiths/bitstring
bitstring.py
Bits._setuintbe
def _setuintbe(self, uintbe, length=None): """Set the bitstring to a big-endian unsigned int interpretation.""" if length is not None and length % 8 != 0: raise CreationError("Big-endian integers must be whole-byte. " "Length = {0} bits.", length) self...
python
def _setuintbe(self, uintbe, length=None): """Set the bitstring to a big-endian unsigned int interpretation.""" if length is not None and length % 8 != 0: raise CreationError("Big-endian integers must be whole-byte. " "Length = {0} bits.", length) self...
[ "def", "_setuintbe", "(", "self", ",", "uintbe", ",", "length", "=", "None", ")", ":", "if", "length", "is", "not", "None", "and", "length", "%", "8", "!=", "0", ":", "raise", "CreationError", "(", "\"Big-endian integers must be whole-byte. \"", "\"Length = {0...
Set the bitstring to a big-endian unsigned int interpretation.
[ "Set", "the", "bitstring", "to", "a", "big", "-", "endian", "unsigned", "int", "interpretation", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1447-L1452
train
scott-griffiths/bitstring
bitstring.py
Bits._readuintbe
def _readuintbe(self, length, start): """Read bits and interpret as a big-endian unsigned int.""" if length % 8: raise InterpretError("Big-endian integers must be whole-byte. " "Length = {0} bits.", length) return self._readuint(length, start)
python
def _readuintbe(self, length, start): """Read bits and interpret as a big-endian unsigned int.""" if length % 8: raise InterpretError("Big-endian integers must be whole-byte. " "Length = {0} bits.", length) return self._readuint(length, start)
[ "def", "_readuintbe", "(", "self", ",", "length", ",", "start", ")", ":", "if", "length", "%", "8", ":", "raise", "InterpretError", "(", "\"Big-endian integers must be whole-byte. \"", "\"Length = {0} bits.\"", ",", "length", ")", "return", "self", ".", "_readuint...
Read bits and interpret as a big-endian unsigned int.
[ "Read", "bits", "and", "interpret", "as", "a", "big", "-", "endian", "unsigned", "int", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1454-L1459
train
scott-griffiths/bitstring
bitstring.py
Bits._setintbe
def _setintbe(self, intbe, length=None): """Set bitstring to a big-endian signed int interpretation.""" if length is not None and length % 8 != 0: raise CreationError("Big-endian integers must be whole-byte. " "Length = {0} bits.", length) self._setint...
python
def _setintbe(self, intbe, length=None): """Set bitstring to a big-endian signed int interpretation.""" if length is not None and length % 8 != 0: raise CreationError("Big-endian integers must be whole-byte. " "Length = {0} bits.", length) self._setint...
[ "def", "_setintbe", "(", "self", ",", "intbe", ",", "length", "=", "None", ")", ":", "if", "length", "is", "not", "None", "and", "length", "%", "8", "!=", "0", ":", "raise", "CreationError", "(", "\"Big-endian integers must be whole-byte. \"", "\"Length = {0} ...
Set bitstring to a big-endian signed int interpretation.
[ "Set", "bitstring", "to", "a", "big", "-", "endian", "signed", "int", "interpretation", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1465-L1470
train
scott-griffiths/bitstring
bitstring.py
Bits._readintbe
def _readintbe(self, length, start): """Read bits and interpret as a big-endian signed int.""" if length % 8: raise InterpretError("Big-endian integers must be whole-byte. " "Length = {0} bits.", length) return self._readint(length, start)
python
def _readintbe(self, length, start): """Read bits and interpret as a big-endian signed int.""" if length % 8: raise InterpretError("Big-endian integers must be whole-byte. " "Length = {0} bits.", length) return self._readint(length, start)
[ "def", "_readintbe", "(", "self", ",", "length", ",", "start", ")", ":", "if", "length", "%", "8", ":", "raise", "InterpretError", "(", "\"Big-endian integers must be whole-byte. \"", "\"Length = {0} bits.\"", ",", "length", ")", "return", "self", ".", "_readint",...
Read bits and interpret as a big-endian signed int.
[ "Read", "bits", "and", "interpret", "as", "a", "big", "-", "endian", "signed", "int", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1472-L1477
train
scott-griffiths/bitstring
bitstring.py
Bits._readuintle
def _readuintle(self, length, start): """Read bits and interpret as a little-endian unsigned int.""" if length % 8: raise InterpretError("Little-endian integers must be whole-byte. " "Length = {0} bits.", length) assert start + length <= self.len ...
python
def _readuintle(self, length, start): """Read bits and interpret as a little-endian unsigned int.""" if length % 8: raise InterpretError("Little-endian integers must be whole-byte. " "Length = {0} bits.", length) assert start + length <= self.len ...
[ "def", "_readuintle", "(", "self", ",", "length", ",", "start", ")", ":", "if", "length", "%", "8", ":", "raise", "InterpretError", "(", "\"Little-endian integers must be whole-byte. \"", "\"Length = {0} bits.\"", ",", "length", ")", "assert", "start", "+", "lengt...
Read bits and interpret as a little-endian unsigned int.
[ "Read", "bits", "and", "interpret", "as", "a", "little", "-", "endian", "unsigned", "int", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1490-L1516
train
scott-griffiths/bitstring
bitstring.py
Bits._readintle
def _readintle(self, length, start): """Read bits and interpret as a little-endian signed int.""" ui = self._readuintle(length, start) if not ui >> (length - 1): # Top bit not set, number is positive return ui # Top bit is set, so number is negative tmp = ...
python
def _readintle(self, length, start): """Read bits and interpret as a little-endian signed int.""" ui = self._readuintle(length, start) if not ui >> (length - 1): # Top bit not set, number is positive return ui # Top bit is set, so number is negative tmp = ...
[ "def", "_readintle", "(", "self", ",", "length", ",", "start", ")", ":", "ui", "=", "self", ".", "_readuintle", "(", "length", ",", "start", ")", "if", "not", "ui", ">>", "(", "length", "-", "1", ")", ":", "# Top bit not set, number is positive", "return...
Read bits and interpret as a little-endian signed int.
[ "Read", "bits", "and", "interpret", "as", "a", "little", "-", "endian", "signed", "int", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1528-L1536
train
scott-griffiths/bitstring
bitstring.py
Bits._readfloat
def _readfloat(self, length, start): """Read bits and interpret as a float.""" if not (start + self._offset) % 8: startbyte = (start + self._offset) // 8 if length == 32: f, = struct.unpack('>f', bytes(self._datastore.getbyteslice(startbyte, startbyte + 4))) ...
python
def _readfloat(self, length, start): """Read bits and interpret as a float.""" if not (start + self._offset) % 8: startbyte = (start + self._offset) // 8 if length == 32: f, = struct.unpack('>f', bytes(self._datastore.getbyteslice(startbyte, startbyte + 4))) ...
[ "def", "_readfloat", "(", "self", ",", "length", ",", "start", ")", ":", "if", "not", "(", "start", "+", "self", ".", "_offset", ")", "%", "8", ":", "startbyte", "=", "(", "start", "+", "self", ".", "_offset", ")", "//", "8", "if", "length", "=="...
Read bits and interpret as a float.
[ "Read", "bits", "and", "interpret", "as", "a", "float", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1557-L1573
train
scott-griffiths/bitstring
bitstring.py
Bits._readfloatle
def _readfloatle(self, length, start): """Read bits and interpret as a little-endian float.""" startbyte, offset = divmod(start + self._offset, 8) if not offset: if length == 32: f, = struct.unpack('<f', bytes(self._datastore.getbyteslice(startbyte, startbyte + 4))) ...
python
def _readfloatle(self, length, start): """Read bits and interpret as a little-endian float.""" startbyte, offset = divmod(start + self._offset, 8) if not offset: if length == 32: f, = struct.unpack('<f', bytes(self._datastore.getbyteslice(startbyte, startbyte + 4))) ...
[ "def", "_readfloatle", "(", "self", ",", "length", ",", "start", ")", ":", "startbyte", ",", "offset", "=", "divmod", "(", "start", "+", "self", ".", "_offset", ",", "8", ")", "if", "not", "offset", ":", "if", "length", "==", "32", ":", "f", ",", ...
Read bits and interpret as a little-endian float.
[ "Read", "bits", "and", "interpret", "as", "a", "little", "-", "endian", "float", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1595-L1612
train
scott-griffiths/bitstring
bitstring.py
Bits._setue
def _setue(self, i): """Initialise bitstring with unsigned exponential-Golomb code for integer i. Raises CreationError if i < 0. """ if i < 0: raise CreationError("Cannot use negative initialiser for unsigned " "exponential-Golomb.") ...
python
def _setue(self, i): """Initialise bitstring with unsigned exponential-Golomb code for integer i. Raises CreationError if i < 0. """ if i < 0: raise CreationError("Cannot use negative initialiser for unsigned " "exponential-Golomb.") ...
[ "def", "_setue", "(", "self", ",", "i", ")", ":", "if", "i", "<", "0", ":", "raise", "CreationError", "(", "\"Cannot use negative initialiser for unsigned \"", "\"exponential-Golomb.\"", ")", "if", "not", "i", ":", "self", ".", "_setbin_unsafe", "(", "'1'", ")...
Initialise bitstring with unsigned exponential-Golomb code for integer i. Raises CreationError if i < 0.
[ "Initialise", "bitstring", "with", "unsigned", "exponential", "-", "Golomb", "code", "for", "integer", "i", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1618-L1638
train
scott-griffiths/bitstring
bitstring.py
Bits._readue
def _readue(self, pos): """Return interpretation of next bits as unsigned exponential-Golomb code. Raises ReadError if the end of the bitstring is encountered while reading the code. """ oldpos = pos try: while not self[pos]: pos += 1 ...
python
def _readue(self, pos): """Return interpretation of next bits as unsigned exponential-Golomb code. Raises ReadError if the end of the bitstring is encountered while reading the code. """ oldpos = pos try: while not self[pos]: pos += 1 ...
[ "def", "_readue", "(", "self", ",", "pos", ")", ":", "oldpos", "=", "pos", "try", ":", "while", "not", "self", "[", "pos", "]", ":", "pos", "+=", "1", "except", "IndexError", ":", "raise", "ReadError", "(", "\"Read off end of bitstring trying to read code.\"...
Return interpretation of next bits as unsigned exponential-Golomb code. Raises ReadError if the end of the bitstring is encountered while reading the code.
[ "Return", "interpretation", "of", "next", "bits", "as", "unsigned", "exponential", "-", "Golomb", "code", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1640-L1663
train
scott-griffiths/bitstring
bitstring.py
Bits._getue
def _getue(self): """Return data as unsigned exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code. """ try: value, newpos = self._readue(0) if value is None or newpos != self.len: raise ReadError ...
python
def _getue(self): """Return data as unsigned exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code. """ try: value, newpos = self._readue(0) if value is None or newpos != self.len: raise ReadError ...
[ "def", "_getue", "(", "self", ")", ":", "try", ":", "value", ",", "newpos", "=", "self", ".", "_readue", "(", "0", ")", "if", "value", "is", "None", "or", "newpos", "!=", "self", ".", "len", ":", "raise", "ReadError", "except", "ReadError", ":", "r...
Return data as unsigned exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code.
[ "Return", "data", "as", "unsigned", "exponential", "-", "Golomb", "code", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1665-L1677
train
scott-griffiths/bitstring
bitstring.py
Bits._setse
def _setse(self, i): """Initialise bitstring with signed exponential-Golomb code for integer i.""" if i > 0: u = (i * 2) - 1 else: u = -2 * i self._setue(u)
python
def _setse(self, i): """Initialise bitstring with signed exponential-Golomb code for integer i.""" if i > 0: u = (i * 2) - 1 else: u = -2 * i self._setue(u)
[ "def", "_setse", "(", "self", ",", "i", ")", ":", "if", "i", ">", "0", ":", "u", "=", "(", "i", "*", "2", ")", "-", "1", "else", ":", "u", "=", "-", "2", "*", "i", "self", ".", "_setue", "(", "u", ")" ]
Initialise bitstring with signed exponential-Golomb code for integer i.
[ "Initialise", "bitstring", "with", "signed", "exponential", "-", "Golomb", "code", "for", "integer", "i", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1679-L1685
train
scott-griffiths/bitstring
bitstring.py
Bits._getse
def _getse(self): """Return data as signed exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code. """ try: value, newpos = self._readse(0) if value is None or newpos != self.len: raise ReadError ...
python
def _getse(self): """Return data as signed exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code. """ try: value, newpos = self._readse(0) if value is None or newpos != self.len: raise ReadError ...
[ "def", "_getse", "(", "self", ")", ":", "try", ":", "value", ",", "newpos", "=", "self", ".", "_readse", "(", "0", ")", "if", "value", "is", "None", "or", "newpos", "!=", "self", ".", "len", ":", "raise", "ReadError", "except", "ReadError", ":", "r...
Return data as signed exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code.
[ "Return", "data", "as", "signed", "exponential", "-", "Golomb", "code", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1687-L1699
train
scott-griffiths/bitstring
bitstring.py
Bits._readse
def _readse(self, pos): """Return interpretation of next bits as a signed exponential-Golomb code. Advances position to after the read code. Raises ReadError if the end of the bitstring is encountered while reading the code. """ codenum, pos = self._readue(pos) ...
python
def _readse(self, pos): """Return interpretation of next bits as a signed exponential-Golomb code. Advances position to after the read code. Raises ReadError if the end of the bitstring is encountered while reading the code. """ codenum, pos = self._readue(pos) ...
[ "def", "_readse", "(", "self", ",", "pos", ")", ":", "codenum", ",", "pos", "=", "self", ".", "_readue", "(", "pos", ")", "m", "=", "(", "codenum", "+", "1", ")", "//", "2", "if", "not", "codenum", "%", "2", ":", "return", "-", "m", ",", "pos...
Return interpretation of next bits as a signed exponential-Golomb code. Advances position to after the read code. Raises ReadError if the end of the bitstring is encountered while reading the code.
[ "Return", "interpretation", "of", "next", "bits", "as", "a", "signed", "exponential", "-", "Golomb", "code", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1701-L1715
train
scott-griffiths/bitstring
bitstring.py
Bits._setuie
def _setuie(self, i): """Initialise bitstring with unsigned interleaved exponential-Golomb code for integer i. Raises CreationError if i < 0. """ if i < 0: raise CreationError("Cannot use negative initialiser for unsigned " "interleaved expon...
python
def _setuie(self, i): """Initialise bitstring with unsigned interleaved exponential-Golomb code for integer i. Raises CreationError if i < 0. """ if i < 0: raise CreationError("Cannot use negative initialiser for unsigned " "interleaved expon...
[ "def", "_setuie", "(", "self", ",", "i", ")", ":", "if", "i", "<", "0", ":", "raise", "CreationError", "(", "\"Cannot use negative initialiser for unsigned \"", "\"interleaved exponential-Golomb.\"", ")", "self", ".", "_setbin_unsafe", "(", "'1'", "if", "i", "==",...
Initialise bitstring with unsigned interleaved exponential-Golomb code for integer i. Raises CreationError if i < 0.
[ "Initialise", "bitstring", "with", "unsigned", "interleaved", "exponential", "-", "Golomb", "code", "for", "integer", "i", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1717-L1726
train
scott-griffiths/bitstring
bitstring.py
Bits._getuie
def _getuie(self): """Return data as unsigned interleaved exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code. """ try: value, newpos = self._readuie(0) if value is None or newpos != self.len: raise...
python
def _getuie(self): """Return data as unsigned interleaved exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code. """ try: value, newpos = self._readuie(0) if value is None or newpos != self.len: raise...
[ "def", "_getuie", "(", "self", ")", ":", "try", ":", "value", ",", "newpos", "=", "self", ".", "_readuie", "(", "0", ")", "if", "value", "is", "None", "or", "newpos", "!=", "self", ".", "len", ":", "raise", "ReadError", "except", "ReadError", ":", ...
Return data as unsigned interleaved exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code.
[ "Return", "data", "as", "unsigned", "interleaved", "exponential", "-", "Golomb", "code", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1748-L1760
train
scott-griffiths/bitstring
bitstring.py
Bits._setsie
def _setsie(self, i): """Initialise bitstring with signed interleaved exponential-Golomb code for integer i.""" if not i: self._setbin_unsafe('1') else: self._setuie(abs(i)) self._append(Bits([i < 0]))
python
def _setsie(self, i): """Initialise bitstring with signed interleaved exponential-Golomb code for integer i.""" if not i: self._setbin_unsafe('1') else: self._setuie(abs(i)) self._append(Bits([i < 0]))
[ "def", "_setsie", "(", "self", ",", "i", ")", ":", "if", "not", "i", ":", "self", ".", "_setbin_unsafe", "(", "'1'", ")", "else", ":", "self", ".", "_setuie", "(", "abs", "(", "i", ")", ")", "self", ".", "_append", "(", "Bits", "(", "[", "i", ...
Initialise bitstring with signed interleaved exponential-Golomb code for integer i.
[ "Initialise", "bitstring", "with", "signed", "interleaved", "exponential", "-", "Golomb", "code", "for", "integer", "i", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1762-L1768
train
scott-griffiths/bitstring
bitstring.py
Bits._getsie
def _getsie(self): """Return data as signed interleaved exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code. """ try: value, newpos = self._readsie(0) if value is None or newpos != self.len: raise R...
python
def _getsie(self): """Return data as signed interleaved exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code. """ try: value, newpos = self._readsie(0) if value is None or newpos != self.len: raise R...
[ "def", "_getsie", "(", "self", ")", ":", "try", ":", "value", ",", "newpos", "=", "self", ".", "_readsie", "(", "0", ")", "if", "value", "is", "None", "or", "newpos", "!=", "self", ".", "len", ":", "raise", "ReadError", "except", "ReadError", ":", ...
Return data as signed interleaved exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code.
[ "Return", "data", "as", "signed", "interleaved", "exponential", "-", "Golomb", "code", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1770-L1782
train
scott-griffiths/bitstring
bitstring.py
Bits._readsie
def _readsie(self, pos): """Return interpretation of next bits as a signed interleaved exponential-Golomb code. Advances position to after the read code. Raises ReadError if the end of the bitstring is encountered while reading the code. """ codenum, pos = self._readui...
python
def _readsie(self, pos): """Return interpretation of next bits as a signed interleaved exponential-Golomb code. Advances position to after the read code. Raises ReadError if the end of the bitstring is encountered while reading the code. """ codenum, pos = self._readui...
[ "def", "_readsie", "(", "self", ",", "pos", ")", ":", "codenum", ",", "pos", "=", "self", ".", "_readuie", "(", "pos", ")", "if", "not", "codenum", ":", "return", "0", ",", "pos", "try", ":", "if", "self", "[", "pos", "]", ":", "return", "-", "...
Return interpretation of next bits as a signed interleaved exponential-Golomb code. Advances position to after the read code. Raises ReadError if the end of the bitstring is encountered while reading the code.
[ "Return", "interpretation", "of", "next", "bits", "as", "a", "signed", "interleaved", "exponential", "-", "Golomb", "code", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1784-L1802
train
scott-griffiths/bitstring
bitstring.py
Bits._setbin_safe
def _setbin_safe(self, binstring): """Reset the bitstring to the value given in binstring.""" binstring = tidy_input_string(binstring) # remove any 0b if present binstring = binstring.replace('0b', '') self._setbin_unsafe(binstring)
python
def _setbin_safe(self, binstring): """Reset the bitstring to the value given in binstring.""" binstring = tidy_input_string(binstring) # remove any 0b if present binstring = binstring.replace('0b', '') self._setbin_unsafe(binstring)
[ "def", "_setbin_safe", "(", "self", ",", "binstring", ")", ":", "binstring", "=", "tidy_input_string", "(", "binstring", ")", "# remove any 0b if present", "binstring", "=", "binstring", ".", "replace", "(", "'0b'", ",", "''", ")", "self", ".", "_setbin_unsafe",...
Reset the bitstring to the value given in binstring.
[ "Reset", "the", "bitstring", "to", "the", "value", "given", "in", "binstring", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1823-L1828
train
scott-griffiths/bitstring
bitstring.py
Bits._setbin_unsafe
def _setbin_unsafe(self, binstring): """Same as _setbin_safe, but input isn't sanity checked. binstring mustn't start with '0b'.""" length = len(binstring) # pad with zeros up to byte boundary if needed boundary = ((length + 7) // 8) * 8 padded_binstring = binstring + '0' * (boun...
python
def _setbin_unsafe(self, binstring): """Same as _setbin_safe, but input isn't sanity checked. binstring mustn't start with '0b'.""" length = len(binstring) # pad with zeros up to byte boundary if needed boundary = ((length + 7) // 8) * 8 padded_binstring = binstring + '0' * (boun...
[ "def", "_setbin_unsafe", "(", "self", ",", "binstring", ")", ":", "length", "=", "len", "(", "binstring", ")", "# pad with zeros up to byte boundary if needed", "boundary", "=", "(", "(", "length", "+", "7", ")", "//", "8", ")", "*", "8", "padded_binstring", ...
Same as _setbin_safe, but input isn't sanity checked. binstring mustn't start with '0b'.
[ "Same", "as", "_setbin_safe", "but", "input", "isn", "t", "sanity", "checked", ".", "binstring", "mustn", "t", "start", "with", "0b", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1830-L1842
train
scott-griffiths/bitstring
bitstring.py
Bits._readbin
def _readbin(self, length, start): """Read bits and interpret as a binary string.""" if not length: return '' # Get the byte slice containing our bit slice startbyte, startoffset = divmod(start + self._offset, 8) endbyte = (start + self._offset + length - 1) // 8 ...
python
def _readbin(self, length, start): """Read bits and interpret as a binary string.""" if not length: return '' # Get the byte slice containing our bit slice startbyte, startoffset = divmod(start + self._offset, 8) endbyte = (start + self._offset + length - 1) // 8 ...
[ "def", "_readbin", "(", "self", ",", "length", ",", "start", ")", ":", "if", "not", "length", ":", "return", "''", "# Get the byte slice containing our bit slice", "startbyte", ",", "startoffset", "=", "divmod", "(", "start", "+", "self", ".", "_offset", ",", ...
Read bits and interpret as a binary string.
[ "Read", "bits", "and", "interpret", "as", "a", "binary", "string", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1844-L1859
train
scott-griffiths/bitstring
bitstring.py
Bits._setoct
def _setoct(self, octstring): """Reset the bitstring to have the value given in octstring.""" octstring = tidy_input_string(octstring) # remove any 0o if present octstring = octstring.replace('0o', '') binlist = [] for i in octstring: try: if n...
python
def _setoct(self, octstring): """Reset the bitstring to have the value given in octstring.""" octstring = tidy_input_string(octstring) # remove any 0o if present octstring = octstring.replace('0o', '') binlist = [] for i in octstring: try: if n...
[ "def", "_setoct", "(", "self", ",", "octstring", ")", ":", "octstring", "=", "tidy_input_string", "(", "octstring", ")", "# remove any 0o if present", "octstring", "=", "octstring", ".", "replace", "(", "'0o'", ",", "''", ")", "binlist", "=", "[", "]", "for"...
Reset the bitstring to have the value given in octstring.
[ "Reset", "the", "bitstring", "to", "have", "the", "value", "given", "in", "octstring", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1865-L1878
train
scott-griffiths/bitstring
bitstring.py
Bits._readoct
def _readoct(self, length, start): """Read bits and interpret as an octal string.""" if length % 3: raise InterpretError("Cannot convert to octal unambiguously - " "not multiple of 3 bits.") if not length: return '' # Get main octa...
python
def _readoct(self, length, start): """Read bits and interpret as an octal string.""" if length % 3: raise InterpretError("Cannot convert to octal unambiguously - " "not multiple of 3 bits.") if not length: return '' # Get main octa...
[ "def", "_readoct", "(", "self", ",", "length", ",", "start", ")", ":", "if", "length", "%", "3", ":", "raise", "InterpretError", "(", "\"Cannot convert to octal unambiguously - \"", "\"not multiple of 3 bits.\"", ")", "if", "not", "length", ":", "return", "''", ...
Read bits and interpret as an octal string.
[ "Read", "bits", "and", "interpret", "as", "an", "octal", "string", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1880-L1893
train
scott-griffiths/bitstring
bitstring.py
Bits._sethex
def _sethex(self, hexstring): """Reset the bitstring to have the value given in hexstring.""" hexstring = tidy_input_string(hexstring) # remove any 0x if present hexstring = hexstring.replace('0x', '') length = len(hexstring) if length % 2: hexstring += '0' ...
python
def _sethex(self, hexstring): """Reset the bitstring to have the value given in hexstring.""" hexstring = tidy_input_string(hexstring) # remove any 0x if present hexstring = hexstring.replace('0x', '') length = len(hexstring) if length % 2: hexstring += '0' ...
[ "def", "_sethex", "(", "self", ",", "hexstring", ")", ":", "hexstring", "=", "tidy_input_string", "(", "hexstring", ")", "# remove any 0x if present", "hexstring", "=", "hexstring", ".", "replace", "(", "'0x'", ",", "''", ")", "length", "=", "len", "(", "hex...
Reset the bitstring to have the value given in hexstring.
[ "Reset", "the", "bitstring", "to", "have", "the", "value", "given", "in", "hexstring", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1899-L1915
train
scott-griffiths/bitstring
bitstring.py
Bits._readhex
def _readhex(self, length, start): """Read bits and interpret as a hex string.""" if length % 4: raise InterpretError("Cannot convert to hex unambiguously - " "not multiple of 4 bits.") if not length: return '' s = self._...
python
def _readhex(self, length, start): """Read bits and interpret as a hex string.""" if length % 4: raise InterpretError("Cannot convert to hex unambiguously - " "not multiple of 4 bits.") if not length: return '' s = self._...
[ "def", "_readhex", "(", "self", ",", "length", ",", "start", ")", ":", "if", "length", "%", "4", ":", "raise", "InterpretError", "(", "\"Cannot convert to hex unambiguously - \"", "\"not multiple of 4 bits.\"", ")", "if", "not", "length", ":", "return", "''", "s...
Read bits and interpret as a hex string.
[ "Read", "bits", "and", "interpret", "as", "a", "hex", "string", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1917-L1932
train
scott-griffiths/bitstring
bitstring.py
Bits._ensureinmemory
def _ensureinmemory(self): """Ensure the data is held in memory, not in a file.""" self._setbytes_unsafe(self._datastore.getbyteslice(0, self._datastore.bytelength), self.len, self._offset)
python
def _ensureinmemory(self): """Ensure the data is held in memory, not in a file.""" self._setbytes_unsafe(self._datastore.getbyteslice(0, self._datastore.bytelength), self.len, self._offset)
[ "def", "_ensureinmemory", "(", "self", ")", ":", "self", ".", "_setbytes_unsafe", "(", "self", ".", "_datastore", ".", "getbyteslice", "(", "0", ",", "self", ".", "_datastore", ".", "bytelength", ")", ",", "self", ".", "len", ",", "self", ".", "_offset",...
Ensure the data is held in memory, not in a file.
[ "Ensure", "the", "data", "is", "held", "in", "memory", "not", "in", "a", "file", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1949-L1952
train
scott-griffiths/bitstring
bitstring.py
Bits._converttobitstring
def _converttobitstring(cls, bs, offset=0, cache={}): """Convert bs to a bitstring and return it. offset gives the suggested bit offset of first significant bit, to optimise append etc. """ if isinstance(bs, Bits): return bs try: return cache[(bs...
python
def _converttobitstring(cls, bs, offset=0, cache={}): """Convert bs to a bitstring and return it. offset gives the suggested bit offset of first significant bit, to optimise append etc. """ if isinstance(bs, Bits): return bs try: return cache[(bs...
[ "def", "_converttobitstring", "(", "cls", ",", "bs", ",", "offset", "=", "0", ",", "cache", "=", "{", "}", ")", ":", "if", "isinstance", "(", "bs", ",", "Bits", ")", ":", "return", "bs", "try", ":", "return", "cache", "[", "(", "bs", ",", "offset...
Convert bs to a bitstring and return it. offset gives the suggested bit offset of first significant bit, to optimise append etc.
[ "Convert", "bs", "to", "a", "bitstring", "and", "return", "it", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1955-L1986
train
scott-griffiths/bitstring
bitstring.py
Bits._slice
def _slice(self, start, end): """Used internally to get a slice, without error checking.""" if end == start: return self.__class__() offset = self._offset startbyte, newoffset = divmod(start + offset, 8) endbyte = (end + offset - 1) // 8 bs = self.__class__() ...
python
def _slice(self, start, end): """Used internally to get a slice, without error checking.""" if end == start: return self.__class__() offset = self._offset startbyte, newoffset = divmod(start + offset, 8) endbyte = (end + offset - 1) // 8 bs = self.__class__() ...
[ "def", "_slice", "(", "self", ",", "start", ",", "end", ")", ":", "if", "end", "==", "start", ":", "return", "self", ".", "__class__", "(", ")", "offset", "=", "self", ".", "_offset", "startbyte", ",", "newoffset", "=", "divmod", "(", "start", "+", ...
Used internally to get a slice, without error checking.
[ "Used", "internally", "to", "get", "a", "slice", "without", "error", "checking", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1995-L2004
train
scott-griffiths/bitstring
bitstring.py
Bits._readtoken
def _readtoken(self, name, pos, length): """Reads a token from the bitstring and returns the result.""" if length is not None and int(length) > self.length - pos: raise ReadError("Reading off the end of the data. " "Tried to read {0} bits when only {1} available."...
python
def _readtoken(self, name, pos, length): """Reads a token from the bitstring and returns the result.""" if length is not None and int(length) > self.length - pos: raise ReadError("Reading off the end of the data. " "Tried to read {0} bits when only {1} available."...
[ "def", "_readtoken", "(", "self", ",", "name", ",", "pos", ",", "length", ")", ":", "if", "length", "is", "not", "None", "and", "int", "(", "length", ")", ">", "self", ".", "length", "-", "pos", ":", "raise", "ReadError", "(", "\"Reading off the end of...
Reads a token from the bitstring and returns the result.
[ "Reads", "a", "token", "from", "the", "bitstring", "and", "returns", "the", "result", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2006-L2020
train
scott-griffiths/bitstring
bitstring.py
Bits._reverse
def _reverse(self): """Reverse all bits in-place.""" # Reverse the contents of each byte n = [BYTE_REVERSAL_DICT[b] for b in self._datastore.rawbytes] # Then reverse the order of the bytes n.reverse() # The new offset is the number of bits that were unused at the end. ...
python
def _reverse(self): """Reverse all bits in-place.""" # Reverse the contents of each byte n = [BYTE_REVERSAL_DICT[b] for b in self._datastore.rawbytes] # Then reverse the order of the bytes n.reverse() # The new offset is the number of bits that were unused at the end. ...
[ "def", "_reverse", "(", "self", ")", ":", "# Reverse the contents of each byte", "n", "=", "[", "BYTE_REVERSAL_DICT", "[", "b", "]", "for", "b", "in", "self", ".", "_datastore", ".", "rawbytes", "]", "# Then reverse the order of the bytes", "n", ".", "reverse", ...
Reverse all bits in-place.
[ "Reverse", "all", "bits", "in", "-", "place", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2030-L2040
train
scott-griffiths/bitstring
bitstring.py
Bits._truncateend
def _truncateend(self, bits): """Truncate bits from the end of the bitstring.""" assert 0 <= bits <= self.len if not bits: return if bits == self.len: self._clear() return newlength_in_bytes = (self._offset + self.len - bits + 7) // 8 s...
python
def _truncateend(self, bits): """Truncate bits from the end of the bitstring.""" assert 0 <= bits <= self.len if not bits: return if bits == self.len: self._clear() return newlength_in_bytes = (self._offset + self.len - bits + 7) // 8 s...
[ "def", "_truncateend", "(", "self", ",", "bits", ")", ":", "assert", "0", "<=", "bits", "<=", "self", ".", "len", "if", "not", "bits", ":", "return", "if", "bits", "==", "self", ".", "len", ":", "self", ".", "_clear", "(", ")", "return", "newlength...
Truncate bits from the end of the bitstring.
[ "Truncate", "bits", "from", "the", "end", "of", "the", "bitstring", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2055-L2066
train
scott-griffiths/bitstring
bitstring.py
Bits._insert
def _insert(self, bs, pos): """Insert bs at pos.""" assert 0 <= pos <= self.len if pos > self.len // 2: # Inserting nearer end, so cut off end. end = self._slice(pos, self.len) self._truncateend(self.len - pos) self._append(bs) self._ap...
python
def _insert(self, bs, pos): """Insert bs at pos.""" assert 0 <= pos <= self.len if pos > self.len // 2: # Inserting nearer end, so cut off end. end = self._slice(pos, self.len) self._truncateend(self.len - pos) self._append(bs) self._ap...
[ "def", "_insert", "(", "self", ",", "bs", ",", "pos", ")", ":", "assert", "0", "<=", "pos", "<=", "self", ".", "len", "if", "pos", ">", "self", ".", "len", "//", "2", ":", "# Inserting nearer end, so cut off end.", "end", "=", "self", ".", "_slice", ...
Insert bs at pos.
[ "Insert", "bs", "at", "pos", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2068-L2087
train
scott-griffiths/bitstring
bitstring.py
Bits._overwrite
def _overwrite(self, bs, pos): """Overwrite with bs at pos.""" assert 0 <= pos < self.len if bs is self: # Just overwriting with self, so do nothing. assert pos == 0 return firstbytepos = (self._offset + pos) // 8 lastbytepos = (self._offset + ...
python
def _overwrite(self, bs, pos): """Overwrite with bs at pos.""" assert 0 <= pos < self.len if bs is self: # Just overwriting with self, so do nothing. assert pos == 0 return firstbytepos = (self._offset + pos) // 8 lastbytepos = (self._offset + ...
[ "def", "_overwrite", "(", "self", ",", "bs", ",", "pos", ")", ":", "assert", "0", "<=", "pos", "<", "self", ".", "len", "if", "bs", "is", "self", ":", "# Just overwriting with self, so do nothing.", "assert", "pos", "==", "0", "return", "firstbytepos", "="...
Overwrite with bs at pos.
[ "Overwrite", "with", "bs", "at", "pos", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2089-L2120
train
scott-griffiths/bitstring
bitstring.py
Bits._delete
def _delete(self, bits, pos): """Delete bits at pos.""" assert 0 <= pos <= self.len assert pos + bits <= self.len if not pos: # Cutting bits off at the start. self._truncatestart(bits) return if pos + bits == self.len: # Cutting bit...
python
def _delete(self, bits, pos): """Delete bits at pos.""" assert 0 <= pos <= self.len assert pos + bits <= self.len if not pos: # Cutting bits off at the start. self._truncatestart(bits) return if pos + bits == self.len: # Cutting bit...
[ "def", "_delete", "(", "self", ",", "bits", ",", "pos", ")", ":", "assert", "0", "<=", "pos", "<=", "self", ".", "len", "assert", "pos", "+", "bits", "<=", "self", ".", "len", "if", "not", "pos", ":", "# Cutting bits off at the start.", "self", ".", ...
Delete bits at pos.
[ "Delete", "bits", "at", "pos", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2122-L2146
train
scott-griffiths/bitstring
bitstring.py
Bits._reversebytes
def _reversebytes(self, start, end): """Reverse bytes in-place.""" # Make the start occur on a byte boundary # TODO: We could be cleverer here to avoid changing the offset. newoffset = 8 - (start % 8) if newoffset == 8: newoffset = 0 self._datastore = offsetco...
python
def _reversebytes(self, start, end): """Reverse bytes in-place.""" # Make the start occur on a byte boundary # TODO: We could be cleverer here to avoid changing the offset. newoffset = 8 - (start % 8) if newoffset == 8: newoffset = 0 self._datastore = offsetco...
[ "def", "_reversebytes", "(", "self", ",", "start", ",", "end", ")", ":", "# Make the start occur on a byte boundary", "# TODO: We could be cleverer here to avoid changing the offset.", "newoffset", "=", "8", "-", "(", "start", "%", "8", ")", "if", "newoffset", "==", "...
Reverse bytes in-place.
[ "Reverse", "bytes", "in", "-", "place", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2148-L2159
train
scott-griffiths/bitstring
bitstring.py
Bits._set
def _set(self, pos): """Set bit at pos to 1.""" assert 0 <= pos < self.len self._datastore.setbit(pos)
python
def _set(self, pos): """Set bit at pos to 1.""" assert 0 <= pos < self.len self._datastore.setbit(pos)
[ "def", "_set", "(", "self", ",", "pos", ")", ":", "assert", "0", "<=", "pos", "<", "self", ".", "len", "self", ".", "_datastore", ".", "setbit", "(", "pos", ")" ]
Set bit at pos to 1.
[ "Set", "bit", "at", "pos", "to", "1", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2161-L2164
train
scott-griffiths/bitstring
bitstring.py
Bits._unset
def _unset(self, pos): """Set bit at pos to 0.""" assert 0 <= pos < self.len self._datastore.unsetbit(pos)
python
def _unset(self, pos): """Set bit at pos to 0.""" assert 0 <= pos < self.len self._datastore.unsetbit(pos)
[ "def", "_unset", "(", "self", ",", "pos", ")", ":", "assert", "0", "<=", "pos", "<", "self", ".", "len", "self", ".", "_datastore", ".", "unsetbit", "(", "pos", ")" ]
Set bit at pos to 0.
[ "Set", "bit", "at", "pos", "to", "0", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2166-L2169
train
scott-griffiths/bitstring
bitstring.py
Bits._invert_all
def _invert_all(self): """Invert every bit.""" set = self._datastore.setbyte get = self._datastore.getbyte for p in xrange(self._datastore.byteoffset, self._datastore.byteoffset + self._datastore.bytelength): set(p, 256 + ~get(p))
python
def _invert_all(self): """Invert every bit.""" set = self._datastore.setbyte get = self._datastore.getbyte for p in xrange(self._datastore.byteoffset, self._datastore.byteoffset + self._datastore.bytelength): set(p, 256 + ~get(p))
[ "def", "_invert_all", "(", "self", ")", ":", "set", "=", "self", ".", "_datastore", ".", "setbyte", "get", "=", "self", ".", "_datastore", ".", "getbyte", "for", "p", "in", "xrange", "(", "self", ".", "_datastore", ".", "byteoffset", ",", "self", ".", ...
Invert every bit.
[ "Invert", "every", "bit", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2176-L2181
train
scott-griffiths/bitstring
bitstring.py
Bits._ilshift
def _ilshift(self, n): """Shift bits by n to the left in place. Return self.""" assert 0 < n <= self.len self._append(Bits(n)) self._truncatestart(n) return self
python
def _ilshift(self, n): """Shift bits by n to the left in place. Return self.""" assert 0 < n <= self.len self._append(Bits(n)) self._truncatestart(n) return self
[ "def", "_ilshift", "(", "self", ",", "n", ")", ":", "assert", "0", "<", "n", "<=", "self", ".", "len", "self", ".", "_append", "(", "Bits", "(", "n", ")", ")", "self", ".", "_truncatestart", "(", "n", ")", "return", "self" ]
Shift bits by n to the left in place. Return self.
[ "Shift", "bits", "by", "n", "to", "the", "left", "in", "place", ".", "Return", "self", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2183-L2188
train
scott-griffiths/bitstring
bitstring.py
Bits._irshift
def _irshift(self, n): """Shift bits by n to the right in place. Return self.""" assert 0 < n <= self.len self._prepend(Bits(n)) self._truncateend(n) return self
python
def _irshift(self, n): """Shift bits by n to the right in place. Return self.""" assert 0 < n <= self.len self._prepend(Bits(n)) self._truncateend(n) return self
[ "def", "_irshift", "(", "self", ",", "n", ")", ":", "assert", "0", "<", "n", "<=", "self", ".", "len", "self", ".", "_prepend", "(", "Bits", "(", "n", ")", ")", "self", ".", "_truncateend", "(", "n", ")", "return", "self" ]
Shift bits by n to the right in place. Return self.
[ "Shift", "bits", "by", "n", "to", "the", "right", "in", "place", ".", "Return", "self", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2190-L2195
train
scott-griffiths/bitstring
bitstring.py
Bits._imul
def _imul(self, n): """Concatenate n copies of self in place. Return self.""" assert n >= 0 if not n: self._clear() return self m = 1 old_len = self.len while m * 2 < n: self._append(self) m *= 2 self._append(self[0:...
python
def _imul(self, n): """Concatenate n copies of self in place. Return self.""" assert n >= 0 if not n: self._clear() return self m = 1 old_len = self.len while m * 2 < n: self._append(self) m *= 2 self._append(self[0:...
[ "def", "_imul", "(", "self", ",", "n", ")", ":", "assert", "n", ">=", "0", "if", "not", "n", ":", "self", ".", "_clear", "(", ")", "return", "self", "m", "=", "1", "old_len", "=", "self", ".", "len", "while", "m", "*", "2", "<", "n", ":", "...
Concatenate n copies of self in place. Return self.
[ "Concatenate", "n", "copies", "of", "self", "in", "place", ".", "Return", "self", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2197-L2209
train
scott-griffiths/bitstring
bitstring.py
Bits._validate_slice
def _validate_slice(self, start, end): """Validate start and end and return them as positive bit positions.""" if start is None: start = 0 elif start < 0: start += self.len if end is None: end = self.len elif end < 0: end += self.le...
python
def _validate_slice(self, start, end): """Validate start and end and return them as positive bit positions.""" if start is None: start = 0 elif start < 0: start += self.len if end is None: end = self.len elif end < 0: end += self.le...
[ "def", "_validate_slice", "(", "self", ",", "start", ",", "end", ")", ":", "if", "start", "is", "None", ":", "start", "=", "0", "elif", "start", "<", "0", ":", "start", "+=", "self", ".", "len", "if", "end", "is", "None", ":", "end", "=", "self",...
Validate start and end and return them as positive bit positions.
[ "Validate", "start", "and", "end", "and", "return", "them", "as", "positive", "bit", "positions", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2240-L2256
train
scott-griffiths/bitstring
bitstring.py
Bits._findbytes
def _findbytes(self, bytes_, start, end, bytealigned): """Quicker version of find when everything's whole byte and byte aligned. """ assert self._datastore.offset == 0 assert bytealigned is True # Extract data bytes from bitstring to be found. bytepos = (start + ...
python
def _findbytes(self, bytes_, start, end, bytealigned): """Quicker version of find when everything's whole byte and byte aligned. """ assert self._datastore.offset == 0 assert bytealigned is True # Extract data bytes from bitstring to be found. bytepos = (start + ...
[ "def", "_findbytes", "(", "self", ",", "bytes_", ",", "start", ",", "end", ",", "bytealigned", ")", ":", "assert", "self", ".", "_datastore", ".", "offset", "==", "0", "assert", "bytealigned", "is", "True", "# Extract data bytes from bitstring to be found.", "by...
Quicker version of find when everything's whole byte and byte aligned.
[ "Quicker", "version", "of", "find", "when", "everything", "s", "whole", "byte", "and", "byte", "aligned", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2352-L2377
train
scott-griffiths/bitstring
bitstring.py
Bits._findregex
def _findregex(self, reg_ex, start, end, bytealigned): """Find first occurrence of a compiled regular expression. Note that this doesn't support arbitrary regexes, in particular they must match a known length. """ p = start length = len(reg_ex.pattern) # We grab...
python
def _findregex(self, reg_ex, start, end, bytealigned): """Find first occurrence of a compiled regular expression. Note that this doesn't support arbitrary regexes, in particular they must match a known length. """ p = start length = len(reg_ex.pattern) # We grab...
[ "def", "_findregex", "(", "self", ",", "reg_ex", ",", "start", ",", "end", ",", "bytealigned", ")", ":", "p", "=", "start", "length", "=", "len", "(", "reg_ex", ".", "pattern", ")", "# We grab overlapping chunks of the binary representation and", "# do an ordinary...
Find first occurrence of a compiled regular expression. Note that this doesn't support arbitrary regexes, in particular they must match a known length.
[ "Find", "first", "occurrence", "of", "a", "compiled", "regular", "expression", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2379-L2409
train
scott-griffiths/bitstring
bitstring.py
Bits.find
def find(self, bs, start=None, end=None, bytealigned=None): """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...
python
def find(self, bs, start=None, end=None, bytealigned=None): """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...
[ "def", "find", "(", "self", ",", "bs", ",", "start", "=", "None", ",", "end", "=", "None", ",", "bytealigned", "=", "None", ")", ":", "bs", "=", "Bits", "(", "bs", ")", "if", "not", "bs", ".", "len", ":", "raise", "ValueError", "(", "\"Cannot fin...
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 positi...
[ "Find", "first", "occurrence", "of", "substring", "bs", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2411-L2447
train
scott-griffiths/bitstring
bitstring.py
Bits.findall
def findall(self, bs, start=None, end=None, count=None, bytealigned=None): """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...
python
def findall(self, bs, start=None, end=None, count=None, bytealigned=None): """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...
[ "def", "findall", "(", "self", ",", "bs", ",", "start", "=", "None", ",", "end", "=", "None", ",", "count", "=", "None", ",", "bytealigned", "=", "None", ")", ":", "if", "count", "is", "not", "None", "and", "count", "<", "0", ":", "raise", "Value...
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 occurren...
[ "Find", "all", "occurrences", "of", "bs", ".", "Return", "generator", "of", "bit", "positions", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2449-L2499
train
scott-griffiths/bitstring
bitstring.py
Bits.rfind
def rfind(self, bs, start=None, end=None, bytealigned=None): """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 foun...
python
def rfind(self, bs, start=None, end=None, bytealigned=None): """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 foun...
[ "def", "rfind", "(", "self", ",", "bs", ",", "start", "=", "None", ",", "end", "=", "None", ",", "bytealigned", "=", "None", ")", ":", "bs", "=", "Bits", "(", "bs", ")", "start", ",", "end", "=", "self", ".", "_validate_slice", "(", "start", ",",...
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 positi...
[ "Find", "final", "occurrence", "of", "substring", "bs", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2501-L2538
train
scott-griffiths/bitstring
bitstring.py
Bits.cut
def cut(self, bits, start=None, end=None, count=None): """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 las...
python
def cut(self, bits, start=None, end=None, count=None): """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 las...
[ "def", "cut", "(", "self", ",", "bits", ",", "start", "=", "None", ",", "end", "=", "None", ",", "count", "=", "None", ")", ":", "start", ",", "end", "=", "self", ".", "_validate_slice", "(", "start", ",", "end", ")", "if", "count", "is", "not", ...
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", "bitstring", "generator", "by", "cutting", "into", "bits", "sized", "chunks", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2540-L2565
train
scott-griffiths/bitstring
bitstring.py
Bits.split
def split(self, delimiter, start=None, end=None, count=None, bytealigned=None): """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 bitstrin...
python
def split(self, delimiter, start=None, end=None, count=None, bytealigned=None): """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 bitstrin...
[ "def", "split", "(", "self", ",", "delimiter", ",", "start", "=", "None", ",", "end", "=", "None", ",", "count", "=", "None", ",", "bytealigned", "=", "None", ")", ":", "delimiter", "=", "Bits", "(", "delimiter", ")", "if", "not", "delimiter", ".", ...
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 -...
[ "Return", "bitstring", "generator", "by", "splittling", "using", "a", "delimiter", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2567-L2622
train
scott-griffiths/bitstring
bitstring.py
Bits.join
def join(self, sequence): """Return concatenation of bitstrings joined by self. sequence -- A sequence of bitstrings. """ s = self.__class__() i = iter(sequence) try: s._append(Bits(next(i))) while True: n = next(i) ...
python
def join(self, sequence): """Return concatenation of bitstrings joined by self. sequence -- A sequence of bitstrings. """ s = self.__class__() i = iter(sequence) try: s._append(Bits(next(i))) while True: n = next(i) ...
[ "def", "join", "(", "self", ",", "sequence", ")", ":", "s", "=", "self", ".", "__class__", "(", ")", "i", "=", "iter", "(", "sequence", ")", "try", ":", "s", ".", "_append", "(", "Bits", "(", "next", "(", "i", ")", ")", ")", "while", "True", ...
Return concatenation of bitstrings joined by self. sequence -- A sequence of bitstrings.
[ "Return", "concatenation", "of", "bitstrings", "joined", "by", "self", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2624-L2640
train
scott-griffiths/bitstring
bitstring.py
Bits.tobytes
def tobytes(self): """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. """ d = offsetcopy(self._datastore, 0).rawbytes # Need to ensure that unused bits at end are set to zero unusedbits = 8 -...
python
def tobytes(self): """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. """ d = offsetcopy(self._datastore, 0).rawbytes # Need to ensure that unused bits at end are set to zero unusedbits = 8 -...
[ "def", "tobytes", "(", "self", ")", ":", "d", "=", "offsetcopy", "(", "self", ".", "_datastore", ",", "0", ")", ".", "rawbytes", "# Need to ensure that unused bits at end are set to zero", "unusedbits", "=", "8", "-", "self", ".", "len", "%", "8", "if", "unu...
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.
[ "Return", "the", "bitstring", "as", "bytes", "padding", "with", "zero", "bits", "if", "needed", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2642-L2653
train
scott-griffiths/bitstring
bitstring.py
Bits.tofile
def tofile(self, f): """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. """ # If the bitstring is file based then we don't want to read it all # in to memory. chunksize = 1024 * 1024 #...
python
def tofile(self, f): """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. """ # If the bitstring is file based then we don't want to read it all # in to memory. chunksize = 1024 * 1024 #...
[ "def", "tofile", "(", "self", ",", "f", ")", ":", "# If the bitstring is file based then we don't want to read it all", "# in to memory.", "chunksize", "=", "1024", "*", "1024", "# 1 MB chunks", "if", "not", "self", ".", "_offset", ":", "a", "=", "0", "bytelen", "...
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.
[ "Write", "the", "bitstring", "to", "a", "file", "object", "padding", "with", "zero", "bits", "if", "needed", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2655-L2687
train
scott-griffiths/bitstring
bitstring.py
Bits.startswith
def startswith(self, prefix, start=None, end=None): """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. """ pr...
python
def startswith(self, prefix, start=None, end=None): """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. """ pr...
[ "def", "startswith", "(", "self", ",", "prefix", ",", "start", "=", "None", ",", "end", "=", "None", ")", ":", "prefix", "=", "Bits", "(", "prefix", ")", "start", ",", "end", "=", "self", ".", "_validate_slice", "(", "start", ",", "end", ")", "if",...
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", "whether", "the", "current", "bitstring", "starts", "with", "prefix", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2689-L2702
train
scott-griffiths/bitstring
bitstring.py
Bits.endswith
def endswith(self, suffix, start=None, end=None): """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. """ suffix...
python
def endswith(self, suffix, start=None, end=None): """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. """ suffix...
[ "def", "endswith", "(", "self", ",", "suffix", ",", "start", "=", "None", ",", "end", "=", "None", ")", ":", "suffix", "=", "Bits", "(", "suffix", ")", "start", ",", "end", "=", "self", ".", "_validate_slice", "(", "start", ",", "end", ")", "if", ...
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.
[ "Return", "whether", "the", "current", "bitstring", "ends", "with", "suffix", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2704-L2717
train
scott-griffiths/bitstring
bitstring.py
Bits.all
def all(self, value, pos=None): """Return True if one or many bits are all set to value. value -- If value is True then checks for bits set to 1, otherwise checks for bits set to 0. pos -- An iterable of bit positions. Negative numbers are treated in the same way...
python
def all(self, value, pos=None): """Return True if one or many bits are all set to value. value -- If value is True then checks for bits set to 1, otherwise checks for bits set to 0. pos -- An iterable of bit positions. Negative numbers are treated in the same way...
[ "def", "all", "(", "self", ",", "value", ",", "pos", "=", "None", ")", ":", "value", "=", "bool", "(", "value", ")", "length", "=", "self", ".", "len", "if", "pos", "is", "None", ":", "pos", "=", "xrange", "(", "self", ".", "len", ")", "for", ...
Return True if one or many bits are all set to value. value -- If value is True then checks for bits set to 1, otherwise checks for bits set to 0. pos -- An iterable of bit positions. Negative numbers are treated in the same way as slice indices. Defaults to the whole bi...
[ "Return", "True", "if", "one", "or", "many", "bits", "are", "all", "set", "to", "value", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2719-L2739
train
scott-griffiths/bitstring
bitstring.py
Bits.count
def count(self, value): """Return count of total number of either zero or one bits. value -- If True then bits set to 1 are counted, otherwise bits set to 0 are counted. >>> Bits('0xef').count(1) 7 """ if not self.len: return 0 # co...
python
def count(self, value): """Return count of total number of either zero or one bits. value -- If True then bits set to 1 are counted, otherwise bits set to 0 are counted. >>> Bits('0xef').count(1) 7 """ if not self.len: return 0 # co...
[ "def", "count", "(", "self", ",", "value", ")", ":", "if", "not", "self", ".", "len", ":", "return", "0", "# count the number of 1s (from which it's easy to work out the 0s).", "# Don't count the final byte yet.", "count", "=", "sum", "(", "BIT_COUNT", "[", "self", ...
Return count of total number of either zero or one bits. value -- If True then bits set to 1 are counted, otherwise bits set to 0 are counted. >>> Bits('0xef').count(1) 7
[ "Return", "count", "of", "total", "number", "of", "either", "zero", "or", "one", "bits", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2763-L2784
train
scott-griffiths/bitstring
bitstring.py
BitArray.replace
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...
python
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...
[ "def", "replace", "(", "self", ",", "old", ",", "new", ",", "start", "=", "None", ",", "end", "=", "None", ",", "count", "=", "None", ",", "bytealigned", "=", "None", ")", ":", "old", "=", "Bits", "(", "old", ")", "new", "=", "Bits", "(", "new"...
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...
[ "Replace", "all", "occurrences", "of", "old", "with", "new", "in", "place", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3298-L3363
train
scott-griffiths/bitstring
bitstring.py
BitArray.insert
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. """ bs = Bits(bs) if not bs.len: return self if bs is self...
python
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. """ bs = Bits(bs) if not bs.len: return self if bs is self...
[ "def", "insert", "(", "self", ",", "bs", ",", "pos", "=", "None", ")", ":", "bs", "=", "Bits", "(", "bs", ")", "if", "not", "bs", ".", "len", ":", "return", "self", "if", "bs", "is", "self", ":", "bs", "=", "self", ".", "__copy__", "(", ")", ...
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.
[ "Insert", "bs", "at", "bit", "position", "pos", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3365-L3388
train
scott-griffiths/bitstring
bitstring.py
BitArray.overwrite
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 """ bs = Bits(bs) if not bs.len: ...
python
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 """ bs = Bits(bs) if not bs.len: ...
[ "def", "overwrite", "(", "self", ",", "bs", ",", "pos", "=", "None", ")", ":", "bs", "=", "Bits", "(", "bs", ")", "if", "not", "bs", ".", "len", ":", "return", "if", "pos", "is", "None", ":", "try", ":", "pos", "=", "self", ".", "_pos", "exce...
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
[ "Overwrite", "with", "bs", "at", "bit", "position", "pos", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3390-L3415
train
scott-griffiths/bitstring
bitstring.py
BitArray.append
def append(self, bs): """Append a bitstring to the current bitstring. bs -- The bitstring to append. """ # The offset is a hint to make bs easily appendable. bs = self._converttobitstring(bs, offset=(self.len + self._offset) % 8) self._append(bs)
python
def append(self, bs): """Append a bitstring to the current bitstring. bs -- The bitstring to append. """ # The offset is a hint to make bs easily appendable. bs = self._converttobitstring(bs, offset=(self.len + self._offset) % 8) self._append(bs)
[ "def", "append", "(", "self", ",", "bs", ")", ":", "# The offset is a hint to make bs easily appendable.", "bs", "=", "self", ".", "_converttobitstring", "(", "bs", ",", "offset", "=", "(", "self", ".", "len", "+", "self", ".", "_offset", ")", "%", "8", ")...
Append a bitstring to the current bitstring. bs -- The bitstring to append.
[ "Append", "a", "bitstring", "to", "the", "current", "bitstring", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3417-L3425
train
scott-griffiths/bitstring
bitstring.py
BitArray.reverse
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 Va...
python
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 Va...
[ "def", "reverse", "(", "self", ",", "start", "=", "None", ",", "end", "=", "None", ")", ":", "start", ",", "end", "=", "self", ".", "_validate_slice", "(", "start", ",", "end", ")", "if", "start", "==", "0", "and", "end", "==", "self", ".", "len"...
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...
[ "Reverse", "bits", "in", "-", "place", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3436-L3454
train
scott-griffiths/bitstring
bitstring.py
BitArray.set
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. D...
python
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. D...
[ "def", "set", "(", "self", ",", "value", ",", "pos", "=", "None", ")", ":", "f", "=", "self", ".", "_set", "if", "value", "else", "self", ".", "_unset", "if", "pos", "is", "None", ":", "pos", "=", "xrange", "(", "self", ".", "len", ")", "try", ...
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. R...
[ "Set", "one", "or", "many", "bits", "to", "1", "or", "0", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3456-L3484
train
scott-griffiths/bitstring
bitstring.py
BitArray.invert
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. ...
python
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. ...
[ "def", "invert", "(", "self", ",", "pos", "=", "None", ")", ":", "if", "pos", "is", "None", ":", "self", ".", "_invert_all", "(", ")", "return", "if", "not", "isinstance", "(", "pos", ",", "collections", ".", "Iterable", ")", ":", "pos", "=", "(", ...
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.
[ "Invert", "one", "or", "many", "bits", "from", "0", "to", "1", "or", "vice", "versa", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3486-L3507
train
scott-griffiths/bitstring
bitstring.py
BitArray.ror
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. """ i...
python
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. """ i...
[ "def", "ror", "(", "self", ",", "bits", ",", "start", "=", "None", ",", "end", "=", "None", ")", ":", "if", "not", "self", ".", "len", ":", "raise", "Error", "(", "\"Cannot rotate an empty bitstring.\"", ")", "if", "bits", "<", "0", ":", "raise", "Va...
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.
[ "Rotate", "bits", "to", "the", "right", "in", "-", "place", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3509-L3529
train
scott-griffiths/bitstring
bitstring.py
BitArray.rol
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. """ if...
python
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. """ if...
[ "def", "rol", "(", "self", ",", "bits", ",", "start", "=", "None", ",", "end", "=", "None", ")", ":", "if", "not", "self", ".", "len", ":", "raise", "Error", "(", "\"Cannot rotate an empty bitstring.\"", ")", "if", "bits", "<", "0", ":", "raise", "Va...
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", "left", "in", "-", "place", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3531-L3551
train
scott-griffiths/bitstring
bitstring.py
BitArray.byteswap
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 ...
python
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 ...
[ "def", "byteswap", "(", "self", ",", "fmt", "=", "None", ",", "start", "=", "None", ",", "end", "=", "None", ",", "repeat", "=", "True", ")", ":", "start", ",", "end", "=", "self", ".", "_validate_slice", "(", "start", ",", "end", ")", "if", "fmt...
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 -...
[ "Change", "the", "endianness", "in", "-", "place", ".", "Return", "number", "of", "repeats", "of", "fmt", "done", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3553-L3611
train
scott-griffiths/bitstring
bitstring.py
ConstBitStream._setbitpos
def _setbitpos(self, pos): """Move to absolute postion bit in bitstream.""" if pos < 0: raise ValueError("Bit position cannot be negative.") if pos > self.len: raise ValueError("Cannot seek past the end of the data.") self._pos = pos
python
def _setbitpos(self, pos): """Move to absolute postion bit in bitstream.""" if pos < 0: raise ValueError("Bit position cannot be negative.") if pos > self.len: raise ValueError("Cannot seek past the end of the data.") self._pos = pos
[ "def", "_setbitpos", "(", "self", ",", "pos", ")", ":", "if", "pos", "<", "0", ":", "raise", "ValueError", "(", "\"Bit position cannot be negative.\"", ")", "if", "pos", ">", "self", ".", "len", ":", "raise", "ValueError", "(", "\"Cannot seek past the end of t...
Move to absolute postion bit in bitstream.
[ "Move", "to", "absolute", "postion", "bit", "in", "bitstream", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3806-L3812
train
scott-griffiths/bitstring
bitstring.py
ConstBitStream.read
def read(self, fmt): """Interpret next bits according to the format string and return result. fmt -- Token string describing how to interpret the next bits. Token examples: 'int:12' : 12 bits as a signed integer 'uint:8' : 8 bits as an unsigned integer ...
python
def read(self, fmt): """Interpret next bits according to the format string and return result. fmt -- Token string describing how to interpret the next bits. Token examples: 'int:12' : 12 bits as a signed integer 'uint:8' : 8 bits as an unsigned integer ...
[ "def", "read", "(", "self", ",", "fmt", ")", ":", "if", "isinstance", "(", "fmt", ",", "numbers", ".", "Integral", ")", ":", "if", "fmt", "<", "0", ":", "raise", "ValueError", "(", "\"Cannot read negative amount.\"", ")", "if", "fmt", ">", "self", ".",...
Interpret next bits according to the format string and return result. fmt -- Token string describing how to interpret the next bits. Token examples: 'int:12' : 12 bits as a signed integer 'uint:8' : 8 bits as an unsigned integer 'float:64' : 8 byt...
[ "Interpret", "next", "bits", "according", "to", "the", "format", "string", "and", "return", "result", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3842-L3897
train
scott-griffiths/bitstring
bitstring.py
ConstBitStream.readto
def readto(self, bs, bytealigned=None): """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...
python
def readto(self, bs, bytealigned=None): """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...
[ "def", "readto", "(", "self", ",", "bs", ",", "bytealigned", "=", "None", ")", ":", "if", "isinstance", "(", "bs", ",", "numbers", ".", "Integral", ")", ":", "raise", "ValueError", "(", "\"Integers cannot be searched for\"", ")", "bs", "=", "Bits", "(", ...
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...
[ "Read", "up", "to", "and", "including", "next", "occurrence", "of", "bs", "and", "return", "result", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3923-L3942
train
scott-griffiths/bitstring
bitstring.py
ConstBitStream.peek
def peek(self, fmt): """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...
python
def peek(self, fmt): """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...
[ "def", "peek", "(", "self", ",", "fmt", ")", ":", "pos_before", "=", "self", ".", "_pos", "value", "=", "self", ".", "read", "(", "fmt", ")", "self", ".", "_pos", "=", "pos_before", "return", "value" ]
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 n...
[ "Interpret", "next", "bits", "according", "to", "format", "string", "and", "return", "result", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3944-L3961
train
scott-griffiths/bitstring
bitstring.py
ConstBitStream.bytealign
def bytealign(self): """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. """ skipped = (8 - (self._pos % 8)) % 8 self.pos += self._offset + skipped assert self._asser...
python
def bytealign(self): """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. """ skipped = (8 - (self._pos % 8)) % 8 self.pos += self._offset + skipped assert self._asser...
[ "def", "bytealign", "(", "self", ")", ":", "skipped", "=", "(", "8", "-", "(", "self", ".", "_pos", "%", "8", ")", ")", "%", "8", "self", ".", "pos", "+=", "self", ".", "_offset", "+", "skipped", "assert", "self", ".", "_assertsanity", "(", ")", ...
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.
[ "Align", "to", "next", "byte", "and", "return", "number", "of", "skipped", "bits", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3985-L3995
train
scott-griffiths/bitstring
bitstring.py
BitStream.prepend
def prepend(self, bs): """Prepend a bitstring to the current bitstring. bs -- The bitstring to prepend. """ bs = self._converttobitstring(bs) self._prepend(bs) self._pos += bs.len
python
def prepend(self, bs): """Prepend a bitstring to the current bitstring. bs -- The bitstring to prepend. """ bs = self._converttobitstring(bs) self._prepend(bs) self._pos += bs.len
[ "def", "prepend", "(", "self", ",", "bs", ")", ":", "bs", "=", "self", ".", "_converttobitstring", "(", "bs", ")", "self", ".", "_prepend", "(", "bs", ")", "self", ".", "_pos", "+=", "bs", ".", "len" ]
Prepend a bitstring to the current bitstring. bs -- The bitstring to prepend.
[ "Prepend", "a", "bitstring", "to", "the", "current", "bitstring", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L4150-L4158
train
g2p/bedup
bedup/dedup.py
find_inodes_in_use
def find_inodes_in_use(fds): """ Find which of these inodes are in use, and give their open modes. Does not count the passed fds as an use of the inode they point to, but if the current process has the same inodes open with different file descriptors these will be listed. Looks at /proc/*/fd a...
python
def find_inodes_in_use(fds): """ Find which of these inodes are in use, and give their open modes. Does not count the passed fds as an use of the inode they point to, but if the current process has the same inodes open with different file descriptors these will be listed. Looks at /proc/*/fd a...
[ "def", "find_inodes_in_use", "(", "fds", ")", ":", "self_pid", "=", "os", ".", "getpid", "(", ")", "id_fd_assoc", "=", "collections", ".", "defaultdict", "(", "list", ")", "for", "fd", "in", "fds", ":", "st", "=", "os", ".", "fstat", "(", "fd", ")", ...
Find which of these inodes are in use, and give their open modes. Does not count the passed fds as an use of the inode they point to, but if the current process has the same inodes open with different file descriptors these will be listed. Looks at /proc/*/fd and /proc/*/map_files (Linux 3.3). Con...
[ "Find", "which", "of", "these", "inodes", "are", "in", "use", "and", "give", "their", "open", "modes", "." ]
9694f6f718844c33017052eb271f68b6c0d0b7d3
https://github.com/g2p/bedup/blob/9694f6f718844c33017052eb271f68b6c0d0b7d3/bedup/dedup.py#L120-L186
train
g2p/bedup
bedup/platform/ioprio.py
set_idle_priority
def set_idle_priority(pid=None): """ Puts a process in the idle io priority class. If pid is omitted, applies to the current process. """ if pid is None: pid = os.getpid() lib.ioprio_set( lib.IOPRIO_WHO_PROCESS, pid, lib.IOPRIO_PRIO_VALUE(lib.IOPRIO_CLASS_IDLE, 0))
python
def set_idle_priority(pid=None): """ Puts a process in the idle io priority class. If pid is omitted, applies to the current process. """ if pid is None: pid = os.getpid() lib.ioprio_set( lib.IOPRIO_WHO_PROCESS, pid, lib.IOPRIO_PRIO_VALUE(lib.IOPRIO_CLASS_IDLE, 0))
[ "def", "set_idle_priority", "(", "pid", "=", "None", ")", ":", "if", "pid", "is", "None", ":", "pid", "=", "os", ".", "getpid", "(", ")", "lib", ".", "ioprio_set", "(", "lib", ".", "IOPRIO_WHO_PROCESS", ",", "pid", ",", "lib", ".", "IOPRIO_PRIO_VALUE",...
Puts a process in the idle io priority class. If pid is omitted, applies to the current process.
[ "Puts", "a", "process", "in", "the", "idle", "io", "priority", "class", "." ]
9694f6f718844c33017052eb271f68b6c0d0b7d3
https://github.com/g2p/bedup/blob/9694f6f718844c33017052eb271f68b6c0d0b7d3/bedup/platform/ioprio.py#L82-L93
train
g2p/bedup
bedup/platform/futimens.py
futimens
def futimens(fd, ns): """ set inode atime and mtime ns is (atime, mtime), a pair of struct timespec with nanosecond resolution. """ # ctime can't easily be reset # also, we have no way to do mandatory locking without # changing the ctime. times = ffi.new('struct timespec[2]') a...
python
def futimens(fd, ns): """ set inode atime and mtime ns is (atime, mtime), a pair of struct timespec with nanosecond resolution. """ # ctime can't easily be reset # also, we have no way to do mandatory locking without # changing the ctime. times = ffi.new('struct timespec[2]') a...
[ "def", "futimens", "(", "fd", ",", "ns", ")", ":", "# ctime can't easily be reset", "# also, we have no way to do mandatory locking without", "# changing the ctime.", "times", "=", "ffi", ".", "new", "(", "'struct timespec[2]'", ")", "atime", ",", "mtime", "=", "ns", ...
set inode atime and mtime ns is (atime, mtime), a pair of struct timespec with nanosecond resolution.
[ "set", "inode", "atime", "and", "mtime" ]
9694f6f718844c33017052eb271f68b6c0d0b7d3
https://github.com/g2p/bedup/blob/9694f6f718844c33017052eb271f68b6c0d0b7d3/bedup/platform/futimens.py#L70-L90
train
g2p/bedup
bedup/platform/openat.py
fopenat
def fopenat(base_fd, path): """ Does openat read-only, then does fdopen to get a file object """ return os.fdopen(openat(base_fd, path, os.O_RDONLY), 'rb')
python
def fopenat(base_fd, path): """ Does openat read-only, then does fdopen to get a file object """ return os.fdopen(openat(base_fd, path, os.O_RDONLY), 'rb')
[ "def", "fopenat", "(", "base_fd", ",", "path", ")", ":", "return", "os", ".", "fdopen", "(", "openat", "(", "base_fd", ",", "path", ",", "os", ".", "O_RDONLY", ")", ",", "'rb'", ")" ]
Does openat read-only, then does fdopen to get a file object
[ "Does", "openat", "read", "-", "only", "then", "does", "fdopen", "to", "get", "a", "file", "object" ]
9694f6f718844c33017052eb271f68b6c0d0b7d3
https://github.com/g2p/bedup/blob/9694f6f718844c33017052eb271f68b6c0d0b7d3/bedup/platform/openat.py#L44-L49
train
g2p/bedup
bedup/platform/openat.py
fopenat_rw
def fopenat_rw(base_fd, path): """ Does openat read-write, then does fdopen to get a file object """ return os.fdopen(openat(base_fd, path, os.O_RDWR), 'rb+')
python
def fopenat_rw(base_fd, path): """ Does openat read-write, then does fdopen to get a file object """ return os.fdopen(openat(base_fd, path, os.O_RDWR), 'rb+')
[ "def", "fopenat_rw", "(", "base_fd", ",", "path", ")", ":", "return", "os", ".", "fdopen", "(", "openat", "(", "base_fd", ",", "path", ",", "os", ".", "O_RDWR", ")", ",", "'rb+'", ")" ]
Does openat read-write, then does fdopen to get a file object
[ "Does", "openat", "read", "-", "write", "then", "does", "fdopen", "to", "get", "a", "file", "object" ]
9694f6f718844c33017052eb271f68b6c0d0b7d3
https://github.com/g2p/bedup/blob/9694f6f718844c33017052eb271f68b6c0d0b7d3/bedup/platform/openat.py#L52-L57
train
g2p/bedup
bedup/platform/fiemap.py
fiemap
def fiemap(fd): """ Gets a map of file extents. """ count = 72 fiemap_cbuf = ffi.new( 'char[]', ffi.sizeof('struct fiemap') + count * ffi.sizeof('struct fiemap_extent')) fiemap_pybuf = ffi.buffer(fiemap_cbuf) fiemap_ptr = ffi.cast('struct fiemap*', fiemap_cbuf) a...
python
def fiemap(fd): """ Gets a map of file extents. """ count = 72 fiemap_cbuf = ffi.new( 'char[]', ffi.sizeof('struct fiemap') + count * ffi.sizeof('struct fiemap_extent')) fiemap_pybuf = ffi.buffer(fiemap_cbuf) fiemap_ptr = ffi.cast('struct fiemap*', fiemap_cbuf) a...
[ "def", "fiemap", "(", "fd", ")", ":", "count", "=", "72", "fiemap_cbuf", "=", "ffi", ".", "new", "(", "'char[]'", ",", "ffi", ".", "sizeof", "(", "'struct fiemap'", ")", "+", "count", "*", "ffi", ".", "sizeof", "(", "'struct fiemap_extent'", ")", ")", ...
Gets a map of file extents.
[ "Gets", "a", "map", "of", "file", "extents", "." ]
9694f6f718844c33017052eb271f68b6c0d0b7d3
https://github.com/g2p/bedup/blob/9694f6f718844c33017052eb271f68b6c0d0b7d3/bedup/platform/fiemap.py#L93-L118
train
g2p/bedup
bedup/platform/chattr.py
getflags
def getflags(fd): """ Gets per-file filesystem flags. """ flags_ptr = ffi.new('uint64_t*') flags_buf = ffi.buffer(flags_ptr) fcntl.ioctl(fd, lib.FS_IOC_GETFLAGS, flags_buf) return flags_ptr[0]
python
def getflags(fd): """ Gets per-file filesystem flags. """ flags_ptr = ffi.new('uint64_t*') flags_buf = ffi.buffer(flags_ptr) fcntl.ioctl(fd, lib.FS_IOC_GETFLAGS, flags_buf) return flags_ptr[0]
[ "def", "getflags", "(", "fd", ")", ":", "flags_ptr", "=", "ffi", ".", "new", "(", "'uint64_t*'", ")", "flags_buf", "=", "ffi", ".", "buffer", "(", "flags_ptr", ")", "fcntl", ".", "ioctl", "(", "fd", ",", "lib", ".", "FS_IOC_GETFLAGS", ",", "flags_buf",...
Gets per-file filesystem flags.
[ "Gets", "per", "-", "file", "filesystem", "flags", "." ]
9694f6f718844c33017052eb271f68b6c0d0b7d3
https://github.com/g2p/bedup/blob/9694f6f718844c33017052eb271f68b6c0d0b7d3/bedup/platform/chattr.py#L74-L82
train
g2p/bedup
bedup/platform/chattr.py
editflags
def editflags(fd, add_flags=0, remove_flags=0): """ Sets and unsets per-file filesystem flags. """ if add_flags & remove_flags != 0: raise ValueError( 'Added and removed flags shouldn\'t overlap', add_flags, remove_flags) # The ext2progs code uses int or unsigned lo...
python
def editflags(fd, add_flags=0, remove_flags=0): """ Sets and unsets per-file filesystem flags. """ if add_flags & remove_flags != 0: raise ValueError( 'Added and removed flags shouldn\'t overlap', add_flags, remove_flags) # The ext2progs code uses int or unsigned lo...
[ "def", "editflags", "(", "fd", ",", "add_flags", "=", "0", ",", "remove_flags", "=", "0", ")", ":", "if", "add_flags", "&", "remove_flags", "!=", "0", ":", "raise", "ValueError", "(", "'Added and removed flags shouldn\\'t overlap'", ",", "add_flags", ",", "rem...
Sets and unsets per-file filesystem flags.
[ "Sets", "and", "unsets", "per", "-", "file", "filesystem", "flags", "." ]
9694f6f718844c33017052eb271f68b6c0d0b7d3
https://github.com/g2p/bedup/blob/9694f6f718844c33017052eb271f68b6c0d0b7d3/bedup/platform/chattr.py#L85-L107
train
luqasz/librouteros
librouteros/__init__.py
connect
def connect(host, username, password, **kwargs): """ Connect and login to routeros device. Upon success return a Api class. :param host: Hostname to connecto to. May be ipv4,ipv6,FQDN. :param username: Username to login with. :param password: Password to login with. Only ASCII characters allowe...
python
def connect(host, username, password, **kwargs): """ Connect and login to routeros device. Upon success return a Api class. :param host: Hostname to connecto to. May be ipv4,ipv6,FQDN. :param username: Username to login with. :param password: Password to login with. Only ASCII characters allowe...
[ "def", "connect", "(", "host", ",", "username", ",", "password", ",", "*", "*", "kwargs", ")", ":", "arguments", "=", "ChainMap", "(", "kwargs", ",", "defaults", ")", "transport", "=", "create_transport", "(", "host", ",", "*", "*", "arguments", ")", "...
Connect and login to routeros device. Upon success return a Api class. :param host: Hostname to connecto to. May be ipv4,ipv6,FQDN. :param username: Username to login with. :param password: Password to login with. Only ASCII characters allowed. :param timeout: Socket timeout. Defaults to 10. :p...
[ "Connect", "and", "login", "to", "routeros", "device", ".", "Upon", "success", "return", "a", "Api", "class", "." ]
59293eb49c07a339af87b0416e4619e78ca5176d
https://github.com/luqasz/librouteros/blob/59293eb49c07a339af87b0416e4619e78ca5176d/librouteros/__init__.py#L26-L54
train
luqasz/librouteros
librouteros/api.py
Api._readSentence
def _readSentence(self): """ Read one sentence and parse words. :returns: Reply word, dict with attribute words. """ reply_word, words = self.protocol.readSentence() words = dict(parseWord(word) for word in words) return reply_word, words
python
def _readSentence(self): """ Read one sentence and parse words. :returns: Reply word, dict with attribute words. """ reply_word, words = self.protocol.readSentence() words = dict(parseWord(word) for word in words) return reply_word, words
[ "def", "_readSentence", "(", "self", ")", ":", "reply_word", ",", "words", "=", "self", ".", "protocol", ".", "readSentence", "(", ")", "words", "=", "dict", "(", "parseWord", "(", "word", ")", "for", "word", "in", "words", ")", "return", "reply_word", ...
Read one sentence and parse words. :returns: Reply word, dict with attribute words.
[ "Read", "one", "sentence", "and", "parse", "words", "." ]
59293eb49c07a339af87b0416e4619e78ca5176d
https://github.com/luqasz/librouteros/blob/59293eb49c07a339af87b0416e4619e78ca5176d/librouteros/api.py#L29-L37
train
luqasz/librouteros
librouteros/api.py
Api._readResponse
def _readResponse(self): """ Yield each row of response untill !done is received. :throws TrapError: If one !trap is received. :throws MultiTrapError: If > 1 !trap is received. """ traps = [] reply_word = None while reply_word != '!done': repl...
python
def _readResponse(self): """ Yield each row of response untill !done is received. :throws TrapError: If one !trap is received. :throws MultiTrapError: If > 1 !trap is received. """ traps = [] reply_word = None while reply_word != '!done': repl...
[ "def", "_readResponse", "(", "self", ")", ":", "traps", "=", "[", "]", "reply_word", "=", "None", "while", "reply_word", "!=", "'!done'", ":", "reply_word", ",", "words", "=", "self", ".", "_readSentence", "(", ")", "if", "reply_word", "==", "'!trap'", "...
Yield each row of response untill !done is received. :throws TrapError: If one !trap is received. :throws MultiTrapError: If > 1 !trap is received.
[ "Yield", "each", "row", "of", "response", "untill", "!done", "is", "received", "." ]
59293eb49c07a339af87b0416e4619e78ca5176d
https://github.com/luqasz/librouteros/blob/59293eb49c07a339af87b0416e4619e78ca5176d/librouteros/api.py#L39-L58
train
luqasz/librouteros
librouteros/connections.py
Encoder.encodeSentence
def encodeSentence(self, *words): """ Encode given sentence in API format. :param words: Words to endoce. :returns: Encoded sentence. """ encoded = map(self.encodeWord, words) encoded = b''.join(encoded) # append EOS (end of sentence) byte encoded...
python
def encodeSentence(self, *words): """ Encode given sentence in API format. :param words: Words to endoce. :returns: Encoded sentence. """ encoded = map(self.encodeWord, words) encoded = b''.join(encoded) # append EOS (end of sentence) byte encoded...
[ "def", "encodeSentence", "(", "self", ",", "*", "words", ")", ":", "encoded", "=", "map", "(", "self", ".", "encodeWord", ",", "words", ")", "encoded", "=", "b''", ".", "join", "(", "encoded", ")", "# append EOS (end of sentence) byte", "encoded", "+=", "b...
Encode given sentence in API format. :param words: Words to endoce. :returns: Encoded sentence.
[ "Encode", "given", "sentence", "in", "API", "format", "." ]
59293eb49c07a339af87b0416e4619e78ca5176d
https://github.com/luqasz/librouteros/blob/59293eb49c07a339af87b0416e4619e78ca5176d/librouteros/connections.py#L14-L25
train
luqasz/librouteros
librouteros/connections.py
Encoder.encodeWord
def encodeWord(self, word): """ Encode word in API format. :param word: Word to encode. :returns: Encoded word. """ encoded_word = word.encode(encoding=self.encoding, errors='strict') return Encoder.encodeLength(len(word)) + encoded_word
python
def encodeWord(self, word): """ Encode word in API format. :param word: Word to encode. :returns: Encoded word. """ encoded_word = word.encode(encoding=self.encoding, errors='strict') return Encoder.encodeLength(len(word)) + encoded_word
[ "def", "encodeWord", "(", "self", ",", "word", ")", ":", "encoded_word", "=", "word", ".", "encode", "(", "encoding", "=", "self", ".", "encoding", ",", "errors", "=", "'strict'", ")", "return", "Encoder", ".", "encodeLength", "(", "len", "(", "word", ...
Encode word in API format. :param word: Word to encode. :returns: Encoded word.
[ "Encode", "word", "in", "API", "format", "." ]
59293eb49c07a339af87b0416e4619e78ca5176d
https://github.com/luqasz/librouteros/blob/59293eb49c07a339af87b0416e4619e78ca5176d/librouteros/connections.py#L27-L35
train
luqasz/librouteros
librouteros/connections.py
Encoder.encodeLength
def encodeLength(length): """ Encode given length in mikrotik format. :param length: Integer < 268435456. :returns: Encoded length. """ if length < 128: ored_length = length offset = -1 elif length < 16384: ored_length = length...
python
def encodeLength(length): """ Encode given length in mikrotik format. :param length: Integer < 268435456. :returns: Encoded length. """ if length < 128: ored_length = length offset = -1 elif length < 16384: ored_length = length...
[ "def", "encodeLength", "(", "length", ")", ":", "if", "length", "<", "128", ":", "ored_length", "=", "length", "offset", "=", "-", "1", "elif", "length", "<", "16384", ":", "ored_length", "=", "length", "|", "0x8000", "offset", "=", "-", "2", "elif", ...
Encode given length in mikrotik format. :param length: Integer < 268435456. :returns: Encoded length.
[ "Encode", "given", "length", "in", "mikrotik", "format", "." ]
59293eb49c07a339af87b0416e4619e78ca5176d
https://github.com/luqasz/librouteros/blob/59293eb49c07a339af87b0416e4619e78ca5176d/librouteros/connections.py#L38-L60
train
luqasz/librouteros
librouteros/connections.py
Decoder.determineLength
def determineLength(length): """ Given first read byte, determine how many more bytes needs to be known in order to get fully encoded length. :param length: First read byte. :return: How many bytes to read. """ integer = ord(length) if integer < 128: ...
python
def determineLength(length): """ Given first read byte, determine how many more bytes needs to be known in order to get fully encoded length. :param length: First read byte. :return: How many bytes to read. """ integer = ord(length) if integer < 128: ...
[ "def", "determineLength", "(", "length", ")", ":", "integer", "=", "ord", "(", "length", ")", "if", "integer", "<", "128", ":", "return", "0", "elif", "integer", "<", "192", ":", "return", "1", "elif", "integer", "<", "224", ":", "return", "2", "elif...
Given first read byte, determine how many more bytes needs to be known in order to get fully encoded length. :param length: First read byte. :return: How many bytes to read.
[ "Given", "first", "read", "byte", "determine", "how", "many", "more", "bytes", "needs", "to", "be", "known", "in", "order", "to", "get", "fully", "encoded", "length", "." ]
59293eb49c07a339af87b0416e4619e78ca5176d
https://github.com/luqasz/librouteros/blob/59293eb49c07a339af87b0416e4619e78ca5176d/librouteros/connections.py#L66-L85
train