Belle II Software development
scripts.bitstring Namespace Reference

Classes

class  BitArray
 
class  Bits
 
class  BitStream
 
class  ByteAlignError
 
class  ByteStore
 
class  ConstBitStream
 
class  ConstByteStore
 
class  CreationError
 
class  Error
 
class  InterpretError
 
class  MmapByteArray
 
class  ReadError
 

Functions

def offsetcopy (s, newoffset)
 
def equal (a, b)
 
def tidy_input_string (s)
 
def structparser (token)
 
def tokenparser (fmt, keys=None, token_cache=None)
 
def expand_brackets (s)
 
def pack (fmt, *values, **kwargs)
 

Variables

str __licence__
 
str __version__ = "3.1.5"
 
str __author__ = "Scott Griffiths"
 
sys byteorder = sys.byteorder
 
bool bytealigned = False
 
int MAX_CHARS = 250
 
int CACHE_SIZE = 1000
 
dict BYTE_REVERSAL_DICT = dict()
 
 try :
 
range xrange = range
 
str basestring = str
 
len LEADING_OCT_CHARS = len(oct(1)) - 1
 
tuple INIT_NAMES
 
re TOKEN_RE
 
re DEFAULT_UINT = re.compile(r'(?P<len>[^=]+)?(=(?P<value>.*))?$', re.IGNORECASE)
 
re MULTIPLICATIVE_RE = re.compile(r'(?P<factor>.*)\*(?P<token>.+)')
 
re LITERAL_RE = re.compile(r'(?P<name>0(x|o|b))(?P<value>.+)', re.IGNORECASE)
 
re STRUCT_PACK_RE = re.compile(r'(?P<endian><|>|@)?(?P<fmt>(?:\d*[bBhHlLqQfd])+)$')
 
re STRUCT_SPLIT_RE = re.compile(r'\d*[bBhHlLqQfd]')
 
dict REPLACEMENTS_BE
 
dict REPLACEMENTS_LE
 
dict PACK_CODE_SIZE
 
dict _tokenname_to_initialiser
 
re BRACKET_RE = re.compile(r'(?P<factor>\d+)\*\‍(')
 
list OCT_TO_BITS = ['{0:03b}'.format(i) for i in xrange(8)]
 
dict BIT_COUNT = dict(zip(xrange(256), [bin(i).count('1') for i in xrange(256)]))
 
dict name_to_read
 
dict init_with_length_and_offset
 
dict init_with_length_only
 
dict init_without_length_or_offset
 
Bits ConstBitArray = Bits
 
BitStream BitString = BitStream
 
list __all__
 

Detailed Description

This package defines classes that simplify bit-wise creation, manipulation and
interpretation of data.

Classes:

Bits -- An immutable container for binary data.
BitArray -- A mutable container for binary data.
ConstBitStream -- An immutable container with streaming methods.
BitStream -- A mutable container with streaming methods.

                      Bits (base class)
                     /    \
 + mutating methods /      \ + streaming methods
                   /        \
              BitArray   ConstBitStream
                   \        /
                    \      /
                     \    /
                    BitStream

Functions:

pack -- Create a BitStream from a format string.

Exceptions:

Error -- Module exception base class.
CreationError -- Error during creation.
InterpretError -- Inappropriate interpretation of binary data.
ByteAlignError -- Whole byte position or length needed.
ReadError -- Reading or peeking past the end of a bitstring.

https://github.com/scott-griffiths/bitstring

Function Documentation

◆ equal()

def equal (   a,
  b 
)
Return True if ByteStores a == b.

Not part of public interface.

Definition at line 292 of file bitstring.py.

