Changeset b3e8629 in sasview for src/sas/qtgui/Utilities/ConnectionProxy.py
- Timestamp:
- Nov 9, 2017 8:41:54 AM (7 years ago)
- Branches:
- ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- cee5c78
- Parents:
- 749b715
- git-author:
- Piotr Rozyczko <rozyczko@…> (10/26/17 03:13:05)
- git-committer:
- Piotr Rozyczko <rozyczko@…> (11/09/17 08:41:54)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Utilities/ConnectionProxy.py
rdc5ef15 rb3e8629 1 1 #!/usr/bin/env python 2 2 # -*- coding: utf-8 -*- 3 import urllib 23 import urllib.request, urllib.error, urllib.parse 4 4 import sys 5 5 import json … … 33 33 if sys.platform == 'win32': 34 34 try: 35 import _winreg as winreg # used from python 2.0-2.635 import winreg as winreg # used from python 2.0-2.6 36 36 except: 37 37 import winreg # used from python 2.7 onwards … … 45 45 this_name, this_val, this_type = winreg.EnumValue(net, i) 46 46 subkeys[this_name] = this_val 47 if 'AutoConfigURL' in subkeys.keys() and len(subkeys['AutoConfigURL']) > 0:47 if 'AutoConfigURL' in list(subkeys.keys()) and len(subkeys['AutoConfigURL']) > 0: 48 48 pac_files.append(subkeys['AutoConfigURL']) 49 49 elif sys.platform == 'darwin': … … 53 53 networks = sys_prefs['NetworkServices'] 54 54 # loop through each possible network (e.g. Ethernet, Airport...) 55 for network in networks.items():55 for network in list(networks.items()): 56 56 # the first part is a long identifier 57 57 net_key, network = network 58 if 'ProxyAutoConfigURLString' in network['Proxies'].keys():58 if 'ProxyAutoConfigURLString' in list(network['Proxies'].keys()): 59 59 pac_files.append( 60 60 network['Proxies']['ProxyAutoConfigURLString']) … … 73 73 logging.debug('Trying pac file (%s)...' % this_pac_url) 74 74 try: 75 response = urllib 2.urlopen(75 response = urllib.request.urlopen( 76 76 this_pac_url, timeout=self.timeout) 77 77 logging.debug('Succeeded (%s)...' % this_pac_url) … … 101 101 # information is retrieved from the OS X System Configuration 102 102 # Framework. 103 proxy = urllib 2.ProxyHandler()103 proxy = urllib.request.ProxyHandler() 104 104 else: 105 105 # If proxies is given, it must be a dictionary mapping protocol names to 106 106 # URLs of proxies. 107 proxy = urllib 2.ProxyHandler(proxy_dic)108 opener = urllib 2.build_opener(proxy)109 urllib 2.install_opener(opener)107 proxy = urllib.request.ProxyHandler(proxy_dic) 108 opener = urllib.request.build_opener(proxy) 109 urllib.request.install_opener(opener) 110 110 111 111 def connect(self): … … 114 114 @return: response object from urllib2.urlopen 115 115 ''' 116 req = urllib 2.Request(self.url)116 req = urllib.request.Request(self.url) 117 117 response = None 118 118 try: 119 119 logging.debug("Trying Direct connection to %s..."%self.url) 120 response = urllib 2.urlopen(req, timeout=self.timeout)121 except Exception ,e:120 response = urllib.request.urlopen(req, timeout=self.timeout) 121 except Exception as e: 122 122 logging.debug("Failed!") 123 123 logging.debug(e) … … 125 125 logging.debug("Trying to use system proxy if it exists...") 126 126 self._set_proxy() 127 response = urllib 2.urlopen(req, timeout=self.timeout)128 except Exception ,e:127 response = urllib.request.urlopen(req, timeout=self.timeout) 128 except Exception as e: 129 129 logging.debug("Failed!") 130 130 logging.debug(e) … … 135 135 logging.debug("Trying to use the proxy %s found in proxy.pac configuration"%proxy) 136 136 self._set_proxy(proxy) 137 response = urllib 2.urlopen(req, timeout=self.timeout)138 except Exception ,e:137 response = urllib.request.urlopen(req, timeout=self.timeout) 138 except Exception as e: 139 139 logging.debug("Failed!") 140 140 logging.debug(e) … … 151 151 response = c.connect() 152 152 if response is not None: 153 print 50 * '-'153 print(50 * '-') 154 154 content = json.loads(response.read().strip()) 155 155 pprint(content)
Note: See TracChangeset
for help on using the changeset viewer.