Created
March 29, 2015 03:23
-
-
Save tiagob/6e7c737c4c482efb7995 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import httplib | |
import urllib | |
def closure_js_api(_in, out, **kwargs): | |
# https://developers.google.com/closure/compiler/docs/api-tutorial1 | |
# Define the parameters for the POST request and encode them in a | |
# URL-safe format. | |
params = urllib.urlencode([ | |
('js_code', _in.read().encode('utf-8')), | |
('compilation_level', 'SIMPLE_OPTIMIZATIONS'), | |
('output_format', 'text'), | |
('output_info', 'compiled_code'), | |
]) | |
# Always use the following value for the Content-type header. | |
headers = {'Content-type': 'application/x-www-form-urlencoded'} | |
conn = httplib.HTTPConnection('closure-compiler.appspot.com') | |
conn.request('POST', '/compile', params, headers) | |
response = conn.getresponse() | |
data = response.read() | |
out.write(data) | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment