Ignore:
Timestamp:
Nov 9, 2017 6:41:54 AM (6 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
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 01:13:05)
git-committer:
Piotr Rozyczko <rozyczko@…> (11/09/17 06:41:54)
Message:

Initial changes to make SasView? run with python3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Utilities/ConnectionProxy.py

    rdc5ef15 rb3e8629  
    11#!/usr/bin/env python 
    22# -*- coding: utf-8 -*- 
    3 import urllib2 
     3import urllib.request, urllib.error, urllib.parse 
    44import sys 
    55import json 
     
    3333        if sys.platform == 'win32': 
    3434            try: 
    35                 import _winreg as winreg  # used from python 2.0-2.6 
     35                import winreg as winreg  # used from python 2.0-2.6 
    3636            except: 
    3737                import winreg  # used from python 2.7 onwards 
     
    4545                this_name, this_val, this_type = winreg.EnumValue(net, i) 
    4646                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: 
    4848                pac_files.append(subkeys['AutoConfigURL']) 
    4949        elif sys.platform == 'darwin': 
     
    5353            networks = sys_prefs['NetworkServices'] 
    5454            # loop through each possible network (e.g. Ethernet, Airport...) 
    55             for network in networks.items(): 
     55            for network in list(networks.items()): 
    5656                # the first part is a long identifier 
    5757                net_key, network = network 
    58                 if 'ProxyAutoConfigURLString' in network['Proxies'].keys(): 
     58                if 'ProxyAutoConfigURLString' in list(network['Proxies'].keys()): 
    5959                    pac_files.append( 
    6060                        network['Proxies']['ProxyAutoConfigURLString']) 
     
    7373            logging.debug('Trying pac file (%s)...' % this_pac_url) 
    7474            try: 
    75                 response = urllib2.urlopen( 
     75                response = urllib.request.urlopen( 
    7676                    this_pac_url, timeout=self.timeout) 
    7777                logging.debug('Succeeded (%s)...' % this_pac_url) 
     
    101101            # information is retrieved from the OS X System Configuration 
    102102            # Framework. 
    103             proxy = urllib2.ProxyHandler() 
     103            proxy = urllib.request.ProxyHandler() 
    104104        else: 
    105105            # If proxies is given, it must be a dictionary mapping protocol names to 
    106106            # URLs of proxies. 
    107             proxy = urllib2.ProxyHandler(proxy_dic) 
    108         opener = urllib2.build_opener(proxy) 
    109         urllib2.install_opener(opener) 
     107            proxy = urllib.request.ProxyHandler(proxy_dic) 
     108        opener = urllib.request.build_opener(proxy) 
     109        urllib.request.install_opener(opener) 
    110110 
    111111    def connect(self): 
     
    114114        @return: response object from urllib2.urlopen 
    115115        ''' 
    116         req = urllib2.Request(self.url) 
     116        req = urllib.request.Request(self.url) 
    117117        response = None 
    118118        try: 
    119119            logging.debug("Trying Direct connection to %s..."%self.url) 
    120             response = urllib2.urlopen(req, timeout=self.timeout) 
    121         except Exception, e: 
     120            response = urllib.request.urlopen(req, timeout=self.timeout) 
     121        except Exception as e: 
    122122            logging.debug("Failed!") 
    123123            logging.debug(e) 
     
    125125                logging.debug("Trying to use system proxy if it exists...") 
    126126                self._set_proxy() 
    127                 response = urllib2.urlopen(req, timeout=self.timeout) 
    128             except Exception, e: 
     127                response = urllib.request.urlopen(req, timeout=self.timeout) 
     128            except Exception as e: 
    129129                logging.debug("Failed!") 
    130130                logging.debug(e) 
     
    135135                        logging.debug("Trying to use the proxy %s found in proxy.pac configuration"%proxy) 
    136136                        self._set_proxy(proxy) 
    137                         response = urllib2.urlopen(req, timeout=self.timeout) 
    138                     except Exception, e: 
     137                        response = urllib.request.urlopen(req, timeout=self.timeout) 
     138                    except Exception as e: 
    139139                        logging.debug("Failed!") 
    140140                        logging.debug(e) 
     
    151151    response = c.connect() 
    152152    if response is not None: 
    153         print 50 * '-' 
     153        print(50 * '-') 
    154154        content = json.loads(response.read().strip()) 
    155155        pprint(content) 
Note: See TracChangeset for help on using the changeset viewer.