292def equal(a, b):
293 """Return True if ByteStores a == b.
294
295 Not part of public interface.
296 """
297 # We want to return False for inequality as soon as possible, which
298 # means we get lots of special cases.
299 # First the easy one - compare lengths:
300 a_bitlength = a.bitlength
301 b_bitlength = b.bitlength
302 if a_bitlength != b_bitlength:
303 return False
304 if not a_bitlength:
305 assert b_bitlength == 0
306 return True
307 # Make 'a' the one with the smaller offset
308 if (a.offset % 8) > (b.offset % 8):
309 a, b = b, a
310 # and create some aliases
311 a_bitoff = a.offset % 8
312 b_bitoff = b.offset % 8
313 a_byteoffset = a.byteoffset
314 b_byteoffset = b.byteoffset
315 a_bytelength = a.bytelength
316 b_bytelength = b.bytelength
317 da = a._rawarray
318 db = b._rawarray
319
320 # If they are pointing to the same data, they must be equal
321 if da is db and a.offset == b.offset:
322 return True
323
324 if a_bitoff == b_bitoff:
325 bits_spare_in_last_byte = 8 - (a_bitoff + a_bitlength) % 8
326 if bits_spare_in_last_byte == 8:
327 bits_spare_in_last_byte = 0
328 # Special case for a, b contained in a single byte
329 if a_bytelength == 1:
330 a_val = ((da[a_byteoffset] << a_bitoff) & 0xff) >> (8 - a_bitlength)
331 b_val = ((db[b_byteoffset] << b_bitoff) & 0xff) >> (8 - b_bitlength)
332 return a_val == b_val
333 # Otherwise check first byte
334 if da[a_byteoffset] & (0xff >> a_bitoff) != db[b_byteoffset] & (0xff >> b_bitoff):
335 return False
336 # then everything up to the last
337 b_a_offset = b_byteoffset - a_byteoffset
338 for x in range(1 + a_byteoffset, a_byteoffset + a_bytelength - 1):
339 if da[x] != db[b_a_offset + x]:
340 return False
341 # and finally the last byte
342 return (da[a_byteoffset + a_bytelength - 1] >> bits_spare_in_last_byte ==
343 db[b_byteoffset + b_bytelength - 1] >> bits_spare_in_last_byte)
344
345 assert a_bitoff != b_bitoff
346 # This is how much we need to shift a to the right to compare with b:
347 shift = b_bitoff - a_bitoff
348 # Special case for b only one byte long
349 if b_bytelength == 1:
350 assert a_bytelength == 1
351 a_val = ((da[a_byteoffset] << a_bitoff) & 0xff) >> (8 - a_bitlength)
352 b_val = ((db[b_byteoffset] << b_bitoff) & 0xff) >> (8 - b_bitlength)
353 return a_val == b_val
354 # Special case for a only one byte long
355 if a_bytelength == 1:
356 assert b_bytelength == 2
357 a_val = ((da[a_byteoffset] << a_bitoff) & 0xff) >> (8 - a_bitlength)
358 b_val = ((db[b_byteoffset] << 8) + db[b_byteoffset + 1]) << b_bitoff
359 b_val &= 0xffff
360 b_val >>= 16 - b_bitlength
361 return a_val == b_val
362
363 # Compare first byte of b with bits from first byte of a
364 if (da[a_byteoffset] & (0xff >> a_bitoff)) >> shift != db[b_byteoffset] & (0xff >> b_bitoff):
365 return False
366 # Now compare every full byte of b with bits from 2 bytes of a
367 for x in range(1, b_bytelength - 1):
368 # Construct byte from 2 bytes in a to compare to byte in b
369 b_val = db[b_byteoffset + x]
370 a_val = ((da[a_byteoffset + x - 1] << 8) + da[a_byteoffset + x]) >> shift
371 a_val &= 0xff
372 if a_val != b_val:
373 return False
374
375 # Now check bits in final byte of b
376 final_b_bits = (b.offset + b_bitlength) % 8
377 if not final_b_bits:
378 final_b_bits = 8
379 b_val = db[b_byteoffset + b_bytelength - 1] >> (8 - final_b_bits)
380 final_a_bits = (a.offset + a_bitlength) % 8
381 if not final_a_bits:
382 final_a_bits = 8
383 if b.bytelength > a_bytelength:
384 assert b_bytelength == a_bytelength + 1
385 a_val = da[a_byteoffset + a_bytelength - 1] >> (8 - final_a_bits)
386 a_val &= 0xff >> (8 - final_b_bits)
387 return a_val == b_val
388 assert a_bytelength == b_bytelength
389 a_val = da[a_byteoffset + a_bytelength - 2] << 8
390 a_val += da[a_byteoffset + a_bytelength - 1]
391 a_val >>= (8 - final_a_bits)
392 a_val &= 0xff >> (8 - final_b_bits)
393 return a_val == b_val
394
395

