From 7b1d7ff9ba988d2458b0905a0c429c0e07999d2d Mon Sep 17 00:00:00 2001 From: manugarg Date: Mon, 21 Jan 2008 18:44:22 +0000 Subject: [PATCH] Fix a small bug in "host extraction from url" part in python module. --- pymod/__init__.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pymod/__init__.py b/pymod/__init__.py index ce36cf05..00eefbda 100644 --- a/pymod/__init__.py +++ b/pymod/__init__.py @@ -52,11 +52,15 @@ def find_proxy(url, host=None): defined, it's extracted from url. """ if host is None: - matches = url_regex.findall(url)[0] - if len(matches) is not 2: + m = url_regex.match(url) + if not m: + print 'URL: %s is not a valid URL' % url + return None + if len(m.groups()) is 2: + host = m.groups()[1] + else: print 'URL: %s is not a valid URL' % url return None - host = matches[1] return _pacparser.find_proxy(url, host) def cleanup(): @@ -77,11 +81,15 @@ def just_find_proxy(pacfile, url, host=None): print 'PAC file: %s doesn\'t exist' % pacfile return None if host is None: - matches = url_regex.findall(url)[0] - if len(matches) is not 2: + m = url_regex.match(url) + if not m: + print 'URL: %s is not a valid URL' % url + return None + if len(m.groups()) is 2: + host = m.groups()[1] + else: print 'URL: %s is not a valid URL' % url return None - host = matches[1] init() parse_pac(pacfile) proxy = find_proxy(url,host)