@@ -2577,6 +2577,7 @@ def _proxy_bypass_macosx_sysconf(host, proxy_settings):
25772577    } 
25782578    """ 
25792579    from  fnmatch  import  fnmatch 
2580+     from  ipaddress  import  AddressValueError , IPv4Address 
25802581
25812582    hostonly , port  =  _splitport (host )
25822583
@@ -2593,20 +2594,17 @@ def ip2num(ipAddr):
25932594            return  True 
25942595
25952596    hostIP  =  None 
2597+     try :
2598+         hostIP  =  int (IPv4Address (hostonly ))
2599+     except  AddressValueError :
2600+         pass 
25962601
25972602    for  value  in  proxy_settings .get ('exceptions' , ()):
25982603        # Items in the list are strings like these: *.local, 169.254/16 
25992604        if  not  value : continue 
26002605
26012606        m  =  re .match (r"(\d+(?:\.\d+)*)(/\d+)?" , value )
2602-         if  m  is  not None :
2603-             if  hostIP  is  None :
2604-                 try :
2605-                     hostIP  =  socket .gethostbyname (hostonly )
2606-                     hostIP  =  ip2num (hostIP )
2607-                 except  OSError :
2608-                     continue 
2609- 
2607+         if  m  is  not None  and  hostIP  is  not None :
26102608            base  =  ip2num (m .group (1 ))
26112609            mask  =  m .group (2 )
26122610            if  mask  is  None :
@@ -2629,6 +2627,31 @@ def ip2num(ipAddr):
26292627    return  False 
26302628
26312629
2630+ # Same as _proxy_bypass_macosx_sysconf, testable on all platforms 
2631+ def  _proxy_bypass_winreg_override (host , override ):
2632+     """Return True if the host should bypass the proxy server. 
2633+ 
2634+     The proxy override list is obtained from the Windows 
2635+     Internet settings proxy override registry value. 
2636+ 
2637+     An example of a proxy override value is: 
2638+     "www.example.com;*.example.net; 192.168.0.1" 
2639+     """ 
2640+     from  fnmatch  import  fnmatch 
2641+ 
2642+     host , _  =  _splitport (host )
2643+     proxy_override  =  override .split (';' )
2644+     for  test  in  proxy_override :
2645+         test  =  test .strip ()
2646+         # "<local>" should bypass the proxy server for all intranet addresses 
2647+         if  test  ==  '<local>' :
2648+             if  '.'  not  in host :
2649+                 return  True 
2650+         elif  fnmatch (host , test ):
2651+             return  True 
2652+     return  False 
2653+ 
2654+ 
26322655if  sys .platform  ==  'darwin' :
26332656    from  _scproxy  import  _get_proxy_settings , _get_proxies 
26342657
@@ -2727,7 +2750,7 @@ def proxy_bypass_registry(host):
27272750            import  winreg 
27282751        except  ImportError :
27292752            # Std modules, so should be around - but you never know! 
2730-             return  0 
2753+             return  False 
27312754        try :
27322755            internetSettings  =  winreg .OpenKey (winreg .HKEY_CURRENT_USER ,
27332756                r'Software\Microsoft\Windows\CurrentVersion\Internet Settings' )
@@ -2737,40 +2760,10 @@ def proxy_bypass_registry(host):
27372760                                                     'ProxyOverride' )[0 ])
27382761            # ^^^^ Returned as Unicode but problems if not converted to ASCII 
27392762        except  OSError :
2740-             return  0 
2763+             return  False 
27412764        if  not  proxyEnable  or  not  proxyOverride :
2742-             return  0 
2743-         # try to make a host list from name and IP address. 
2744-         rawHost , port  =  _splitport (host )
2745-         host  =  [rawHost ]
2746-         try :
2747-             addr  =  socket .gethostbyname (rawHost )
2748-             if  addr  !=  rawHost :
2749-                 host .append (addr )
2750-         except  OSError :
2751-             pass 
2752-         try :
2753-             fqdn  =  socket .getfqdn (rawHost )
2754-             if  fqdn  !=  rawHost :
2755-                 host .append (fqdn )
2756-         except  OSError :
2757-             pass 
2758-         # make a check value list from the registry entry: replace the 
2759-         # '<local>' string by the localhost entry and the corresponding 
2760-         # canonical entry. 
2761-         proxyOverride  =  proxyOverride .split (';' )
2762-         # now check if we match one of the registry values. 
2763-         for  test  in  proxyOverride :
2764-             if  test  ==  '<local>' :
2765-                 if  '.'  not  in rawHost :
2766-                     return  1 
2767-             test  =  test .replace ("." , r"\." )     # mask dots 
2768-             test  =  test .replace ("*" , r".*" )     # change glob sequence 
2769-             test  =  test .replace ("?" , r"." )      # change glob char 
2770-             for  val  in  host :
2771-                 if  re .match (test , val , re .I ):
2772-                     return  1 
2773-         return  0 
2765+             return  False 
2766+         return  _proxy_bypass_winreg_override (host , proxyOverride )
27742767
27752768    def  proxy_bypass (host ):
27762769        """Return True, if host should be bypassed. 
0 commit comments