def encode_int(n):
 global ENCODED_INT_CACHE
 try:
  return ENCODED_INT_CACHE[n]
 except KeyError:
  pass
 if ((n < MIN_29B_INT) or (n > MAX_29B_INT)):
  raise OverflowError('Out of range')
 if (n < 0):
  n += 536870912
 bytes = ''
 real_value = None
 if (n > 2097151):
  real_value = n
  n >>= 1
  bytes += chr((128 | ((n >> 21) & 255)))
 if (n > 16383):
  bytes += chr((128 | ((n >> 14) & 255)))
 if (n > 127):
  bytes += chr((128 | ((n >> 7) & 255)))
 if (real_value is not None):
  n = real_value
 if (n > 2097151):
  bytes += chr((n & 255))
 else:
  bytes += chr((n & 127))
 ENCODED_INT_CACHE[n] = bytes
 return bytes

def encode_int ( n ) : global ENCODED_INT_CACHE try : return ENCODED_INT_CACHE [ n ] except KeyError : pass if ( ( n < MIN_29B_INT ) or ( n > MAX_29B_INT ) ) : raise OverflowError ( 'Out of range' ) if ( n < 0 ) : n += 536870912 bytes = '' real_value = None if ( n > 2097151 ) : real_value = n n >>= 1 bytes += chr ( ( 128 | ( ( n >> 21 ) & 255 ) ) ) if ( n > 16383 ) : bytes += chr ( ( 128 | ( ( n >> 14 ) & 255 ) ) ) if ( n > 127 ) : bytes += chr ( ( 128 | ( ( n >> 7 ) & 255 ) ) ) if ( real_value is not None ) : n = real_value if ( n > 2097151 ) : bytes += chr ( ( n & 255 ) ) else : bytes += chr ( ( n & 127 ) ) ENCODED_INT_CACHE [ n ] = bytes return bytes
encodes an integer into serialization .