◆ expand_brackets()

def expand_brackets (   s)
Remove whitespace and expand all brackets.

Definition at line 648 of file bitstring.py.

648def expand_brackets(s):
649 """Remove whitespace and expand all brackets."""
650 s = ''.join(s.split())
651 while True:
652 start = s.find('(')
653 if start == -1:
654 break
655 count = 1 # Number of hanging open brackets
656 p = start + 1
657 while p < len(s):
658 if s[p] == '(':
659 count += 1
660 if s[p] == ')':
661 count -= 1
662 if not count:
663 break
664 p += 1
665 if count:
666 raise ValueError("Unbalanced parenthesis in '{0}'.".format(s))
667 if start == 0 or s[start - 1] != '*':
668 s = s[0:start] + s[start + 1:p] + s[p + 1:]
669 else:
670 m = BRACKET_RE.search(s)
671 if m:
672 factor = int(m.group('factor'))
673 matchstart = m.start('factor')
674 s = s[0:matchstart] + (factor - 1) * (s[start + 1:p] + ',') + s[start + 1:p] + s[p + 1:]
675 else:
676 raise ValueError("Failed to parse '{0}'.".format(s))
677 return s
678
679
680# This converts a single octal digit to 3 bits.

◆ offsetcopy()

def offsetcopy (   s,
  newoffset 
)
Return a copy of a ByteStore with the newoffset.

Not part of public interface.

Definition at line 250 of file bitstring.py.

250def offsetcopy(s, newoffset):
251 """Return a copy of a ByteStore with the newoffset.
252
253 Not part of public interface.
254 """
255 assert 0 <= newoffset < 8
256 if not s.bitlength:
257 return copy.copy(s)
258 else:
259 if newoffset == s.offset % 8:
260 return ByteStore(s.getbyteslice(s.byteoffset, s.byteoffset + s.bytelength), s.bitlength, newoffset)
261 newdata = []
262 d = s._rawarray
263 assert newoffset != s.offset % 8
264 if newoffset < s.offset % 8:
265 # We need to shift everything left
266 shiftleft = s.offset % 8 - newoffset
267 # First deal with everything except for the final byte
268 for x in range(s.byteoffset, s.byteoffset + s.bytelength - 1):
269 newdata.append(((d[x] << shiftleft) & 0xff) +
270 (d[x + 1] >> (8 - shiftleft)))
271 bits_in_last_byte = (s.offset + s.bitlength) % 8
272 if not bits_in_last_byte:
273 bits_in_last_byte = 8
274 if bits_in_last_byte > shiftleft:
275 newdata.append((d[s.byteoffset + s.bytelength - 1] << shiftleft) & 0xff)
276 else: # newoffset > s._offset % 8
277 shiftright = newoffset - s.offset % 8
278 newdata.append(s.getbyte(0) >> shiftright)
279 for x in range(s.byteoffset + 1, s.byteoffset + s.bytelength):
280 newdata.append(((d[x - 1] << (8 - shiftright)) & 0xff) +
281 (d[x] >> shiftright))
282 bits_in_last_byte = (s.offset + s.bitlength) % 8
283 if not bits_in_last_byte:
284 bits_in_last_byte = 8
285 if bits_in_last_byte + shiftright > 8:
286 newdata.append((d[s.byteoffset + s.bytelength - 1] << (8 - shiftright)) & 0xff)
287 new_s = ByteStore(bytearray(newdata), s.bitlength, newoffset)
288 assert new_s.offset == newoffset
289 return new_s
290
291

