[Inteproxy-commits] r207 - in trunk: . inteproxy test

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Sep 11 21:36:51 CEST 2009


Author: bh
Date: 2009-09-11 21:36:50 +0200 (Fri, 11 Sep 2009)
New Revision: 207

Modified:
   trunk/ChangeLog
   trunk/inteproxy/transcoder.py
   trunk/test/test_owsproxy_get_transcoder.py
   trunk/test/test_owsproxy_post_transcoder.py
Log:
* inteproxy/transcoder.py (IdentityTranscoder.__init__): New
parameter and instance variable rule to hold the inteproxy rule
for which the transcoder was instantiated.
(IdentityTranscoder.get_password): If the rule already has the
credentials, return those instead of the trying to get the
password from elsewhere
(HTTPSTranscoder.__init__): Add the rule parameter
(TranscoderMap.lookup): Now returns the rule instead of the
transcoder class
(TranscoderMap.get_transcoder): Do the transcoder class lookup
here and pass the rule to the transcoder

* test/test_owsproxy_post_transcoder.py,
test/test_owsproxy_get_transcoder.py: Adapt to transcoder changes.
No need for special transcoder classes with predefined passwords
anymore since the base classes can handle this now.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2009-09-11 19:21:03 UTC (rev 206)
+++ trunk/ChangeLog	2009-09-11 19:36:50 UTC (rev 207)
@@ -1,5 +1,24 @@
 2009-09-11  Bernhard Herzog  <bh at intevation.de>
 
+	* inteproxy/transcoder.py (IdentityTranscoder.__init__): New
+	parameter and instance variable rule to hold the inteproxy rule
+	for which the transcoder was instantiated.
+	(IdentityTranscoder.get_password): If the rule already has the
+	credentials, return those instead of the trying to get the
+	password from elsewhere
+	(HTTPSTranscoder.__init__): Add the rule parameter
+	(TranscoderMap.lookup): Now returns the rule instead of the
+	transcoder class
+	(TranscoderMap.get_transcoder): Do the transcoder class lookup
+	here and pass the rule to the transcoder
+
+	* test/test_owsproxy_post_transcoder.py,
+	test/test_owsproxy_get_transcoder.py: Adapt to transcoder changes.
+	No need for special transcoder classes with predefined passwords
+	anymore since the base classes can handle this now.
+
+2009-09-11  Bernhard Herzog  <bh at intevation.de>
+
 	* create-rewrite-rules.py: Substantial changes to adapt to the new
 	features: credentials and wild-card patterns in the config file.
 	Since the credentials are now in the main configuration file, the

Modified: trunk/inteproxy/transcoder.py
===================================================================
--- trunk/inteproxy/transcoder.py	2009-09-11 19:21:03 UTC (rev 206)
+++ trunk/inteproxy/transcoder.py	2009-09-11 19:36:50 UTC (rev 207)
@@ -27,7 +27,7 @@
     request.
     """
 
-    def __init__(self, method, spliturl):
+    def __init__(self, method, spliturl, rule):
         """Initializes the transcoder
 
         Parameters:
@@ -38,6 +38,7 @@
         """
         self.method = method
         self.spliturl = spliturl
+        self.rule = rule
 
     def get_password(self):
         """Returns the username and password needed for the request
@@ -46,6 +47,8 @@
         parts of the url as the parameter for the
         get_password_with_cache function.
         """
+        if self.rule.user is not None:
+            return (self.rule.user, self.rule.password)
         return getpassword.get_password_with_cache("".join(self.spliturl[1:3]))
 
     def get_url(self):
@@ -67,8 +70,9 @@
 
     """Transcoder that turns the URL unconditionally into a HTTPS URL"""
 
-    def __init__(self, method, spliturl):
-        super(HTTPSTranscoder, self).__init__(method, ("https",) + spliturl[1:])
+    def __init__(self, method, spliturl, rule):
+        super(HTTPSTranscoder, self).__init__(method, ("https",) + spliturl[1:],
+                                              rule)
 
 
 class OWSProxyGETTranscoder(HTTPSTranscoder):
@@ -206,19 +210,17 @@
         for rule in rules:
             self.add_rule(rule)
 
-    def lookup(self, method, host, path):
-        """Returns the python class implementing the transcoder for path on host
+    def lookup(self, host, path):
+        """Returns the rule matching host and path.
+        If no rule matches, the method returns None
         """
         for host_regex, path_regex, rule in self.rules:
             host_match = host_regex.match(host)
             if host_match and host_match.group(0) == host:
                 path_match = path_regex.match(path)
                 if path_match and path_match.group(0) == path:
