home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / iria107a.lzh / script / gaogaolib.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-11-21  |  4.1 KB  |  136 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.0)
  3.  
  4. import sys
  5. import httplib
  6. import re
  7. import urlparse
  8. import string
  9. import os.path as os
  10. TRUE = 1
  11. FALSE = 0
  12. ERROR = 0
  13. SUCCESS = 1
  14. TERMINATE = 2
  15. IGNORE = 3
  16. TERMINATE_SUCCESS = 4
  17. EXIT = 5
  18. SUCCESS_EXIT = 6
  19.  
  20. def parse_url(url, protocol = ''):
  21.     '''\x95\xd4\x92l\x82\xcdurl\x8f\xee\x95\xf1\x82\xcc\x93\xfc\x82\xc1\x82\xbd\x8e\xab\x8f\x91 protocol://user:pass@host:port/path?query'''
  22.     u = {
  23.         'protocol': 'http',
  24.         'host': '',
  25.         'port': '',
  26.         'user': '',
  27.         'password': '',
  28.         'path': '/',
  29.         'dir': '/',
  30.         'filename': 'index.html',
  31.         'query': '' }
  32.     u['url'] = url
  33.     tmp = url
  34.     protocol = string.lower(protocol)
  35.     idx = string.find(tmp, '://')
  36.     if idx == -1:
  37.         u['protocol'] = protocol
  38.     else:
  39.         u['protocol'] = tmp[0:idx]
  40.         tmp = tmp[idx + 3:]
  41.     idx = string.find(tmp, '/')
  42.     if idx == -1:
  43.         host = tmp[0:]
  44.         tmp = '/'
  45.     else:
  46.         host = tmp[0:idx]
  47.         tmp = tmp[idx:]
  48.     u['path'] = tmp
  49.     u['dir'] = os.path.dirname(tmp)
  50.     u['filename'] = os.path.basename(tmp)
  51.     idx = string.find(u['filename'], '?')
  52.     if idx > -1:
  53.         u['query'] = u['filename'][idx + 1:]
  54.     
  55.     idx = string.find(host, '@')
  56.     if idx == -1:
  57.         idx = string.find(host, ':')
  58.         if idx == -1:
  59.             u['host'] = host
  60.         else:
  61.             u['host'] = host[0:idx]
  62.             u['port'] = host[idx + 1:]
  63.     else:
  64.         tmp2 = host[0:idx]
  65.         tmp3 = host[idx + 1:]
  66.         idx = string.find(tmp2, ':')
  67.         if idx > -1:
  68.             u['user'] = tmp2[0:idx]
  69.             u['password'] = tmp2[idx + 1:]
  70.         
  71.         idx = string.find(tmp3, ':')
  72.         if idx == -1:
  73.             u['host'] = tmp3
  74.         else:
  75.             u['host'] = tmp3[0:idx]
  76.             u['port'] = tmp3[idx + 1:]
  77.     return u
  78.  
  79.  
  80. def extract_url(url, proxy = ''):
  81.     '''\x95\xd4\x92l\x82\xcd host,port,path\x82\xcc\x83^\x83v\x83\x8b'''
  82.     url_info = parse_url(url, 'http')
  83.     if proxy:
  84.         if url_info['port']:
  85.             path = url_info['protocol'] + '://' + url_info['host'] + ':' + url_info['port'] + url_info['path']
  86.         else:
  87.             path = url_info['protocol'] + '://' + url_info['host'] + url_info['path']
  88.         proxy_info = parse_url(proxy)
  89.         host = proxy_info['host']
  90.         
  91.         try:
  92.             port = string.atoi(proxy_info['port'])
  93.         except:
  94.             port = 8080
  95.  
  96.     else:
  97.         path = url_info['path']
  98.         host = url_info['host']
  99.         
  100.         try:
  101.             port = string.atoi(url_info['port'])
  102.         except:
  103.             port = 80
  104.  
  105.     return (host, port, path)
  106.  
  107.  
  108. def restore_webjump(url):
  109.     '''\x95\xd4\x92l\x82\xcd webjump\x82\xcc\x8c\xb3\x82\xccUrl
  110.   http://freehosting1.at.webjump.com/0919a3cc8/ac/acount-webjump/filename.jpg'''
  111.     m = re.search('freehosting[0-9]*\\.at\\.webjump\\.com', url, re.IGNORECASE)
  112.     if m:
  113.         m = re.search('/[^/]+-webjump/', url, re.IGNORECASE)
  114.         if m:
  115.             acount = url[m.start(0) + 1:m.end(0) - 9]
  116.             path = url[m.end(0) - 1:]
  117.             return 'http://' + acount + '.webjump.com' + path
  118.         
  119.     
  120.     return url
  121.  
  122.  
  123. def restore_homestead(url):
  124.     '''\x95\xd4\x92l\x82\xcdhomestead\x82\xcc\x8c\xb3\x82\xccurl
  125.   http://freeload.homestead.com/_ksi0701961600708147/acount/files/filename'''
  126.     m = re.search('freeload.*\\.homestead\\.com/', url, re.IGNORECASE)
  127.     if m:
  128.         path = url[m.end(0) - 1:]
  129.         m = re.search('/[^/]*/files/.*', path, re.IGNORECASE)
  130.         if m:
  131.             return 'http://www.homestead.com' + path[m.start(0):]
  132.         
  133.     
  134.     return url
  135.  
  136.