shrinksafe.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Script to provide a wrapper around the ShrinkSafe "web service"
00004 # <http://shrinksafe.dojotoolkit.org/>
00005 #
00006 
00007 #
00008 # We use this script for two reasons:
00009 #
00010 #  * This avoids having to install and configure Java and the standalone
00011 #    ShrinkSafe utility.
00012 #
00013 #  * The current ShrinkSafe standalone utility was broken when we last
00014 #    used it.
00015 #
00016 
00017 import sys
00018 
00019 import urllib
00020 import urllib2
00021 
00022 URL_SHRINK_SAFE = "http://shrinksafe.dojotoolkit.org/shrinksafe.php"
00023 
00024 # This would normally be dynamically generated:
00025 BOUNDARY_MARKER = "---------------------------72288400411964641492083565382"
00026                    
00027 if __name__ == "__main__":
00028     ## Grab the source code
00029     try:
00030         sourceFilename = sys.argv[1]
00031     except:
00032         print "Usage: %s (<source filename>|-)" % sys.argv[0]
00033         raise SystemExit
00034 
00035     if sourceFilename == "-":
00036         sourceCode = sys.stdin.read()
00037         sourceFilename = "stdin.js"
00038     else:
00039         sourceCode = open(sourceFilename).read()
00040         
00041     ## Create the request replicating posting of the form from the web page
00042     request = urllib2.Request(url=URL_SHRINK_SAFE)
00043     request.add_header("Content-Type",
00044                        "multipart/form-data; boundary=%s" % BOUNDARY_MARKER)
00045     request.add_data("""
00046 --%s
00047 Content-Disposition: form-data; name="shrinkfile[]"; filename="%s"
00048 Content-Type: application/x-javascript
00049 
00050 %s
00051 """ % (BOUNDARY_MARKER, sourceFilename, sourceCode))
00052 
00053     ## Deliver the result
00054     print urllib2.urlopen(request).read(),


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