def encint(value, forward=True):
 if (value < 0):
  raise ValueError(u'Cannot encode negative numbers as vwi')
 byts = bytearray()
 while True:
  b = (value & 127)
  value >>= 7
  byts.append(b)
  if (value == 0):
   break
 byts[(0 if forward else (-1))] |= 128
 byts.reverse()
 return bytes(byts)

def encint ( value , forward = True ) : if ( value < 0 ) : raise ValueError ( u'Cannot encode negative numbers as vwi' ) byts = bytearray ( ) while True : b = ( value & 127 ) value >>= 7 byts . append ( b ) if ( value == 0 ) : break byts [ ( 0 if forward else ( - 1 ) ) ] |= 128 byts . reverse ( ) return bytes ( byts )
some parts of the mobipocket format encode data as variable-width integers .