コード例 #1
0
ファイル: tw_uuencode.py プロジェクト: dbachrach/char140
def encode(s, storage=BIT_STORAGE, alpha=ALPHABET, char_func=unichr):
  """
    Accepts any string/bytes. You can override the storage and alpha
    keywords to change to another language set and storage mechanism

    Returns a list of encoded bits.
  """
  n = s
  buf = ''
  while len(n) > 0:
    b = n[:storage]
    n = n[storage:]

    d = 11 - len(b)
    for i in range(d):
      b += '\0'

    bs = BitString(data=b)

    for i in range(8):
      v = bs.readbits(storage).uint
      buf += char_func(alpha[v])

  return buf.rstrip(char_func(alpha[0]))