Honor 'http_proxy' environment variable

'repo upload' makes http request using urllib2 python library.
Unfortunately this library does not work (by default) in case
if the user behind a proxy.

This change adds proxy handler in case if 'http_proxy' environment
variable is set.

Change-Id: Ic4176ad733fc21bd5b59661b3eacc2f0a7c3c1ff
This commit is contained in:
Anatol Pomozov 2011-07-08 13:52:11 -07:00 committed by Shawn O. Pearce
parent 49cd59bc86
commit a101f1c167

View File

@ -563,6 +563,12 @@ class Remote(object):
self._review_port = info[2] self._review_port = info[2]
else: else:
try: try:
if 'http_proxy' in os.environ:
proxy_url = os.environ['http_proxy']
proxy_support = urllib2.ProxyHandler({"http" : proxy_url, "https" : proxy_url})
opener = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener)
info = urlopen(u).read() info = urlopen(u).read()
if info == 'NOT_AVAILABLE': if info == 'NOT_AVAILABLE':
raise UploadError('%s: SSH disabled' % self.review) raise UploadError('%s: SSH disabled' % self.review)