[bugzilla-gnome-org-extensions] Get rid of ternary usage for Python-2.4 compat
- From: Krzesimir Nowak <krnowak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bugzilla-gnome-org-extensions] Get rid of ternary usage for Python-2.4 compat
- Date: Thu, 20 Nov 2014 22:19:08 +0000 (UTC)
commit cd29486fd8ebf76719014abbe9957cfde42903c8
Author: Owen W. Taylor <otaylor fishsoup net>
Date: Mon Sep 14 14:39:30 2009 -0400
Get rid of ternary usage for Python-2.4 compat
Don't use 'if B then X else Y' so that we work with Python-2.4
proxy/splinter_proxy.py | 39 +++++++++++++++++++++------------------
1 files changed, 21 insertions(+), 18 deletions(-)
---
diff --git a/proxy/splinter_proxy.py b/proxy/splinter_proxy.py
index 5d3e7ce..fbe0c6d 100755
--- a/proxy/splinter_proxy.py
+++ b/proxy/splinter_proxy.py
@@ -41,23 +41,34 @@ start_time = time.time()
# Content for config.js
config_js_content = None
+def port_from_scheme(scheme, override):
+ if scheme =='http':
+ if override:
+ return override
+ else:
+ return 80
+ elif scheme =='https':
+ if override:
+ return override
+ else:
+ return 443
+ else:
+ raise RuntimeError("Bad scheme %s" % scheme)
+
# 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'])
- port = split.port
- portstr = ":" + str(port) if port else ""
- if split.scheme =='http':
- port = port if port else 80
- elif split.scheme =='https':
- port = port if port else 443
+ if split.port:
+ portstr = ":" + str(split.port)
else:
- raise RuntimeError("Bad scheme %s" % split.scheme)
+ portstr = ""
+ port = port_from_scheme(split.scheme, split.port)
url = "%s://%s%s%s" % (split.scheme, split.hostname,
portstr, split.path + path)
- return split.scheme, split.hostname, split.port, split.path + path, url
+ return split.scheme, split.hostname, port, split.path + path, url
# Without the mixin, HTTPServer is single-connection-at-a-time
class ProxyServer(HTTPServer, ForkingMixIn):
@@ -143,21 +154,13 @@ class ProxyHandler(SimpleHTTPRequestHandler):
def do_redirect(self, location, seen_urls):
self.log_message("Redirecting to %s", location)
split = urlparse.urlsplit(location)
+ port = port_from_scheme(split.scheme, split.port)
+
if (split.scheme == 'http'):
connection = httplib.HTTPConnection(split.hostname, split.port)
else:
connection = httplib.HTTPSConnection(split.hostname, split.port)
- split = urlparse.urlsplit(location)
- port = split.port
- portstr = ":" + str(port) if port else ""
- if split.scheme =='http':
- port = port if port else 80
- elif split.scheme =='https':
- port = port if port else 443
- else:
- raise RuntimeError("Bad scheme %s" % split.scheme)
-
relative = urlparse.urlunsplit((None, None, split.path, split.query, split.fragment))
connection.putrequest('GET', relative)
for header, value in self.headers.items():
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]