# HG changeset patch # User paulb # Date 1201995336 0 # Node ID 7a9ee094a4b764394f217e0cdab1c61fe9fb9733 # Parent c9c8bbed41882ff74c00ddd77d97367b59811216 [project @ 2008-02-02 23:35:36 by paulb] Removed local default encoding attributes. Improved the SimpleMap resource documentation and initialisation features. diff -r c9c8bbed4188 -r 7a9ee094a4b7 WebStack/Resources/Login.py --- a/WebStack/Resources/Login.py Sat Feb 02 23:33:13 2008 +0000 +++ b/WebStack/Resources/Login.py Sat Feb 02 23:35:36 2008 +0000 @@ -28,8 +28,6 @@ "A resource providing a login screen." - encoding = "utf-8" - def __init__(self, authenticator, use_redirect=1, urlencoding=None, encoding=None): """ @@ -53,7 +51,7 @@ self.authenticator = authenticator self.use_redirect = use_redirect self.urlencoding = urlencoding - self.encoding = encoding or self.encoding + self.encoding = encoding def respond(self, trans): diff -r c9c8bbed4188 -r 7a9ee094a4b7 WebStack/Resources/LoginRedirect.py --- a/WebStack/Resources/LoginRedirect.py Sat Feb 02 23:33:13 2008 +0000 +++ b/WebStack/Resources/LoginRedirect.py Sat Feb 02 23:35:36 2008 +0000 @@ -28,8 +28,6 @@ "A resource redirecting to a login URL." - encoding = "utf-8" - def __init__(self, resource, authenticator, login_url=None, app_url=None, anonymous_parameter_name=None, anonymous_username="anonymous", logout_parameter_name=None, logout_url="/", use_logout_redirect=1, @@ -76,7 +74,7 @@ self.logout_parameter_name = logout_parameter_name self.logout_url = logout_url self.use_logout_redirect = use_logout_redirect - self.path_encoding = path_encoding or urlencoding or self.encoding + self.path_encoding = path_encoding or urlencoding def respond(self, trans): @@ -162,7 +160,7 @@ # When logout takes place, show the logout screen. - trans.set_content_type(WebStack.Generic.ContentType("text/html", self.encoding)) + trans.set_content_type(WebStack.Generic.ContentType("text/html")) out = trans.get_response_stream() out.write(self.logout_page % redirect) diff -r c9c8bbed4188 -r 7a9ee094a4b7 WebStack/Resources/OpenIDInitiation.py --- a/WebStack/Resources/OpenIDInitiation.py Sat Feb 02 23:33:13 2008 +0000 +++ b/WebStack/Resources/OpenIDInitiation.py Sat Feb 02 23:35:36 2008 +0000 @@ -28,7 +28,6 @@ "A resource providing an OpenID initiation screen." - encoding = "utf-8" openid_ns = "http://specs.openid.net/auth/2.0" def __init__(self, openid_mode=None, use_redirect=1, urlencoding=None, encoding=None): @@ -57,7 +56,7 @@ self.openid_mode = openid_mode or "checkid_setup" self.use_redirect = use_redirect self.urlencoding = urlencoding - self.encoding = encoding or self.encoding + self.encoding = encoding def respond(self, trans): diff -r c9c8bbed4188 -r 7a9ee094a4b7 WebStack/Resources/OpenIDLogin.py --- a/WebStack/Resources/OpenIDLogin.py Sat Feb 02 23:33:13 2008 +0000 +++ b/WebStack/Resources/OpenIDLogin.py Sat Feb 02 23:35:36 2008 +0000 @@ -171,8 +171,6 @@ "A resource providing a login screen." - encoding = "utf-8" - def __init__(self, app_url, authenticator, associations=None, use_redirect=1, urlencoding=None, encoding=None): """ @@ -201,7 +199,7 @@ self.app_url = app_url self.authenticator = authenticator self.urlencoding = urlencoding - self.encoding = encoding or self.encoding + self.encoding = encoding def respond(self, trans): diff -r c9c8bbed4188 -r 7a9ee094a4b7 WebStack/Resources/OpenIDRedirect.py --- a/WebStack/Resources/OpenIDRedirect.py Sat Feb 02 23:33:13 2008 +0000 +++ b/WebStack/Resources/OpenIDRedirect.py Sat Feb 02 23:35:36 2008 +0000 @@ -62,7 +62,6 @@ cookie, accepting OpenID assertions if necessary. """ - encoding = "utf-8" openid_ns = "http://specs.openid.net/auth/2.0" replay_limit = datetime.timedelta(0, 10) # 10s @@ -79,7 +78,7 @@ self.app_url = app_url self.associations = associations or {} self.replay_limit = replay_limit or self.replay_limit - self.urlencoding = urlencoding or self.encoding + self.urlencoding = urlencoding def authenticate(self, trans, verify=0): diff -r c9c8bbed4188 -r 7a9ee094a4b7 WebStack/Resources/ResourceMap.py --- a/WebStack/Resources/ResourceMap.py Sat Feb 02 23:33:13 2008 +0000 +++ b/WebStack/Resources/ResourceMap.py Sat Feb 02 23:35:36 2008 +0000 @@ -26,8 +26,6 @@ "A resource mapping names to other resources." - path_encoding = "utf-8" - def __init__(self, mapping, pass_through=0, directory_redirects=1, path_encoding=None, urlencoding=None): """ @@ -86,7 +84,7 @@ self.mapping = mapping self.pass_through = pass_through self.directory_redirects = directory_redirects - self.path_encoding = path_encoding or urlencoding or self.path_encoding + self.path_encoding = path_encoding or urlencoding def respond(self, trans): @@ -170,4 +168,19 @@ query_string = "?" + query_string trans.redirect(trans.encode_path(path_without_query, self.path_encoding) + "/" + query_string) +class SimpleMap(MapResource): + + "A simple mapping of names to resources, focused on the most common case." + + def __init__(self, mapping, directory_redirects=1): + + """ + Initialise the resource with the given 'mapping' and optional + 'directory_redirects' settings. Unlike MapResource, other options are + not exposed: if the 'mapping' has an entry for None, the 'pass_through' + option of MapResource is enabled. + """ + + MapResource.__init__(self, mapping, mapping.has_key(None), directory_redirects) + # vim: tabstop=4 expandtab shiftwidth=4 diff -r c9c8bbed4188 -r 7a9ee094a4b7 WebStack/Resources/Selectors.py --- a/WebStack/Resources/Selectors.py Sat Feb 02 23:33:13 2008 +0000 +++ b/WebStack/Resources/Selectors.py Sat Feb 02 23:35:36 2008 +0000 @@ -25,7 +25,7 @@ "Set a request's current path and processed path info on an attribute." - def __init__(self, resource, add_slash=1, attribute_name="root", path_encoding="utf-8"): + def __init__(self, resource, add_slash=1, attribute_name="root", path_encoding=None): """ Initialise the selector with a 'resource' (to which all requests shall diff -r c9c8bbed4188 -r 7a9ee094a4b7 WebStack/Resources/Static.py --- a/WebStack/Resources/Static.py Sat Feb 02 23:33:13 2008 +0000 +++ b/WebStack/Resources/Static.py Sat Feb 02 23:35:36 2008 +0000 @@ -30,7 +30,7 @@ def __init__(self, directory, media_types=None, unrecognised_media_type="application/data", content_types=None, unrecognised_content_type=None, default_encoding=None, - urlencoding="utf-8"): + urlencoding=None): """ Initialise the resource to serve files from the given 'directory'.