[code.view]

[top] / python / PyMOTW / base64 / base64_b64encode.py

     #!/usr/bin/env python
     # encoding: utf-8
     #
     # Copyright (c) 2008 Doug Hellmann All rights reserved.
     #
     """
     """
     
     __version__ = "$Id$"
     #end_pymotw_header
     
     import base64
     
     # Load this source file and strip the header.
     initial_data = open(__file__, 'rt').read().split('#end_pymotw_header')[1]
     
     encoded_data = base64.b64encode(initial_data)
     
     num_initial = len(initial_data)
     padding = { 0:0, 1:2, 2:1 }[num_initial % 3]
     
     print '%d bytes before encoding' % num_initial
     print 'Expect %d padding bytes' % padding
     print '%d bytes after encoding' % len(encoded_data)
     print
     #print encoded_data
     for i in xrange((len(encoded_data)/40)+1):
         print encoded_data[i*40:(i+1)*40]

[top] / python / PyMOTW / base64 / base64_b64encode.py

contact | logmethods.com