Changeset 6822 for anuga_core/source/anuga/utilities/system_tools.py
- Timestamp:
- Apr 16, 2009, 5:00:43 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/utilities/system_tools.py
r6687 r6822 296 296 # @param auth Auth tuple (httpproxy, proxyuser, proxypass). 297 297 # @param blocksize Read file in this block size. 298 # @return 'auth' tuple for subsequent calls, if successful .298 # @return 'auth' tuple for subsequent calls, if successful, else False. 299 299 # @note If 'auth' not supplied, will prompt user. 300 300 # @note Will try using environment variable HTTP_PROXY for proxy server. … … 302 302 # @note Will try using environment variable PROXY_PASSWORD for proxy password. 303 303 def get_web_file(file_url, file_name, auth=None, blocksize=1024*1024): 304 '''Get a file from the web .304 '''Get a file from the web (HTTP). 305 305 306 306 file_url: The URL of the file to get … … 319 319 # Simple fetch, if fails, check for proxy error 320 320 try: 321 urllib.urlretrieve(file_url, file_name) # original 'line of code'321 urllib.urlretrieve(file_url, file_name) 322 322 return None # no proxy, no auth required 323 323 except IOError, e: 324 if e[1] != 407: 325 raise # raise error if *not* proxy auth error 324 if e[1] == 407: # proxy error 325 pass 326 elif e[1][0] == 113: # no route to host 327 print 'No route to host for %s' % file_url 328 return False # return False 329 else: 330 print 'Unknown connection error to %s' % file_url 331 return False 326 332 327 333 # We get here if there was a proxy error, get file through the proxy … … 343 349 # Get auth info from user if still not supplied 344 350 if httpproxy is None or proxyuser is None or proxypass is None: 345 print '-'*80 346 print ('You need to supply proxy authentication information. ' 347 'Use environment variables\n' 348 'HTTP_PROXY, PROXY_USERNAME and PROXY_PASSWORD to bypass ' 349 'entry here:') 351 print '-'*52 352 print ('You need to supply proxy authentication information.') 350 353 if httpproxy is None: 351 httpproxy = raw_input(' proxy server: ') 354 httpproxy = raw_input(' proxy server: ') 355 else: 356 print ' HTTP proxy was supplied: %s' % httpproxy 352 357 if proxyuser is None: 353 proxyuser = raw_input('proxy username: ') 358 proxyuser = raw_input(' proxy username: ') 359 else: 360 print 'HTTP proxy username was supplied: %s' % proxyuser 354 361 if proxypass is None: 355 proxypass = getpass.getpass('proxy password: ') 356 print '-'*80 362 proxypass = getpass.getpass(' proxy password: ') 363 else: 364 print 'HTTP proxy password was supplied: %s' % '*'*len(proxyuser) 365 print '-'*52 357 366 358 367 # the proxy URL cannot start with 'http://', we add that later
Note: See TracChangeset
for help on using the changeset viewer.