-                    classname = rule.scheme
-                    break
-        else:
-            classname = self.default_classname
-        return self.classmap[classname][method]
+                    return rule
+        return None
 
     def get_transcoder(self, method, url):
         """Returns a transcoder for the given HTTP method and URL
@@ -256,9 +258,14 @@
             netloc = split_path.pop(0)
             path = "/" + "/".join(split_path)
 
-        transcoder_class = self.lookup(method, netloc, path)
+        inteproxy_scheme = self.default_classname
+        rule = self.lookup(netloc, path)
+        if rule is not None:
+            inteproxy_scheme = rule.scheme
+        transcoder_class = self.classmap[inteproxy_scheme][method]
         return transcoder_class(method,
-                                (scheme, netloc, path, query, fragment))
+                                (scheme, netloc, path, query, fragment),
+                                rule)
 
     def rewrite_urls(self, data, prefix, log_debug):
         """Prefix all known URLs in data with prefix.

Modified: trunk/test/test_owsproxy_get_transcoder.py
===================================================================
--- trunk/test/test_owsproxy_get_transcoder.py	2009-09-11 19:21:03 UTC (rev 206)
+++ trunk/test/test_owsproxy_get_transcoder.py	2009-09-11 19:36:50 UTC (rev 207)
@@ -1,4 +1,4 @@
-# Copyright (C) 2007 by Intevation GmbH
+# Copyright (C) 2007, 2009 by Intevation GmbH
 # Authors:
 # Bernhard Herzog <bh at intevation.de>
 #
@@ -11,21 +11,11 @@
 import unittest
 
 from inteproxy.transcoder import OWSProxyGETTranscoder
+from inteproxy.config import InteProxyRule
 
-
 class TestOWSProxyGETTranscoder(unittest.TestCase):
 
     def test_username_password_substitution(self):
-
-        class Transcoder(OWSProxyGETTranscoder):
-            """
-            An OWSProxyGETTranscoder that uses usernames/passwords
-            defined in this test case
-            """
-            def get_password(self):
-                return user, password
-
-
         test_users = [("user", "password",
                        "https://example.com/wfs",
                        "https://example.com/wfs?user=user&password=password"),
@@ -45,5 +35,9 @@
                        "user=some+%C3%BCser%26&password=%3Cpass%26%3Eword%3F"),
                       ]
         for user, password, baseurl, encodedurl in test_users:
-            transcoder = Transcoder("GET", urlparse.urlsplit(baseurl))
+            rule = InteProxyRule("owsproxy", "example.com", "/wfs",
+                                 user=user, password=password)
+            transcoder = OWSProxyGETTranscoder("GET",
+                                               urlparse.urlsplit(baseurl),
+                                               rule)
             self.assertEquals(transcoder.get_url(), encodedurl)

Modified: trunk/test/test_owsproxy_post_transcoder.py
===================================================================
--- trunk/test/test_owsproxy_post_transcoder.py	2009-09-11 19:21:03 UTC (rev 206)
+++ trunk/test/test_owsproxy_post_transcoder.py	2009-09-11 19:36:50 UTC (rev 207)
@@ -1,4 +1,4 @@
-# Copyright (C) 2007, 2008 by Intevation GmbH
+# Copyright (C) 2007, 2008, 2009 by Intevation GmbH
 # Authors:
 # Bernhard Herzog <bh at intevation.de>
 #
@@ -13,6 +13,7 @@
 import unittest
 from inteproxy.transcoder import OWSProxyPOSTTranscoder
 from inteproxy.httpmessage import HTTPRequestMessage
+from inteproxy.config import InteProxyRule
 
 
 class TestOWSProxyPOSTTranscoder(unittest.TestCase):
@@ -56,23 +57,17 @@
                                   StringIO(body))
 
     def test_username_password_substitution(self):
-
-        class Transcoder(OWSProxyPOSTTranscoder):
-            """
-            An OWSProxyPOSTTranscoder that uses usernames/passwords
-            defined in this test case
-            """
-            def get_password(self):
-                return user, password
-
-
         test_users = [("user", "password", '"user"', '"password"'),
                       (u"some \xfcser&", "<pass&>word",
                        '"some &#252;ser&amp;"', '"&lt;pass&amp;&gt;word"'),
                       ]
         for user, password, userattr, passwordattr in test_users:
-            transcoder = Transcoder("POST",
-                                    ("https", "example.com", "wfs", "", ""))
+            rule = InteProxyRule("owsproxy", "example.com", "/wfs",
+                                 user=user, password=password)
+            transcoder = OWSProxyPOSTTranscoder("POST",
+                                                ("https", "example.com", "wfs",
+                                                 "", ""),
+                                                rule=rule)
             request = self.create_request(self.get_feature_orig)
             transcoder.convert_request(request)
             self.assertEquals(request.body,



More information about the Inteproxy-commits mailing list