◆ pack()

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

fmt -- A single string or a list of strings with comma separated tokens
       describing how to create the BitStream.
values -- Zero or more values to pack according to the format.
kwargs -- A dictionary or keyword-value pairs - the keywords used in the
          format string will be replaced with their given value.

Token examples: 'int:12'    : 12 bits as a signed integer
                'uint:8'    : 8 bits as an unsigned integer
                'float:64'  : 8 bytes as a big-endian float
                'intbe:16'  : 2 bytes as a big-endian signed integer
                'uintbe:16' : 2 bytes as a big-endian unsigned integer
                'intle:32'  : 4 bytes as a little-endian signed integer
                'uintle:32' : 4 bytes as a little-endian unsigned integer
                'floatle:64': 8 bytes as a little-endian float
                'intne:24'  : 3 bytes as a native-endian signed integer
                'uintne:24' : 3 bytes as a native-endian unsigned integer
                'floatne:32': 4 bytes as a native-endian float
                'hex:80'    : 80 bits as a hex string
                'oct:9'     : 9 bits as an octal string
                'bin:1'     : single bit binary string
                'ue' / 'uie': next bits as unsigned exp-Golomb code
                'se' / 'sie': next bits as signed exp-Golomb code
                'bits:5'    : 5 bits as a bitstring object
                'bytes:10'  : 10 bytes as a bytes object
                'bool'      : 1 bit as a bool
                'pad:3'     : 3 zero bits as padding

>>> s = pack('uint:12, bits', 100, '0xffe')
>>> t = pack(['bits', 'bin:3'], s, '111')
>>> u = pack('uint:8=a, uint:8=b, uint:55=a', a=6, b=44)

Definition at line 4170 of file bitstring.py.

4170def pack(fmt, *values, **kwargs):
4171 """Pack the values according to the format string and return a new BitStream.
4172
4173 fmt -- A single string or a list of strings with comma separated tokens
4174 describing how to create the BitStream.
4175 values -- Zero or more values to pack according to the format.
4176 kwargs -- A dictionary or keyword-value pairs - the keywords used in the
4177 format string will be replaced with their given value.
4178
4179 Token examples: 'int:12' : 12 bits as a signed integer
4180 'uint:8' : 8 bits as an unsigned integer
4181 'float:64' : 8 bytes as a big-endian float
4182 'intbe:16' : 2 bytes as a big-endian signed integer
4183 'uintbe:16' : 2 bytes as a big-endian unsigned integer
4184 'intle:32' : 4 bytes as a little-endian signed integer
4185 'uintle:32' : 4 bytes as a little-endian unsigned integer
4186 'floatle:64': 8 bytes as a little-endian float
4187 'intne:24' : 3 bytes as a native-endian signed integer
4188 'uintne:24' : 3 bytes as a native-endian unsigned integer
4189 'floatne:32': 4 bytes as a native-endian float
4190 'hex:80' : 80 bits as a hex string
4191 'oct:9' : 9 bits as an octal string
4192 'bin:1' : single bit binary string
4193 'ue' / 'uie': next bits as unsigned exp-Golomb code
4194 'se' / 'sie': next bits as signed exp-Golomb code
4195 'bits:5' : 5 bits as a bitstring object
4196 'bytes:10' : 10 bytes as a bytes object
4197 'bool' : 1 bit as a bool
4198 'pad:3' : 3 zero bits as padding
4199
4200 >>> s = pack('uint:12, bits', 100, '0xffe')
4201 >>> t = pack(['bits', 'bin:3'], s, '111')
4202 >>> u = pack('uint:8=a, uint:8=b, uint:55=a', a=6, b=44)
4203
4204 """
4205 tokens = []
4206 if isinstance(fmt, basestring):
4207 fmt = [fmt]
4208 try:
4209 for f_item in fmt:
4210 _, tkns = tokenparser(f_item, tuple(sorted(kwargs.keys())))
4211 tokens.extend(tkns)
4212 except ValueError as e:
4213 raise CreationError(*e.args)
4214 value_iter = iter(values)
4215 s = BitStream()
4216 try:
4217 for name, length, value in tokens:
4218 # If the value is in the kwd dictionary then it takes precedence.
4219 if value in kwargs:
4220 value = kwargs[value]
4221 # If the length is in the kwd dictionary then use that too.
4222 if length in kwargs:
4223 length = kwargs[length]
4224 # Also if we just have a dictionary name then we want to use it
4225 if name in kwargs and length is None and value is None:
4226 s.append(kwargs[name])
4227 continue
4228 if length is not None:
4229 length = int(length)
4230 if value is None and name != 'pad':
4231 # Take the next value from the ones provided
4232 value = next(value_iter)
4233 s._append(BitStream._init_with_token(name, length, value))
4234 except StopIteration:
4235 raise CreationError("Not enough parameters present to pack according to the "
4236 "format. {0} values are needed.", len(tokens))
4237 try:
4238 next(value_iter)
4239 except StopIteration:
4240 # Good, we've used up all the *values.
4241 return s
4242 raise CreationError("Too many parameters present to pack according to the format.")
4243
4244
4245# Aliases for backward compatibility

