closure_ws.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 import httplib, urllib, sys
00004 import time
00005 # Define the parameters for the POST request and encode them in
00006 # a URL-safe format.
00007 
00008 def minimize(code):
00009 
00010     params = urllib.urlencode([
00011         ('js_code', code),
00012         ('compilation_level', 'SIMPLE_OPTIMIZATIONS'),
00013         ('output_format', 'text'),
00014         ('output_info', 'compiled_code'),
00015       ])
00016     
00017     t = time.time()
00018     # Always use the following value for the Content-type header.
00019     headers = { "Content-type": "application/x-www-form-urlencoded" }
00020     conn = httplib.HTTPConnection('closure-compiler.appspot.com')
00021     conn.request('POST', '/compile', params, headers)
00022     response = conn.getresponse()
00023     data = response.read()
00024     conn.close()
00025     if data.startswith("Error"):
00026         raise Exception(data)
00027     print "%.3f seconds to compile" % (time.time() - t) 
00028     return data


websocket_gui
Author(s): Benoit Lescot and Stéphane Magnenat
autogenerated on Sat Dec 28 2013 17:46:48