Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 345df3d8e60d41cb2b1c12e5e29f87f5abd03e19 @niklasvh committed Jul 28, 2011
Showing with 85 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +8 −0 python/app.yaml
  3. +60 −0 python/html2canvas.py
  4. +11 −0 python/index.yaml
  5. +5 −0 readme.md
1 .gitignore
@@ -0,0 +1 @@
+/nbproject/
8 python/app.yaml
@@ -0,0 +1,8 @@
+application: html2canvas
+version: 1
+runtime: python
+api_version: 1
+
+handlers:
+- url: .*
+ script: html2canvas.py
60 python/html2canvas.py
@@ -0,0 +1,60 @@
+__author__="Niklas von Hertzen <niklas at hertzen.com>"
+__date__ ="$19.7.2011 23:16:25$"
+
+from google.appengine.ext import webapp
+from google.appengine.ext.webapp.util import run_wsgi_app
+import urllib2
+import base64
+import simplejson as json
+import urlparse;
+
+class MainPage(webapp.RequestHandler):
+ def get(self):
+ if self.request.get('url') != "" and self.request.get('callback') != "":
+ try:
+
+ url = self.request.get('url');
+
+ urlInfo = urlparse.urlparse(url);
+
+ if urlInfo.scheme in ["http","https"]:
+ result = urllib2.urlopen(url)
+ requestInfo = result.info();
+
+ if requestInfo['content-type'] in ["image/jpeg","image/png","image/gif"] or "image/png" in requestInfo['content-type'] or "image/jpg" in requestInfo['content-type'] or "image/jpeg" in requestInfo['content-type'] or "image/gif" in requestInfo['content-type'] or "text/html" in requestInfo['content-type'] or "application/xhtml" in requestInfo['content-type']:
+ if self.request.get('xhr2') == "true":
+ self.response.headers.add_header("Access-Control-Allow-Origin", "*");
+ self.response.headers['Content-Type'] = requestInfo['content-type'];
+ self.response.out.write(result.read());
+ else:
+ self.response.headers['Content-Type'] = "application/javascript";
+ if "text/html" in requestInfo['content-type'] or "application/xhtml" in requestInfo['content-type']:
+ htmlContent = result.read();
+ try:
+ self.response.out.write(self.request.get('callback')+"("+json.dumps(htmlContent)+")");
+ except:
+ #this certainly isn't the best solution, but works for most common cases
+ self.response.out.write(self.request.get('callback')+"("+json.dumps(unicode(htmlContent,"ISO-8859-1"))+")");
+ else:
+ self.response.out.write(self.request.get('callback')+"("+json.dumps("data:" + requestInfo['content-type'] + ";base64," + base64.b64encode( result.read()) )+")");
+ else:
+ self.response.headers['Content-Type'] = "application/javascript";
+ self.response.out.write( self.request.get('callback')+"("+json.dumps("error:Invalid mime:" + requestInfo['content-type']) +")" );
+ else:
+ self.response.headers['Content-Type'] = "application/javascript";
+ self.response.out.write(self.request.get('callback')+"("+json.dumps( "error:Invalid protocol:" + urlInfo.scheme )+")" );
+
+ except urllib2.URLError, e:
+ self.response.headers['Content-Type'] = "application/javascript";
+ self.response.out.write(self.request.get('callback')+"("+json.dumps( "error:Application error" ) +")" );
+
+
+application = webapp.WSGIApplication(
+ [('/', MainPage)],
+ debug=True)
+
+def main():
+ run_wsgi_app(application)
+
+if __name__ == "__main__":
+ main()
11 python/index.yaml
@@ -0,0 +1,11 @@
+indexes:
+
+# AUTOGENERATED
+
+# This index.yaml is automatically updated whenever the dev_appserver
+# detects that a new type of query is run. If you want to manage the
+# index.yaml file manually, remove the above marker line (the line
+# saying "# AUTOGENERATED"). If you want to manage some indexes
+# manually, move them above the marker line. The index.yaml file is
+# automatically uploaded to the admin console when you next deploy
+# your application using appcfg.py.
5 readme.md
@@ -0,0 +1,5 @@
+html2canvas-proxy
+=================
+Proxies for <a href="https://github.com/niklasvh/html2canvas">html2canvas</a>. Currently available proxies:
+
+* Python for Google Appengine

0 comments on commit 345df3d

Please sign in to comment.