File: closure_ws.py

package info (click to toggle)
openlayers 2.11%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 60,144 kB
  • ctags: 10,906
  • sloc: xml: 7,435; python: 778; sh: 68; makefile: 30
file content (28 lines) | stat: -rw-r--r-- 861 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/python

import httplib, urllib, sys
import time
# Define the parameters for the POST request and encode them in
# a URL-safe format.

def minimize(code):

    params = urllib.urlencode([
        ('js_code', code),
        ('compilation_level', 'SIMPLE_OPTIMIZATIONS'),
        ('output_format', 'text'),
        ('output_info', 'compiled_code'),
      ])
    
    t = time.time()
    # 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()
    conn.close()
    if data.startswith("Error"):
        raise Exception(data)
    print "%.3f seconds to compile" % (time.time() - t) 
    return data