diff options
author | bbangert <devnull@localhost> | 2007-01-31 23:23:04 +0000 |
---|---|---|
committer | bbangert <devnull@localhost> | 2007-01-31 23:23:04 +0000 |
commit | 3cf9d7b924258f7a43f44941301fec33ca4b9281 (patch) | |
tree | a916e5a15418e3559543ecdcd8bcf3cfa72869d1 /paste/wsgiwrappers.py | |
parent | 23c338c931b0f905ad1d8e4bf09d4cb47f6039ec (diff) | |
download | paste-3cf9d7b924258f7a43f44941301fec33ca4b9281.tar.gz |
Switching mime-type parsing to be a WSGIRequest function instead of attribute.
Diffstat (limited to 'paste/wsgiwrappers.py')
-rw-r--r-- | paste/wsgiwrappers.py | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/paste/wsgiwrappers.py b/paste/wsgiwrappers.py index 587c5ae..50646e6 100644 --- a/paste/wsgiwrappers.py +++ b/paste/wsgiwrappers.py @@ -73,13 +73,9 @@ class WSGIRequest(object): specified by the client. The class variable ``defaults`` specifies default values for - ``charset``, ``errors``, ``mimetypes``, and ``langauge``. These can be - overridden for the current request via the registry. - - The ``mimetypes`` option should be a list of mime-types in their desired - order. This determines the valid mime-types in order based on what the - browser declared it can accept via the HTTP Accept header. - + ``charset``, ``errors``, and ``langauge``. These can be overridden for the + current request via the registry. + The ``language`` default value is considered the fallback during i18n translations to ensure in odd cases that mixed languages don't occur should the ``language`` file contain the string but not another language in the @@ -102,7 +98,6 @@ class WSGIRequest(object): """ defaults = StackedObjectProxy(default=dict(charset=None, errors='strict', decode_param_names=False, - mimetypes=['text/html'], language='en-us')) def __init__(self, environ): self.environ = environ @@ -120,7 +115,6 @@ class WSGIRequest(object): self.errors = defaults.get('errors', 'strict') self.decode_param_names = defaults.get('decode_param_names', False) self._languages = None - self._mimetypes = None body = environ_getter('wsgi.input') scheme = environ_getter('wsgi.url_scheme') @@ -138,17 +132,6 @@ class WSGIRequest(object): """Host name provided in HTTP_HOST, with fall-back to SERVER_NAME""" return self.environ.get('HTTP_HOST', self.environ.get('SERVER_NAME')) host = property(host, doc=host.__doc__) - - def mimetypes(self): - """Return a list of developer-specified mime-types that the browser's - HTTP Accept header allows in the order provided by - defaults['mimetypes']""" - if self._mimetypes is not None: - return self._mimetypes - mytypes = self.defaults.get('mimetypes', ['text/html']) - self._mimetypes = desired_matches(mytypes, self.environ.get('HTTP_ACCEPT', '*/*')) - return self._mimetypes - mimetypes = property(mimetypes, doc=mimetypes.__doc__) def languages(self): """Return a list of preferred languages, most preferred first. @@ -263,6 +246,12 @@ class WSGIRequest(object): if charset_match: return charset_match.group(1) + def match_accept(self, mimetypes): + """Return a list of specified mime-types that the browser's HTTP Accept + header allows in the order provided.""" + return desired_matches(mimetypes, + self.environ.get('HTTP_ACCEPT', '*/*')) + class WSGIResponse(object): """A basic HTTP response with content, headers, and out-bound cookies |