# HG changeset patch # User paulb # Date 1075649288 0 # Node ID 95501d8e090b27a81730f35defa005c4bdd5eb8e # Parent 8e718b11986572475e25f7550af7e3c2716bc995 [project @ 2004-02-01 15:28:08 by paulb] Fixed content type setting on responses. Added whole path support. diff -r 8e718b119865 -r 95501d8e090b WebStack/Generic.py --- a/WebStack/Generic.py Thu Jan 29 23:42:47 2004 +0000 +++ b/WebStack/Generic.py Sun Feb 01 15:28:08 2004 +0000 @@ -19,7 +19,7 @@ "A container for content type information." - def __init__(self, content_type, charset): + def __init__(self, content_type, charset=None): self.content_type = content_type self.charset = charset @@ -48,6 +48,22 @@ else: return ContentType(t[0], t[1]) + def format_content_type(self, content_type): + + """ + Format the given 'content_type' object, producing a string suitable for + the response header field. + """ + + if content_type.charset: + field = "%s; charset=%s" % (content_type.content_type, content_type.charset) + else: + field = content_type.content_type + + # Make sure that only ASCII is used in the header. + + return field.encode("US-ASCII") + def parse_content_preferences(self, accept_preference): """ @@ -122,6 +138,14 @@ raise NotImplementedError, "get_content_languages" + def get_path(self): + + """ + A framework-specific method which gets the entire path from the request. + """ + + raise NotImplementedError, "get_path" + def get_path_info(self): """ diff -r 8e718b119865 -r 95501d8e090b WebStack/ModPython.py --- a/WebStack/ModPython.py Thu Jan 29 23:42:47 2004 +0000 +++ b/WebStack/ModPython.py Sun Feb 01 15:28:08 2004 +0000 @@ -73,6 +73,14 @@ return self.parse_content_preferences(self.trans.headers_in["Accept-Language"]) + def get_path(self): + + """ + A framework-specific method which gets the entire path from the request. + """ + + return self.trans.uri + def get_path_info(self): """ @@ -81,7 +89,7 @@ request. """ - raise NotImplementedError, "get_path_info" + raise self.trans.path_info # Higher level request-related methods. @@ -121,8 +129,6 @@ response. """ - # Make sure that only ASCII is used in the header. - - self.trans.content_type = content_type.encode("US-ASCII") + self.trans.content_type = self.format_content_type(content_type) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 8e718b119865 -r 95501d8e090b WebStack/Twisted.py --- a/WebStack/Twisted.py Thu Jan 29 23:42:47 2004 +0000 +++ b/WebStack/Twisted.py Sun Feb 01 15:28:08 2004 +0000 @@ -27,7 +27,7 @@ the transaction. """ - return self.trans + return self.trans.content def get_request_method(self): @@ -74,6 +74,16 @@ return self.parse_content_preferences(self.trans.getHeader("Accept-Charset")) + def get_path(self): + + """ + A framework-specific method which gets the entire path from the request. + """ + + # NOTE: The path and "path info" are mostly equivalent for Twisted. + + return self.trans.postpath + def get_path_info(self): """ @@ -82,7 +92,7 @@ request. """ - raise NotImplementedError, "get_path_info" + return self.trans.postpath # Higher level request-related methods. @@ -115,7 +125,7 @@ the transaction. """ - return self.trans.content + return self.trans def set_content_type(self, content_type): @@ -124,8 +134,6 @@ response. """ - # Make sure that only ASCII is used in the header. - - self.trans.setHeader("Content-Type", content_type.encode("US-ASCII")) + self.trans.setHeader("Content-Type", self.format_content_type(content_type)) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 8e718b119865 -r 95501d8e090b WebStack/Webware.py --- a/WebStack/Webware.py Thu Jan 29 23:42:47 2004 +0000 +++ b/WebStack/Webware.py Sun Feb 01 15:28:08 2004 +0000 @@ -80,6 +80,14 @@ return self.trans.request().contentLanguages() + def get_path(self): + + """ + A framework-specific method which gets the entire path from the request. + """ + + raise NotImplementedError, "get_path" + def get_path_info(self): """ @@ -128,8 +136,6 @@ response. """ - # Make sure that only ASCII is used in the header. - - return self.trans.response().setHeader("Content-Type", content_type.encode("US-ASCII")) + return self.trans.response().setHeader("Content-Type", self.format_content_type(content_type)) # vim: tabstop=4 expandtab shiftwidth=4