home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.2)
-
- import binascii
- __all__ = [
- 'encode',
- 'decode',
- 'encodestring',
- 'decodestring']
- MAXLINESIZE = 76
- MAXBINSIZE = (MAXLINESIZE // 4) * 3
-
- def encode(input, output):
- while 1:
- s = input.read(MAXBINSIZE)
- if not s:
- break
-
- while len(s) < MAXBINSIZE:
- ns = input.read(MAXBINSIZE - len(s))
- if not ns:
- break
-
- s = s + ns
- line = binascii.b2a_base64(s)
- output.write(line)
-
-
- def decode(input, output):
- while 1:
- line = input.readline()
- if not line:
- break
-
- s = binascii.a2b_base64(line)
- output.write(s)
-
-
- def encodestring(s):
- pieces = []
- for i in range(0, len(s), MAXBINSIZE):
- chunk = s[i:i + MAXBINSIZE]
- pieces.append(binascii.b2a_base64(chunk))
-
- return ''.join(pieces)
-
-
- def decodestring(s):
- return binascii.a2b_base64(s)
-
-
- def test():
- import sys
- import getopt
-
- try:
- (opts, args) = getopt.getopt(sys.argv[1:], 'deut')
- except getopt.error:
- msg = None
- sys.stdout = sys.stderr
- print msg
- print "usage: %s [-d|-e|-u|-t] [file|-]\n -d, -u: decode\n -e: encode (default)\n -t: encode and decode string 'Aladdin:open sesame'" % sys.argv[0]
- sys.exit(2)
-
- func = encode
- for o, a in opts:
- if o == '-e':
- func = encode
-
- if o == '-d':
- func = decode
-
- if o == '-u':
- func = decode
-
- if o == '-t':
- test1()
- return None
-
-
- if args and args[0] != '-':
- func(open(args[0], 'rb'), sys.stdout)
- else:
- func(sys.stdin, sys.stdout)
-
-
- def test1():
- s0 = 'Aladdin:open sesame'
- s1 = encodestring(s0)
- s2 = decodestring(s1)
- print s0, `s1`, s2
-
- if __name__ == '__main__':
- test()
-
-