# Path: mom/_compat.py
#   INT_MAX = sys.maxsize
#   INT_MAX = sys.maxint
# INT64_MAX = (1 << 63) - 1
# INT32_MAX = (1 << 31) - 1
# INT16_MAX = (1 << 15) - 1
# UINT128_MAX = (1 << 128) - 1    # 340282366920938463463374607431768211455L
# UINT64_MAX = 0xffffffffffffffff  # ((1 << 64) - 1)
# UINT32_MAX = 0xffffffff  # ((1 << 32) - 1)
# UINT16_MAX = 0xffff  # ((1 << 16) - 1)
# UINT8_MAX = 0xff
#   MACHINE_WORD_SIZE = 64
#   UINT_MAX = UINT64_MAX
#   MACHINE_WORD_SIZE = 32
#   UINT_MAX = UINT32_MAX
#   MACHINE_WORD_SIZE = 64
#   UINT_MAX = UINT64_MAX
#   LONG_TYPE = long
#   LONG_TYPE = int
#   INT_TYPE = long
#   INTEGER_TYPES = (int, long)
#   INT_TYPE = int
#   INTEGER_TYPES = (int,)
#   BYTES_TYPE = bytes
#   BYTES_TYPE = str
#   UNICODE_TYPE = unicode
#   BASESTRING_TYPE = basestring
#   HAVE_PYTHON3 = False
#   UNICODE_TYPE = str
#   BASESTRING_TYPE = (str, bytes)
#   HAVE_PYTHON3 = True
# ZERO_BYTE = byte_literal("\x00")
# EMPTY_BYTE = byte_literal("")
# EQUAL_BYTE = byte_literal("=")
# PLUS_BYTE = byte_literal("+")
# HYPHEN_BYTE = byte_literal("-")
# FORWARD_SLASH_BYTE = byte_literal("/")
# UNDERSCORE_BYTE = byte_literal("_")
# DIGIT_ZERO_BYTE = byte_literal("0")
# HAVE_LITTLE_ENDIAN = bool(struct.pack("h", 1) == "\x01\x00")
#   def byte_ord(byte_):
#   def byte_ord(byte_):
#   def byte_literal(literal):
#   def byte_literal(literal):
#   def dict_each(func, iterable):
#   def dict_each(func, iterable):
#   def next(iterator, default=throw):
#   def generate_random_bytes(count):
#     def generate_random_bytes(count):
#       def generate_random_bytes(count):
#       def generate_random_bytes(_):
# def get_word_alignment(num, force_arch=64,
#                        _machine_word_size=MACHINE_WORD_SIZE):
#   class Throw(object):
# 
# Path: mom/builtins.py
# def byte(number):
# def bytes_leading(raw_bytes, needle=_compat.ZERO_BYTE):
# def bytes_trailing(raw_bytes, needle=_compat.ZERO_BYTE):
# def bin(number, prefix="0b"):
# def hex(number, prefix="0x"):
# def is_sequence(obj):
# def is_unicode(obj):
# def is_bytes(obj):
# def is_bytes_or_unicode(obj):
# def is_integer(obj):
# def integer_byte_length(number):
# def integer_byte_size(number):
# def integer_bit_length(number):
# def integer_bit_size(number):
# def integer_bit_count(number):
# def is_even(num):
# def is_odd(num):
# def is_positive(num):
# def is_negative(num):


  import psyco
