From caa3d532944ace6ed0c6eec9b14e24500ece878d Mon Sep 17 00:00:00 2001 From: Patrick <0x00111111@gmail.com> Date: Wed, 18 May 2016 14:22:00 +0800 Subject: [PATCH] proxy option for build.py --- build.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/build.py b/build.py index 52701d8d9..800812fb3 100755 --- a/build.py +++ b/build.py @@ -43,6 +43,16 @@ if sys.version_info[0] != 2: import errno, glob, httplib, json, os, re, subprocess, threading, urllib +import getopt +import requests +opts , args = getopt.getopt(sys.argv[1:], "hp:") +proxy_url = False +for op, value in opts: + if op == '-h': + print('-p Compile via , example: python build.py -p 127.0.0.1:8787') + sys.exit() + elif op == '-p': + proxy_url = value def import_path(fullpath): """Import a file with full path specification. @@ -263,11 +273,16 @@ class Gen_compressed(threading.Thread): def do_compile(self, params, target_filename, filenames, remove): # Send the request to Google. headers = {"Content-type": "application/x-www-form-urlencoded"} - conn = httplib.HTTPConnection("closure-compiler.appspot.com") - conn.request("POST", "/compile", urllib.urlencode(params), headers) - response = conn.getresponse() - json_str = response.read() - conn.close() + + json_str='' + if proxy_url: + json_str=requests.post("http://closure-compiler.appspot.com/compile",data=params,headers=headers,proxies={"http":proxy_url,"https":proxy_url},timeout=100).content + else: + conn = httplib.HTTPConnection("closure-compiler.appspot.com") + conn.request("POST", "/compile", urllib.urlencode(params), headers) + response = conn.getresponse() + json_str = response.read() + conn.close() # Parse the JSON response. json_data = json.loads(json_str)