◆ structparser()

def structparser (   token)
Parse struct-like format string token into sub-token list.

Definition at line 511 of file bitstring.py.

511def structparser(token):
512 """Parse struct-like format string token into sub-token list."""
513 m = STRUCT_PACK_RE.match(token)
514 if not m:
515 return [token]
516 else:
517 endian = m.group('endian')
518 if endian is None:
519 return [token]
520 # Split the format string into a list of 'q', '4h' etc.
521 formatlist = re.findall(STRUCT_SPLIT_RE, m.group('fmt'))
522 # Now deal with mulitiplicative factors, 4h -> hhhh etc.
523 fmt = ''.join([f[-1] * int(f[:-1]) if len(f) != 1 else
524 f for f in formatlist])
525 if endian == '@':
526 # Native endianness
527 if byteorder == 'little':
528 endian = '<'
529 else:
530 assert byteorder == 'big'
531 endian = '>'
532 if endian == '<':
533 tokens = [REPLACEMENTS_LE[c] for c in fmt]
534 else:
535 assert endian == '>'
536 tokens = [REPLACEMENTS_BE[c] for c in fmt]
537 return tokens
538
539

◆ tidy_input_string()

def tidy_input_string (   s)
Return string made lowercase and with all whitespace removed.

Definition at line 463 of file bitstring.py.

463def tidy_input_string(s):
464 """Return string made lowercase and with all whitespace removed."""
465 s = ''.join(s.split()).lower()
466 return s
467
468

◆ tokenparser()

def tokenparser (   fmt,
  keys = None,
  token_cache = None 
)
Divide the format string into tokens and parse them.

Return stretchy token and list of [initialiser, length, value]
initialiser is one of: hex, oct, bin, uint, int, se, ue, 0x, 0o, 0b etc.
length is None if not known, as is value.

If the token is in the keyword dictionary (keys) then it counts as a
special case and isn't messed with.

tokens must be of the form: [factor*][initialiser][:][length][=value]

Definition at line 540 of file bitstring.py.

