[Inteproxy-commits] r33 - trunk
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Apr 5 17:16:14 CEST 2007
Author: bh
Date: 2007-04-05 17:16:13 +0200 (Thu, 05 Apr 2007)
New Revision: 33
Added:
trunk/demo.cfg
Modified:
trunk/ChangeLog
trunk/InteProxy.py
trunk/transcoder.py
Log:
* InteProxy.py (run_server): Add command line option --config-file
with default inteproxy.cfg. Read the transcoder configuration
from the file specified with this option.
* transcoder.py (HTTPSTranscoder): New base class for the OWSProxy
transcoders. HTTPSTranscoder turns all URLs into https urls.
(TranscoderMap): New class for the transcoder_map. This takes
care of the lookup and can read a config file.
(transcoder_map): Is now a TranscoderMap instance.
(get_transcoder): Uses transcoder_map directly now. Also no
longer hard-wires conversion to https urls.
(lookup_transcoder): removed again. It functionality is now part
of transcoder_map
* demo.cfg: New. Example configuration.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2007-04-05 12:55:39 UTC (rev 32)
+++ trunk/ChangeLog 2007-04-05 15:16:13 UTC (rev 33)
@@ -1,5 +1,23 @@
2007-04-05 Bernhard Herzog <bh at intevation.de>
+ * InteProxy.py (run_server): Add command line option --config-file
+ with default inteproxy.cfg. Read the transcoder configuration
+ from the file specified with this option.
+
+ * transcoder.py (HTTPSTranscoder): New base class for the OWSProxy
+ transcoders. HTTPSTranscoder turns all URLs into https urls.
+ (TranscoderMap): New class for the transcoder_map. This takes
+ care of the lookup and can read a config file.
+ (transcoder_map): Is now a TranscoderMap instance.
+ (get_transcoder): Uses transcoder_map directly now. Also no
+ longer hard-wires conversion to https urls.
+ (lookup_transcoder): removed again. It functionality is now part
+ of transcoder_map
+
+ * demo.cfg: New. Example configuration.
+
+2007-04-05 Bernhard Herzog <bh at intevation.de>
+
* InteProxy.py (InteProxyHTTPRequestHandler.transfer_data.limit_length):
If debug level is less than two, limit the length of the debug
output with the actual data transferred. When all the data is
Modified: trunk/InteProxy.py
===================================================================
--- trunk/InteProxy.py 2007-04-05 12:55:39 UTC (rev 32)
+++ trunk/InteProxy.py 2007-04-05 15:16:13 UTC (rev 33)
@@ -25,7 +25,7 @@
import Queue
import socket
import proxyconnection
-from transcoder import get_transcoder
+from transcoder import get_transcoder, transcoder_map
inteproxy_version = "0.1.2"
@@ -364,17 +364,21 @@
ServerClass = MasterWorkerServer):
"""Run the InteProxy server"""
parser = optparse.OptionParser()
- parser.set_defaults(port=64609, workers=5, debug_level=0)
+ parser.set_defaults(port=64609, workers=5, debug_level=0,
+ config_file="inteproxy.cfg")
parser.add_option("--logfile")
parser.add_option("--allow-shutdown", action="store_true")
parser.add_option("--port", type="int")
parser.add_option("--workers", type="int")
parser.add_option("--debug-level", type="int")
+ parser.add_option("--config-file")
opts, rest = parser.parse_args()
HandlerClass.allow_shutdown = opts.allow_shutdown
HandlerClass.debug_level = opts.debug_level
+ transcoder_map.read_config(opts.config_file)
+
setup_urllib2(opts.debug_level)
server_address = ('localhost', opts.port)
Added: trunk/demo.cfg
===================================================================
--- trunk/demo.cfg 2007-04-05 12:55:39 UTC (rev 32)
+++ trunk/demo.cfg 2007-04-05 15:16:13 UTC (rev 33)
@@ -0,0 +1,29 @@
+# Demo configuration for InteProxy.
+#
+# This file defines how different remote servers are to be accessed.
+# There is one section for each remote server. How the sections are
+# named doesn't really matter but it's a good idea to include the full
+# domain name in the section name.
+#
+# There might be some additional section with predefined names in the
+# future for other inteproxy settings. The names for those section will
+# be chosen so as to not interfere with existing section names. Hence
+# the suggestion to use the full domain name.
+
+# An example section for the host inteproxy-demo.intevation.org.
+[inteproxy-demo.intevation.org]
+
+# The hostname used in the URLs accessing this server
+host=inteproxy-demo.intevation.org
+
+# The path on the server
+path=/cgi-bin/frida-wms
+
+# the class defines how InteProxy handles the connection to the server.
+# Supported classes are:
+#
+# identity simply passes the request through.
+#
+# owsproxy The remote host is an OWSProxy requiring authentication
+# and https
+class=owsproxy
Modified: trunk/transcoder.py
===================================================================
--- trunk/transcoder.py 2007-04-05 12:55:39 UTC (rev 32)
+++ trunk/transcoder.py 2007-04-05 15:16:13 UTC (rev 33)
@@ -10,6 +10,7 @@
import urlparse
from urllib import quote_plus
from StringIO import StringIO
+from ConfigParser import SafeConfigParser
from lxml import etree
@@ -68,8 +69,16 @@
return content_type, body
-class OWSProxyGETTranscoder(IdentityTranscoder):
+class HTTPSTranscoder(IdentityTranscoder):
+ """Transcoder that turns the URL unconditionally into a HTTPS URL"""
+
+ def __init__(self, method, spliturl):
+ IdentityTranscoder.__init__(self, method, ("https",) + spliturl[1:])
+
+
+class OWSProxyGETTranscoder(HTTPSTranscoder):
+
"""Transcoder for GET requests to the OWSProxy"""
def get_url(self):
@@ -88,7 +97,7 @@
return urlparse.urlunsplit((scheme, netloc, path, query, fragment))
-class OWSProxyPOSTTranscoder(IdentityTranscoder):
+class OWSProxyPOSTTranscoder(HTTPSTranscoder):
"""Transcoder for POST requests to the OWSProxy"""
@@ -107,33 +116,47 @@
return content_type, body
-# Maps the path of an InteProxy request to transcoders. The key of the
-# transcoder_map is the path of the URL given to the InteProxy. E.g. if
-# the URL entered in the client is http://localhost:123/remote-host/wfs
-# the path is /remote-host/wfs. The values are dictionaries mapping the
-# http request method ("GET" or "POST") to the transcoder class. For
-# example, a value for transcoder_map might be
-#
-# transcoder_map = {
-# "/example.como/wfs": {"GET": OWSProxyGETTranscoder,
-# "POST": OWSProxyPOSTTranscoder},
-# }
+class TranscoderMap(object):
-transcoder_map = {
- }
+ def __init__(self, classes):
+ self.hostmap = dict()
+ self.classmap = dict()
+ self.default_classname = None
+ if classes:
+ for item in classes:
+ self.add_class(*item)
+ self.set_default_class(classes[0][0])
-def lookup_transcoder(method, path):
- # FIXME: ideally, we would use the IdentityTranscoder by default.
- # However, until we have some way to populate the transcoder_map
- # without hardcoding it, i. e. until we have a configuration file or
- # a similar mechanism, we use the OWSProxyPOSTTranscoder and
- # OWSProxyGETTranscoder as defaults so that the behavior is
- # basically the same as before the introduction of the transcoders.
- defaults = dict(GET=OWSProxyGETTranscoder, POST=OWSProxyPOSTTranscoder)
- return transcoder_map.get(path, defaults).get(method, IdentityTranscoder)
+ def set_default_class(self, name):
+ self.default_classname = name
+ def add_class(self, name, get, post):
+ self.classmap[name] = dict(GET=get, POST=post)
+ def add_host(self, host, path, classname):
+ self.hostmap[(host, path)] = classname
+
+ def lookup(self, method, host, path):
+ classname = self.hostmap.get((host, path), self.default_classname)
+ return self.classmap[classname][method]
+
+ def read_config(self, filename):
+ parser = SafeConfigParser()
+ parser.read([filename])
+ for section in parser.sections():
+ host = parser.get(section, "host")
+ path = parser.get(section, "path")
+ cls = parser.get(section, "class")
+ self.add_host(host, path, cls)
+
+
+transcoder_map = TranscoderMap([
+ ("identity", IdentityTranscoder, IdentityTranscoder),
+ ("owsproxy", OWSProxyGETTranscoder, OWSProxyPOSTTranscoder),
+ ])
+
+
def get_transcoder(method, url):
"""Return a transcoder for the given HTTP method and URL
@@ -159,12 +182,9 @@
# If scheme is given, InteProxy is used as a HTTP proxy.
if scheme:
- transcoder_key = netloc + path
real_netloc = netloc
real_path = path
else:
- transcoder_key = path
-
# determine the remote host encoded in the path
split_path = path.split("/")
if not split_path[0]:
@@ -172,6 +192,6 @@
real_netloc = split_path.pop(0)
real_path = "/" + "/".join(split_path)
- transcoder_class = lookup_transcoder(method, transcoder_key)
+ transcoder_class = transcoder_map.lookup(method, real_netloc, real_path)
return transcoder_class(method,
- ("https", real_netloc, real_path, query, fragment))
+ (scheme, real_netloc, real_path, query, fragment))
More information about the Inteproxy-commits
mailing list