[Git][debian-gis-team/openlayers][master] Update proxy.cgi example for Python 3.

Bas Couwenberg gitlab at salsa.debian.org
Sat Jul 27 18:47:02 BST 2019



Bas Couwenberg pushed to branch master at Debian GIS Project / openlayers


Commits:
9bf82906 by Bas Couwenberg at 2019-07-27T17:45:21Z
Update proxy.cgi example for Python 3.

- - - - -


1 changed file:

- debian/patches/python3.patch


Changes:

=====================================
debian/patches/python3.patch
=====================================
@@ -383,16 +383,49 @@ Author: Bas Couwenberg <sebastic at debian.org>
  
  
  """This is a blind proxy that we use to get around browser
-@@ -29,7 +29,7 @@ method = os.environ["REQUEST_METHOD"]
+@@ -9,9 +9,12 @@ people can use this proxy to browse the
+ with it.  It only loads pages via http and https, but it can load any
+ content type. It supports GET and POST requests."""
+ 
+-import urllib2
+ import cgi
+-import sys, os
++import os
++import sys
++import urllib
++
++import requests
+ 
+ # Designed to prevent Open Proxy type stuff.
+ 
+@@ -20,62 +23,65 @@ allowedHosts = ['www.openlayers.org', 'o
+                 'prototype.openmnnd.org', 'geo.openplans.org',
+                 'sigma.openplans.org', 'demo.opengeo.org',
+                 'www.openstreetmap.org', 'sample.azavea.com',
+-                'v2.suite.opengeo.org', 'v-swe.uni-muenster.de:8080',
++                'v2.suite.opengeo.org', 'v-swe.uni-muenster.de:8080', 
+                 'vmap0.tiles.osgeo.org', 'www.openrouteservice.org',
+                 'maps.wien.gv.at']
+ 
++default_url = "http://www.openlayers.org"
++
+ method = os.environ["REQUEST_METHOD"]
+ 
  if method == "POST":
      qs = os.environ["QUERY_STRING"]
-     d = cgi.parse_qs(qs)
+-    d = cgi.parse_qs(qs)
 -    if d.has_key("url"):
++    d = urllib.parse.parse_qs(qs)
 +    if "url" in d:
          url = d["url"][0]
      else:
-         url = "http://www.openlayers.org"
-@@ -40,12 +40,12 @@ else:
+-        url = "http://www.openlayers.org"
++        url = default_url
+ else:
+     fs = cgi.FieldStorage()
+-    url = fs.getvalue('url', "http://www.openlayers.org")
++    url = fs.getvalue('url', default_url)
+ 
  try:
      host = url.split("/")[2]
      if allowedHosts and not host in allowedHosts:
@@ -411,37 +444,54 @@ Author: Bas Couwenberg <sebastic at debian.org>
    
      elif url.startswith("http://") or url.startswith("https://"):
      
-@@ -60,22 +60,22 @@ try:
+         if method == "POST":
++            content_type = 'text/plain'
++            if 'CONTENT_TYPE' in os.environ:
++                content_type = os.environ["CONTENT_TYPE"]
++
+             length = int(os.environ["CONTENT_LENGTH"])
+-            headers = {"Content-Type": os.environ["CONTENT_TYPE"]}
++            headers = {"Content-Type": content_type}
+             body = sys.stdin.read(length)
+-            r = urllib2.Request(url, body, headers)
+-            y = urllib2.urlopen(r)
++
++            r = requests.post(url, data=body, headers=headers)
+         else:
+-            y = urllib2.urlopen(url)
++            r = requests.get(url)
          
          # print content type header
-         i = y.info()
+-        i = y.info()
 -        if i.has_key("Content-Type"):
 -            print "Content-Type: %s" % (i["Content-Type"])
-+        if "Content-Type" in i:
-+            print("Content-Type: %s" % (i["Content-Type"]))
++        if "Content-Type" in r.headers:
++            print("Content-Type: %s" % (r.headers["Content-Type"]))
          else:
 -            print "Content-Type: text/plain"
 -        print
+-        
+-        print y.read()
 +            print("Content-Type: text/plain")
 +        print("")
          
--        print y.read()
-+        print(y.read())
-         
-         y.close()
+-        y.close()
++        print(r.text)
      else:
 -        print "Content-Type: text/plain"
 -        print
 -        print "Illegal request."
-+        print("Content-Type: text/plain")
-+        print("")
-+        print("Illegal request.")
- 
- except Exception, E:
+-
+-except Exception, E:
 -    print "Status: 500 Unexpected Error"
 -    print "Content-Type: text/plain"
 -    print 
 -    print "Some unexpected error occurred. Error text was:", E
++        print("Content-Type: text/plain")
++        print("")
++        print("Illegal request.")
++
++except Exception as E:
 +    print("Status: 500 Unexpected Error")
 +    print("Content-Type: text/plain")
 +    print("")



View it on GitLab: https://salsa.debian.org/debian-gis-team/openlayers/commit/9bf829060e7901f5e5eea8491d31749214f930a6

-- 
View it on GitLab: https://salsa.debian.org/debian-gis-team/openlayers/commit/9bf829060e7901f5e5eea8491d31749214f930a6
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-grass-devel/attachments/20190727/14dd3d89/attachment-0001.html>


More information about the Pkg-grass-devel mailing list