1.1 --- a/WebStack/Generic.py Thu Jan 29 23:42:47 2004 +0000
1.2 +++ b/WebStack/Generic.py Sun Feb 01 15:28:08 2004 +0000
1.3 @@ -19,7 +19,7 @@
1.4
1.5 "A container for content type information."
1.6
1.7 - def __init__(self, content_type, charset):
1.8 + def __init__(self, content_type, charset=None):
1.9 self.content_type = content_type
1.10 self.charset = charset
1.11
1.12 @@ -48,6 +48,22 @@
1.13 else:
1.14 return ContentType(t[0], t[1])
1.15
1.16 + def format_content_type(self, content_type):
1.17 +
1.18 + """
1.19 + Format the given 'content_type' object, producing a string suitable for
1.20 + the response header field.
1.21 + """
1.22 +
1.23 + if content_type.charset:
1.24 + field = "%s; charset=%s" % (content_type.content_type, content_type.charset)
1.25 + else:
1.26 + field = content_type.content_type
1.27 +
1.28 + # Make sure that only ASCII is used in the header.
1.29 +
1.30 + return field.encode("US-ASCII")
1.31 +
1.32 def parse_content_preferences(self, accept_preference):
1.33
1.34 """
1.35 @@ -122,6 +138,14 @@
1.36
1.37 raise NotImplementedError, "get_content_languages"
1.38
1.39 + def get_path(self):
1.40 +
1.41 + """
1.42 + A framework-specific method which gets the entire path from the request.
1.43 + """
1.44 +
1.45 + raise NotImplementedError, "get_path"
1.46 +
1.47 def get_path_info(self):
1.48
1.49 """
2.1 --- a/WebStack/ModPython.py Thu Jan 29 23:42:47 2004 +0000
2.2 +++ b/WebStack/ModPython.py Sun Feb 01 15:28:08 2004 +0000
2.3 @@ -73,6 +73,14 @@
2.4
2.5 return self.parse_content_preferences(self.trans.headers_in["Accept-Language"])
2.6
2.7 + def get_path(self):
2.8 +
2.9 + """
2.10 + A framework-specific method which gets the entire path from the request.
2.11 + """
2.12 +
2.13 + return self.trans.uri
2.14 +
2.15 def get_path_info(self):
2.16
2.17 """
2.18 @@ -81,7 +89,7 @@
2.19 request.
2.20 """
2.21
2.22 - raise NotImplementedError, "get_path_info"
2.23 + raise self.trans.path_info
2.24
2.25 # Higher level request-related methods.
2.26
2.27 @@ -121,8 +129,6 @@
2.28 response.
2.29 """
2.30
2.31 - # Make sure that only ASCII is used in the header.
2.32 -
2.33 - self.trans.content_type = content_type.encode("US-ASCII")
2.34 + self.trans.content_type = self.format_content_type(content_type)
2.35
2.36 # vim: tabstop=4 expandtab shiftwidth=4
3.1 --- a/WebStack/Twisted.py Thu Jan 29 23:42:47 2004 +0000
3.2 +++ b/WebStack/Twisted.py Sun Feb 01 15:28:08 2004 +0000
3.3 @@ -27,7 +27,7 @@
3.4 the transaction.
3.5 """
3.6
3.7 - return self.trans
3.8 + return self.trans.content
3.9
3.10 def get_request_method(self):
3.11
3.12 @@ -74,6 +74,16 @@
3.13
3.14 return self.parse_content_preferences(self.trans.getHeader("Accept-Charset"))
3.15
3.16 + def get_path(self):
3.17 +
3.18 + """
3.19 + A framework-specific method which gets the entire path from the request.
3.20 + """
3.21 +
3.22 + # NOTE: The path and "path info" are mostly equivalent for Twisted.
3.23 +
3.24 + return self.trans.postpath
3.25 +
3.26 def get_path_info(self):
3.27
3.28 """
3.29 @@ -82,7 +92,7 @@
3.30 request.
3.31 """
3.32
3.33 - raise NotImplementedError, "get_path_info"
3.34 + return self.trans.postpath
3.35
3.36 # Higher level request-related methods.
3.37
3.38 @@ -115,7 +125,7 @@
3.39 the transaction.
3.40 """
3.41
3.42 - return self.trans.content
3.43 + return self.trans
3.44
3.45 def set_content_type(self, content_type):
3.46
3.47 @@ -124,8 +134,6 @@
3.48 response.
3.49 """
3.50
3.51 - # Make sure that only ASCII is used in the header.
3.52 -
3.53 - self.trans.setHeader("Content-Type", content_type.encode("US-ASCII"))
3.54 + self.trans.setHeader("Content-Type", self.format_content_type(content_type))
3.55
3.56 # vim: tabstop=4 expandtab shiftwidth=4
4.1 --- a/WebStack/Webware.py Thu Jan 29 23:42:47 2004 +0000
4.2 +++ b/WebStack/Webware.py Sun Feb 01 15:28:08 2004 +0000
4.3 @@ -80,6 +80,14 @@
4.4
4.5 return self.trans.request().contentLanguages()
4.6
4.7 + def get_path(self):
4.8 +
4.9 + """
4.10 + A framework-specific method which gets the entire path from the request.
4.11 + """
4.12 +
4.13 + raise NotImplementedError, "get_path"
4.14 +
4.15 def get_path_info(self):
4.16
4.17 """
4.18 @@ -128,8 +136,6 @@
4.19 response.
4.20 """
4.21
4.22 - # Make sure that only ASCII is used in the header.
4.23 -
4.24 - return self.trans.response().setHeader("Content-Type", content_type.encode("US-ASCII"))
4.25 + return self.trans.response().setHeader("Content-Type", self.format_content_type(content_type))
4.26
4.27 # vim: tabstop=4 expandtab shiftwidth=4