[bugzilla-gnome-org-extensions] Fix compatibility with Python-2.4 urlparse.urlsplit()
- From: Krzesimir Nowak <krnowak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bugzilla-gnome-org-extensions] Fix compatibility with Python-2.4 urlparse.urlsplit()
- Date: Thu, 20 Nov 2014 22:19:13 +0000 (UTC)
commit d2193bc33b24582227884e3ef087f5947de7bee2
Author: Owen W. Taylor <otaylor fishsoup net>
Date: Mon Sep 14 15:20:39 2009 -0400
Fix compatibility with Python-2.4 urlparse.urlsplit()
urlparse.urlsplit() only started returning an attributed tuple
with Python 2.5; work around that by converting the returned
tuple into a custom CompatSplitResult class.
proxy/splinter_proxy.py | 21 +++++++++++++++++++--
1 files changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/proxy/splinter_proxy.py b/proxy/splinter_proxy.py
index fbe0c6d..1bc3d50 100755
--- a/proxy/splinter_proxy.py
+++ b/proxy/splinter_proxy.py
@@ -41,6 +41,23 @@ start_time = time.time()
# Content for config.js
config_js_content = None
+# This wraps up the pure-tuple old SplitResult into an object with attributes
+# like the new version
+class CompatSplitResult:
+ def __init__(self, *args):
+ (self.scheme, self.netloc, self.path, self.query, self.fragment) = args
+ colon = self.netloc.find(':')
+ if colon >= 0:
+ self.hostname = self.netloc[0:colon]
+ self.port = self.netloc[colon + 1:]
+ else:
+ self.hostname = self.netloc
+ self.port = None
+
+def urlsplit(url):
+ tuple = urlparse.urlsplit(url)
+ return CompatSplitResult(*tuple)
+
def port_from_scheme(scheme, override):
if scheme =='http':
if override:
@@ -58,7 +75,7 @@ def port_from_scheme(scheme, override):
# Convert an URL we received from a client to all the information we'll
# need to proxy to the Bugzilla server - host, port, new path, etc.
def get_proxy_info(path):
- split = urlparse.urlsplit(current_config['bugzilla_url'])
+ split = urlsplit(current_config['bugzilla_url'])
if split.port:
portstr = ":" + str(split.port)
else:
@@ -153,7 +170,7 @@ class ProxyHandler(SimpleHTTPRequestHandler):
# Retry the request with a GET after a redirect
def do_redirect(self, location, seen_urls):
self.log_message("Redirecting to %s", location)
- split = urlparse.urlsplit(location)
+ split = urlsplit(location)
port = port_from_scheme(split.scheme, split.port)
if (split.scheme == 'http'):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]