moksha/middleware/middleware.py | 93 ++++++++++++++++++-----------------
moksha/tests/functional/test_csrf.py | 9 ++-
2 files changed, 54 insertions(+), 48 deletions(-)
New commits:
commit 234e47421b72aae838e680b5a03cf57fb70688bd
Author: Luke Macken <lmacken(a)redhat.com>
Date: Fri Jun 4 18:21:26 2010 -0400
Get our CSRF tests working with the TurboGears 2.1 stack
diff --git a/moksha/tests/functional/test_csrf.py b/moksha/tests/functional/test_csrf.py
index d3c62ed..3cab8f7 100644
--- a/moksha/tests/functional/test_csrf.py
+++ b/moksha/tests/functional/test_csrf.py
@@ -76,11 +76,13 @@ class TestCSRFProtection(TestController):
# Make sure we can't get back to the page without the token
resp = self.app.get('/moksha_admin/', status=302)
assert 'The resource was found at /post_logout' in resp or \
- 'The resource was found at /login' in resp, resp
+ 'The resource was found at /login' in resp or \
+ 'The resource was found at
http://localhost/login' in resp
# Make sure that we can't get back after we got rejected once
resp = self.app.post('/moksha_admin/', {'_csrf_token': token},
status=302)
- assert 'The resource was found at /login' in resp, resp
+ assert 'The resource was found at /login' in resp or \
+ 'The resource was found at
http://localhost/login' in resp
# Ensure the token gets removed
resp = self.app.get('/', status=200)
@@ -104,4 +106,5 @@ class TestCSRFProtection(TestController):
# Now, make sure we reject invalid tokens
resp = self.app.post('/moksha_admin/', {'_csrf_token': token +
' '}, status=302)
- assert 'The resource was found at /post_logout' in resp, resp
+ assert 'The resource was found at /post_logout' in resp or \
+ 'The resource was found at
http://localhost/post_logout' in resp
commit e658ef86925c8144303c4f6de76dbcea624634a0
Author: Luke Macken <lmacken(a)redhat.com>
Date: Fri Jun 4 18:14:36 2010 -0400
Get our middleware working with TG2.1!
diff --git a/moksha/middleware/middleware.py b/moksha/middleware/middleware.py
index 8aca064..315e313 100644
--- a/moksha/middleware/middleware.py
+++ b/moksha/middleware/middleware.py
@@ -202,54 +202,57 @@ class MokshaMiddleware(object):
"""
from mako.template import Template
from mako.lookup import TemplateLookup
- try: # TG2b6 and later
- from tg.dottednamesupport import DottedTemplateLookup
- except: # TG2b5 and earlier
- from tg.util import get_dotted_filename
-
- class DottedTemplateLookup(object):
- """this is an emulation of the Mako template lookup
- that will handle get_template and support dotted names
- in python path notation to support zipped eggs
- """
- def __init__(self, input_encoding, output_encoding,
- imports, default_filters):
- self.input_encoding = input_encoding
- self.output_encoding = output_encoding
- self.imports = imports
- self.default_filters = default_filters
-
- def adjust_uri(self, uri, relativeto):
- """this method is used by mako for filesystem based
reasons.
- In dotted lookup land we don't adjust uri so se just return
- the value we are given without any change
+ try: # TG2.1
+ from tg.dottednames.mako_lookup import DottedTemplateLookup
+ except ImportError:
+ try: # TG2b6
+ from tg.dottednamesupport import DottedTemplateLookup
+ except: # TG2b5 and earlier
+ from tg.util import get_dotted_filename
+
+ class DottedTemplateLookup(object):
+ """this is an emulation of the Mako template lookup
+ that will handle get_template and support dotted names
+ in python path notation to support zipped eggs
"""
- if '.' in uri:
- """we are in the DottedTemplateLookup system so
dots in
- names should be treated as a python path.
- Since this method is called by template inheritance we must
- support dotted names also in the inheritance.
+ def __init__(self, input_encoding, output_encoding,
+ imports, default_filters):
+ self.input_encoding = input_encoding
+ self.output_encoding = output_encoding
+ self.imports = imports
+ self.default_filters = default_filters
+
+ def adjust_uri(self, uri, relativeto):
+ """this method is used by mako for filesystem
based reasons.
+ In dotted lookup land we don't adjust uri so se just return
+ the value we are given without any change
"""
- result = get_dotted_filename(template_name=uri,
- template_extension='.mak')
-
- else:
- """no dot detected, just return plain name
+ if '.' in uri:
+ """we are in the DottedTemplateLookup system
so dots in
+ names should be treated as a python path.
+ Since this method is called by template inheritance we must
+ support dotted names also in the inheritance.
+ """
+ result = get_dotted_filename(template_name=uri,
+
template_extension='.mak')
+
+ else:
+ """no dot detected, just return plain name
+ """
+ result = uri
+
+ return result
+
+ def get_template(self, template_name):
+ """this is the emulated method that must return a
template
+ instance based on a given template name
"""
- result = uri
-
- return result
-
- def get_template(self, template_name):
- """this is the emulated method that must return a
template
- instance based on a given template name
- """
- return Template(open(template_name).read(),
- input_encoding=self.input_encoding,
- output_encoding=self.output_encoding,
- default_filters=self.default_filters,
- imports=self.imports,
- lookup=self)
+ return Template(open(template_name).read(),
+ input_encoding=self.input_encoding,
+ output_encoding=self.output_encoding,
+ default_filters=self.default_filters,
+ imports=self.imports,
+ lookup=self)
if config.get('use_dotted_templatenames', True):
# support dotted names by injecting a slightly different template