code: 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 += 0x20000000
  
      bytes = ''
      real_value = None
  
      if n > 0x1fffff:
          real_value = n
          n >>= 1
          bytes += chr(0x80 | ((n >> 21) & 0xff))
  
      if n > 0x3fff:
          bytes += chr(0x80 | ((n >> 14) & 0xff))
  
      if n > 0x7f:
          bytes += chr(0x80 | ((n >> 7) & 0xff))
  
      if real_value is not None:
          n = real_value
  
      if n > 0x1fffff:
          bytes += chr(n & 0xff)
      else:
          bytes += chr(n & 0x7f)
  
      ENCODED_INT_CACHE[n] = bytes
  
      return bytes
docs: Encodes an int as a variable length signed 29-bit integer as defined by
      the spec.
  
      @param n: The integer to be encoded
      @return: The encoded string
      @rtype: C{str}
      @raise OverflowError: Out of range.