# HG changeset patch # User paulb # Date 1169334929 0 # Node ID c091bb3733be12ecdefbf9ca2058330b3f441180 # Parent fbdb75bbf4865a0af1eecfd176cbfafdf328fc0e [project @ 2007-01-20 23:15:29 by paulb] Added the EncodingSelector class. diff -r fbdb75bbf486 -r c091bb3733be WebStack/Resources/Selectors.py --- a/WebStack/Resources/Selectors.py Sat Jan 20 23:15:19 2007 +0000 +++ b/WebStack/Resources/Selectors.py Sat Jan 20 23:15:29 2007 +0000 @@ -51,7 +51,8 @@ """ Respond to the transaction 'trans' by storing the current path and - processed virtual path info on the named transaction attribute. + processed virtual path info on the named transaction attribute, then + forwarding the transaction to the previously specified resource. """ pwi = trans.get_path_without_info(self.path_encoding) @@ -68,4 +69,34 @@ self.resource.respond(trans) +class EncodingSelector: + + """ + Set the default encoding (or "charset") on transactions presented to this + resource. + """ + + def __init__(self, resource, encoding): + + """ + Initialise the selector with a 'resource' (to which all requests shall + be forwarded), specifying the 'encoding' which shall be used as the + default encoding (or "charset") for all transactions handled by this + resource. + """ + + self.resource = resource + self.encoding = encoding + + def respond(self, trans): + + """ + Respond to the transaction 'trans' by setting the default encoding (or + "charset") on 'trans', then forwarding the transaction to the previously + specified resource. + """ + + trans.default_charset = self.encoding + self.resource.respond(trans) + # vim: tabstop=4 expandtab shiftwidth=4