#NEWLINE# def readbits( self , count ) : #NEWLINE# #INDENT# if self . _buf : #NEWLINE# #INDENT# if ( ( self . _bitoffset + count ) >= 8 ) : #NEWLINE# #INDENT# val = ( ( ( 1 << ( 8 - self . _bitoffset ) ) - 1 ) & self . _buf [ 0 ] ) #NEWLINE# count -= ( 8 - self . _bitoffset ) #NEWLINE# self . _buf = b'' #NEWLINE# self . _bitoffset = 0 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# val = ( ( ( 1 << count ) - 1 ) & ( self . _buf [ 0 ] >> ( ( 8 - self . _bitoffset ) - count ) ) ) #NEWLINE# self . _bitoffset += count #NEWLINE# return val #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# val = 0 #NEWLINE# #UNINDENT# bytes = ( count >> 3 ) #NEWLINE# for i in range ( bytes ) : #NEWLINE# #INDENT# byt = self . _stream . read ( 1 ) #NEWLINE# val = ( ( val << 8 ) | byt [ 0 ] ) #NEWLINE# #UNINDENT# tail = ( count & 7 ) #NEWLINE# if tail : #NEWLINE# #INDENT# self . _buf = self . _stream . read ( 1 ) #NEWLINE# val <<= tail #NEWLINE# val |= ( self . _buf [ 0 ] >> ( 8 - tail ) ) #NEWLINE# self . _bitoffset = tail #NEWLINE# #UNINDENT# return val