540def tokenparser(fmt, keys=None, token_cache=None):
541 """Divide the format string into tokens and parse them.
542
543 Return stretchy token and list of [initialiser, length, value]
544 initialiser is one of: hex, oct, bin, uint, int, se, ue, 0x, 0o, 0b etc.
545 length is None if not known, as is value.
546
547 If the token is in the keyword dictionary (keys) then it counts as a
548 special case and isn't messed with.
549
550 tokens must be of the form: [factor*][initialiser][:][length][=value]
551
552 """
553 if token_cache is None:
554 token_cache = {}
555 try:
556 return token_cache[(fmt, keys)]
557 except KeyError:
558 token_key = (fmt, keys)
559 # Very inefficient expanding of brackets.
560 fmt = expand_brackets(fmt)
561 # Split tokens by ',' and remove whitespace
562 # The meta_tokens can either be ordinary single tokens or multiple
563 # struct-format token strings.
564 meta_tokens = (''.join(f.split()) for f in fmt.split(','))
565 return_values = []
566 stretchy_token = False
567 for meta_token in meta_tokens:
568 # See if it has a multiplicative factor
569 m = MULTIPLICATIVE_RE.match(meta_token)
570 if not m:
571 factor = 1
572 else:
573 factor = int(m.group('factor'))
574 meta_token = m.group('token')
575 # See if it's a struct-like format
576 tokens = structparser(meta_token)
577 ret_vals = []
578 for token in tokens:
579 if keys and token in keys:
580 # Don't bother parsing it, it's a keyword argument
581 ret_vals.append([token, None, None])
582 continue
583 value = length = None
584 if token == '':
585 continue
586 # Match literal tokens of the form 0x... 0o... and 0b...
587 m = LITERAL_RE.match(token)
588 if m:
589 name = m.group('name')
590 value = m.group('value')
591 ret_vals.append([name, length, value])
592 continue
593 # Match everything else:
594 m1 = TOKEN_RE.match(token)
595 if not m1:
596 # and if you don't specify a 'name' then the default is 'uint':
597 m2 = DEFAULT_UINT.match(token)
598 if not m2:
599 raise ValueError("Don't understand token '{0}'.".format(token))
600 if m1:
601 name = m1.group('name')
602 length = m1.group('len')
603 if m1.group('value'):
604 value = m1.group('value')
605 else:
606 assert m2
607 name = 'uint'
608 length = m2.group('len')
609 if m2.group('value'):
610 value = m2.group('value')
611 if name == 'bool':
612 if length is not None:
613 raise ValueError("You can't specify a length with bool tokens - they are always one bit.")
614 length = 1
615 if length is None and name not in ('se', 'ue', 'sie', 'uie'):
616 stretchy_token = True
617 if length is not None:
618 # Try converting length to int, otherwise check it's a key.
619 try:
620 length = int(length)
621 if length < 0:
622 raise Error
623 # For the 'bytes' token convert length to bits.
624 if name == 'bytes':
625 length *= 8
626 except Error:
627 raise ValueError("Can't read a token with a negative length.")
628 except ValueError:
629 if not keys or length not in keys:
630 raise ValueError("Don't understand length '{0}' of token.".format(length))
631 ret_vals.append([name, length, value])
632 # This multiplies by the multiplicative factor, but this means that
633 # we can't allow keyword values as multipliers (e.g. n*uint:8).
634 # The only way to do this would be to return the factor in some fashion
635 # (we can't use the key's value here as it would mean that we couldn't
636 # sensibly continue to cache the function's results. (TODO).
637 return_values.extend(ret_vals * factor)
638 return_values = [tuple(x) for x in return_values]
639 if len(token_cache) < CACHE_SIZE:
640 token_cache[token_key] = stretchy_token, return_values
641 return stretchy_token, return_values
642
643
644# Looks for first number*(

Variable Documentation

◆ __all__

list __all__
private
Initial value:
1= ['ConstBitArray', 'ConstBitStream', 'BitStream', 'BitArray',
2 'Bits', 'BitString', 'pack', 'Error', 'ReadError',
3 'InterpretError', 'ByteAlignError', 'CreationError', 'bytealigned']

Definition at line 4249 of file bitstring.py.

◆ __author__

str __author__ = "Scott Griffiths"
private

Definition at line 65 of file bitstring.py.

◆ __licence__

