Skip to content

Instantly share code, notes, and snippets.

@tiagob
Created March 29, 2015 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiagob/6e7c737c4c482efb7995 to your computer and use it in GitHub Desktop.
Save tiagob/6e7c737c4c482efb7995 to your computer and use it in GitHub Desktop.
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