import array
import struct
from mom import _compat
from mom import builtins
  Convert a integer to bytes (base-256 representation)::

      integer_to_bytes(n:int, chunk_size:int) : string

  .. WARNING:
      Does not preserve leading zeros if you don't specify a chunk size.

  :param number:
      Integer value
  :param chunk_size:
      If optional chunk size is given and greater than zero, pad the front of
      the byte string with binary zeros so that the length is a multiple of
      ``chunk_size``. Raises an OverflowError if the chunk_size is not
      sufficient to represent the integer.
  :returns:
      Raw bytes (base-256 representation).
  :raises:
      ``OverflowError`` when block_size is given and the number takes up more
      bytes than fit into the block.
  """
  # Machine word aligned byte array based implementation.
  if number < 0:
    raise ValueError("Number must be unsigned integer: %d" % number)

  raw_bytes = EMPTY_BYTE
  if not number:
    raw_bytes = ZERO_BYTE

  # Align packing to machine word size.
  num = number

# Path: mom/_compat.py
#   INT_MAX = sys.maxsize
#   INT_MAX = sys.maxint
# INT64_MAX = (1 << 63) - 1
# INT32_MAX = (1 << 31) - 1
# INT16_MAX = (1 << 15) - 1
# UINT128_MAX = (1 << 128) - 1    # 340282366920938463463374607431768211455L
# UINT64_MAX = 0xffffffffffffffff  # ((1 << 64) - 1)
# UINT32_MAX = 0xffffffff  # ((1 << 32) - 1)
# UINT16_MAX = 0xffff  # ((1 << 16) - 1)
# UINT8_MAX = 0xff
#   MACHINE_WORD_SIZE = 64
#   UINT_MAX = UINT64_MAX
#   MACHINE_WORD_SIZE = 32
#   UINT_MAX = UINT32_MAX
#   MACHINE_WORD_SIZE = 64
#   UINT_MAX = UINT64_MAX
#   LONG_TYPE = long
#   LONG_TYPE = int
#   INT_TYPE = long
#   INTEGER_TYPES = (int, long)
#   INT_TYPE = int
#   INTEGER_TYPES = (int,)
#   BYTES_TYPE = bytes
#   BYTES_TYPE = str
#   UNICODE_TYPE = unicode
#   BASESTRING_TYPE = basestring
#   HAVE_PYTHON3 = False
#   UNICODE_TYPE = str
#   BASESTRING_TYPE = (str, bytes)
#   HAVE_PYTHON3 = True
# ZERO_BYTE = byte_literal("\x00")
# EMPTY_BYTE = byte_literal("")
# EQUAL_BYTE = byte_literal("=")
# PLUS_BYTE = byte_literal("+")
# HYPHEN_BYTE = byte_literal("-")
# FORWARD_SLASH_BYTE = byte_literal("/")
# UNDERSCORE_BYTE = byte_literal("_")
# DIGIT_ZERO_BYTE = byte_literal("0")
# HAVE_LITTLE_ENDIAN = bool(struct.pack("h", 1) == "\x01\x00")
#   def byte_ord(byte_):
#   def byte_ord(byte_):
#   def byte_literal(literal):
#   def byte_literal(literal):
#   def dict_each(func, iterable):
#   def dict_each(func, iterable):
#   def next(iterator, default=throw):
#   def generate_random_bytes(count):
#     def generate_random_bytes(count):
#       def generate_random_bytes(count):
#       def generate_random_bytes(_):
# def get_word_alignment(num, force_arch=64,
#                        _machine_word_size=MACHINE_WORD_SIZE):
#   class Throw(object):
# 
# Path: mom/builtins.py
# def byte(number):
# def bytes_leading(raw_bytes, needle=_compat.ZERO_BYTE):
# def bytes_trailing(raw_bytes, needle=_compat.ZERO_BYTE):
# def bin(number, prefix="0b"):
# def hex(number, prefix="0x"):
# def is_sequence(obj):
# def is_unicode(obj):
# def is_bytes(obj):
# def is_bytes_or_unicode(obj):
# def is_integer(obj):
# def integer_byte_length(number):
# def integer_byte_size(number):
# def integer_bit_length(number):
# def integer_bit_size(number):
# def integer_bit_count(number):
# def is_even(num):
# def is_odd(num):
# def is_positive(num):
# def is_negative(num):


# Path: mom/codec/_alt_integer.py
  import psyco
import array
import struct
from mom import _compat
from mom import builtins

  Convert a integer to bytes (base-256 representation)::

      integer_to_bytes(n:int, chunk_size:int) : string

  .. WARNING:
      Does not preserve leading zeros if you don't specify a chunk size.

  :param number:
      Integer value
  :param chunk_size:
      If optional chunk size is given and greater than zero, pad the front of
      the byte string with binary zeros so that the length is a multiple of
      ``chunk_size``. Raises an OverflowError if the chunk_size is not
      sufficient to represent the integer.
  :returns:
      Raw bytes (base-256 representation).
  :raises:
      ``OverflowError`` when block_size is given and the number takes up more
      bytes than fit into the block.
  """
  # Machine word aligned byte array based implementation.
  if number < 0:
    raise ValueError("Number must be unsigned integer: %d" % number)

  raw_bytes = EMPTY_BYTE
  if not number:
    raw_bytes = ZERO_BYTE

  # Align packing to machine word size.
  num = number

  word_bits, word_bytes, max_uint, pack_type = _compat.get_word_alignment(num)