str __licence__
private
Initial value:
1= """
2The MIT License
3
4Copyright (c) 2006-2016 Scott Griffiths (dr.scottgriffiths@gmail.com)
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in
14all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22THE SOFTWARE.
23"""

Definition at line 39 of file bitstring.py.

◆ __version__

str __version__ = "3.1.5"
private

Definition at line 63 of file bitstring.py.

◆ _tokenname_to_initialiser

dict _tokenname_to_initialiser
protected
Initial value:
1= {'hex': 'hex', '0x': 'hex', '0X': 'hex', 'oct': 'oct',
2 '0o': 'oct', '0O': 'oct', 'bin': 'bin', '0b': 'bin',
3 '0B': 'bin', 'bits': 'auto', 'bytes': 'bytes', 'pad': 'pad'}

Definition at line 506 of file bitstring.py.

◆ basestring

str basestring = str

Definition at line 457 of file bitstring.py.

◆ BIT_COUNT

dict BIT_COUNT = dict(zip(xrange(256), [bin(i).count('1') for i in xrange(256)]))

Definition at line 684 of file bitstring.py.

◆ BitString

BitStream BitString = BitStream

Definition at line 4247 of file bitstring.py.

◆ BRACKET_RE

re BRACKET_RE = re.compile(r'(?P<factor>\d+)\*\‍(')

Definition at line 645 of file bitstring.py.

◆ BYTE_REVERSAL_DICT

dict BYTE_REVERSAL_DICT = dict()

Definition at line 444 of file bitstring.py.

◆ bytealigned

bool bytealigned = False

Definition at line 81 of file bitstring.py.

◆ byteorder

sys byteorder = sys.byteorder

Definition at line 79 of file bitstring.py.

◆ CACHE_SIZE

int CACHE_SIZE = 1000

Definition at line 88 of file bitstring.py.

◆ ConstBitArray

Bits ConstBitArray = Bits

Definition at line 4246 of file bitstring.py.

◆ DEFAULT_UINT

re DEFAULT_UINT = re.compile(r'(?P<len>[^=]+)?(=(?P<value>.*))?$', re.IGNORECASE)

Definition at line 475 of file bitstring.py.

◆ INIT_NAMES

tuple INIT_NAMES
Initial value:
1= ('uint', 'int', 'ue', 'se', 'sie', 'uie', 'hex', 'oct', 'bin', 'bits',
2 'uintbe', 'intbe', 'uintle', 'intle', 'uintne', 'intne',
3 'float', 'floatbe', 'floatle', 'floatne', 'bytes', 'bool', 'pad')

Definition at line 469 of file bitstring.py.

◆ init_with_length_and_offset

dict init_with_length_and_offset
Initial value:
1= {'bytes': Bits._setbytes_safe,
2 'filename': Bits._setfile,
3 }

Definition at line 2920 of file bitstring.py.

◆ init_with_length_only

dict init_with_length_only
Initial value:
1= {'uint': Bits._setuint,
2 'int': Bits._setint,
3 'float': Bits._setfloat,
4 'uintbe': Bits._setuintbe,
5 'intbe': Bits._setintbe,
6 'floatbe': Bits._setfloat,
7 'uintle': Bits._setuintle,
8 'intle': Bits._setintle,
9 'floatle': Bits._setfloatle,
10 'uintne': Bits._setuintne,
11 'intne': Bits._setintne,
12 'floatne': Bits._setfloatne,
13 }

Definition at line 2924 of file bitstring.py.

◆ init_without_length_or_offset

dict init_without_length_or_offset
Initial value:
1= {'bin': Bits._setbin_safe,
2 'hex': Bits._sethex,
3 'oct': Bits._setoct,
4 'ue': Bits._setue,
5 'se': Bits._setse,
6 'uie': Bits._setuie,
7 'sie': Bits._setsie,
8 'bool': Bits._setbool,
9 }

Definition at line 2938 of file bitstring.py.

◆ LEADING_OCT_CHARS

len LEADING_OCT_CHARS = len(oct(1)) - 1

