3 # Script to provide a wrapper around the ShrinkSafe "web service"
4 # <http://shrinksafe.dojotoolkit.org/>
8 # We use this script for two reasons:
10 # * This avoids having to install and configure Java and the standalone
13 # * The current ShrinkSafe standalone utility was broken when we last
22 URL_SHRINK_SAFE = "http://shrinksafe.dojotoolkit.org/shrinksafe.php"
24 # This would normally be dynamically generated:
25 BOUNDARY_MARKER = "---------------------------72288400411964641492083565382"
27 if __name__ == "__main__":
28 ## Grab the source code
30 sourceFilename = sys.argv[1]
32 print "Usage: %s (<source filename>|-)" % sys.argv[0]
35 if sourceFilename == "-":
36 sourceCode = sys.stdin.read()
37 sourceFilename = "stdin.js"
39 sourceCode = open(sourceFilename).read()
41 ## Create the request replicating posting of the form from the web page
42 request = urllib2.Request(url=URL_SHRINK_SAFE)
43 request.add_header("Content-Type",
44 "multipart/form-data; boundary=%s" % BOUNDARY_MARKER)
47 Content-Disposition: form-data; name="shrinkfile[]"; filename="%s"
48 Content-Type: application/x-javascript
51 """ % (BOUNDARY_MARKER, sourceFilename, sourceCode))
54 print urllib2.urlopen(request).read(),