Ignore:
Timestamp:
18/02/09 11:33:18 (11 years ago)
Author:
cbyrom
Message:

Move generic 'httpify' method to utilities + adjust utilities method
to retrive default proxy to cope with standard formatting + set this
up on each call to urlopen - since different urls may use different
proxies + tidyup and extend test suite.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ndgCommon/trunk/ndg/common/src/lib/utilities.py

    r4977 r4991  
    2323esc_chars = {'\xb0':'°','°':'°'} 
    2424     
    25 URLIB2_INITIALISED = False 
    26  
    2725        
    2826class edict(dict): 
     
    5553 
    5654 
     55def httpify(url): 
     56    ''' 
     57    Ensure a url has an http prefix 
     58    @param url: url to check and, if required, to add 'http' prefix to 
     59    @return url - with 'http' prefix added, if required 
     60    ''' 
     61    if not url.startswith('http'): 
     62        url = 'http://' + url 
     63    return url 
     64 
     65 
    5766def loadConfigDetails(configFilename, dbName = None): 
    5867    ''' 
     
    106115        noProxyHosts = os.getenv(NO_PROXY_KEY) 
    107116        if noProxyHosts: 
    108             for host in noProxyHosts.split(';'): 
     117            for host in noProxyHosts.split(','): 
    109118                if url.lower().find(host.lower().strip()) > -1: 
    110119                    logging.debug("Proxies disabled for communication with uri machine ('%s')" 
     
    150159    ''' 
    151160    logging.debug("Checking validity of uri, '%s'" %uri) 
    152      
    153     if not URLIB2_INITIALISED: 
    154         # set the socket timeout period 
    155         socket.setdefaulttimeout(120) 
    156      
    157         proxy = getDefaultProxy(uri) 
    158         proxy_support = urllib2.ProxyHandler(proxy) 
    159      
    160         # build a new opener that adds authentication and caching FTP handlers 
    161         opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler) 
    162      
    163         # install it 
    164         urllib2.install_opener(opener) 
     161 
     162    # set the socket timeout period 
     163    socket.setdefaulttimeout(120) 
     164 
     165    proxy = getDefaultProxy(uri) 
     166    proxy_support = urllib2.ProxyHandler(proxy) 
     167 
     168    # build a new opener that adds authentication and caching FTP handlers 
     169    opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler) 
     170 
     171    # install it 
     172    urllib2.install_opener(opener) 
    165173     
    166174    try: 
Note: See TracChangeset for help on using the changeset viewer.