Definition at line 460 of file bitstring.py.

◆ LITERAL_RE

re LITERAL_RE = re.compile(r'(?P<name>0(x|o|b))(?P<value>.+)', re.IGNORECASE)

Definition at line 480 of file bitstring.py.

◆ MAX_CHARS

int MAX_CHARS = 250

Definition at line 85 of file bitstring.py.

◆ MULTIPLICATIVE_RE

re MULTIPLICATIVE_RE = re.compile(r'(?P<factor>.*)\*(?P<token>.+)')

Definition at line 477 of file bitstring.py.

◆ name_to_read

dict name_to_read
Initial value:
1= {'uint': Bits._readuint,
2 'uintle': Bits._readuintle,
3 'uintbe': Bits._readuintbe,
4 'uintne': Bits._readuintne,
5 'int': Bits._readint,
6 'intle': Bits._readintle,
7 'intbe': Bits._readintbe,
8 'intne': Bits._readintne,
9 'float': Bits._readfloat,
10 'floatbe': Bits._readfloat, # floatbe is a synonym for float
11 'floatle': Bits._readfloatle,
12 'floatne': Bits._readfloatne,
13 'hex': Bits._readhex,
14 'oct': Bits._readoct,
15 'bin': Bits._readbin,
16 'bits': Bits._readbits,
17 'bytes': Bits._readbytes,
18 'ue': Bits._readue,
19 'se': Bits._readse,
20 'uie': Bits._readuie,
21 'sie': Bits._readsie,
22 'bool': Bits._readbool,
23 }

Definition at line 2895 of file bitstring.py.

◆ OCT_TO_BITS

list OCT_TO_BITS = ['{0:03b}'.format(i) for i in xrange(8)]

Definition at line 681 of file bitstring.py.

◆ PACK_CODE_SIZE

dict PACK_CODE_SIZE
Initial value:
1= {'b': 1, 'B': 1, 'h': 2, 'H': 2, 'l': 4, 'L': 4,
2 'q': 8, 'Q': 8, 'f': 4, 'd': 8}

Definition at line 503 of file bitstring.py.

◆ REPLACEMENTS_BE

dict REPLACEMENTS_BE
Initial value:
1= {'b': 'intbe:8', 'B': 'uintbe:8',
2 'h': 'intbe:16', 'H': 'uintbe:16',
3 'l': 'intbe:32', 'L': 'uintbe:32',
4 'q': 'intbe:64', 'Q': 'uintbe:64',
5 'f': 'floatbe:32', 'd': 'floatbe:64'}

Definition at line 490 of file bitstring.py.

◆ REPLACEMENTS_LE

dict REPLACEMENTS_LE
Initial value:
1= {'b': 'intle:8', 'B': 'uintle:8',
2 'h': 'intle:16', 'H': 'uintle:16',
3 'l': 'intle:32', 'L': 'uintle:32',
4 'q': 'intle:64', 'Q': 'uintle:64',
5 'f': 'floatle:32', 'd': 'floatle:64'}

Definition at line 496 of file bitstring.py.

◆ STRUCT_PACK_RE

re STRUCT_PACK_RE = re.compile(r'(?P<endian><|>|@)?(?P<fmt>(?:\d*[bBhHlLqQfd])+)$')

Definition at line 483 of file bitstring.py.

◆ STRUCT_SPLIT_RE

re STRUCT_SPLIT_RE = re.compile(r'\d*[bBhHlLqQfd]')

Definition at line 486 of file bitstring.py.

◆ TOKEN_RE

re TOKEN_RE
Initial value:
1= re.compile(r'(?P<name>' + '|'.join(INIT_NAMES) +
2 r')((:(?P<len>[^=]+)))?(=(?P<value>.*))?$', re.IGNORECASE)

Definition at line 473 of file bitstring.py.

◆ try

try :

Definition at line 448 of file bitstring.py.

◆ xrange

range xrange = range

Definition at line 456 of file bitstring.py.