home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Lib / urllib.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-06-23  |  38.9 KB  |  109 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4. import string
  5. import socket
  6. import os
  7. import sys
  8. __version__ = '1.10'
  9. MAXFTPCACHE = 10
  10. if os.name == 'mac':
  11.     pathname2url
  12. elif os.name == 'nt':
  13.     pathname2url
  14.  
  15.  
  16. def test1():
  17.     import time
  18.     s = ''
  19.     for i in range(256):
  20.         s = s + chr(i)
  21.     
  22.     s = s * 4
  23.     t0 = time.time()
  24.     qs = quote(s)
  25.     uqs = unquote(qs)
  26.     t1 = time.time()
  27.     if uqs != s:
  28.         print 'Wrong!'
  29.     
  30.     print `s`
  31.     print `qs`
  32.     print `uqs`
  33.     print round(t1 - t0, 3), 'sec'
  34.  
  35.  
  36. def reporthook(blocknum, blocksize, totalsize):
  37.     print 'Block number: %d, Block size: %d, Total size: %d' % (blocknum, blocksize, totalsize)
  38.  
  39.  
  40. def test(args = []):
  41.     if not args:
  42.         args = [
  43.             '/etc/passwd',
  44.             'file:/etc/passwd',
  45.             'file://localhost/etc/passwd',
  46.             'ftp://ftp.python.org/etc/passwd',
  47.             'http://www.python.org/index.html']
  48.     
  49.     
  50.     try:
  51.         for url in args:
  52.             print '-' * 10, url, '-' * 10
  53.             (fn, h) = urlretrieve(url, None, reporthook)
  54.             print fn, h
  55.             if h:
  56.                 print '======'
  57.                 for k in h.keys():
  58.                     print k + ':', h[k]
  59.                 
  60.                 print '======'
  61.             
  62.             fp = open(fn, 'rb')
  63.             data = fp.read()
  64.             del fp
  65.             if '\r' in data:
  66.                 table = string.maketrans('', '')
  67.                 data = string.translate(data, table, '\r')
  68.             
  69.             print data
  70.             (fn, h) = (None, None)
  71.         
  72.         print '-' * 40
  73.     finally:
  74.         urlcleanup()
  75.  
  76.  
  77.  
  78. def main():
  79.     import getopt
  80.     import sys
  81.     
  82.     try:
  83.         (opts, args) = getopt.getopt(sys.argv[1:], 'th')
  84.     except getopt.error:
  85.         msg = None
  86.         print msg
  87.         print 'Use -h for help'
  88.         return None
  89.  
  90.     t = 0
  91.     for o, a in opts:
  92.         pass
  93.     
  94.     if t:
  95.         if t > 1:
  96.             test1()
  97.         
  98.         test(args)
  99.     elif not args:
  100.         print 'Use -h for help'
  101.     
  102.     for url in args:
  103.         print urlopen(url).read(),
  104.     
  105.  
  106. if __name__ == '__main__':
  107.     main()
  108.  
  109.