diff options
author | bbangert <devnull@localhost> | 2006-03-09 02:08:53 +0000 |
---|---|---|
committer | bbangert <devnull@localhost> | 2006-03-09 02:08:53 +0000 |
commit | 9f1d5b07ae899c7fc33cceda9da7754eab787c36 (patch) | |
tree | 89471e0bf1211f2c3de1f63d33f2b718215254ad /paste/request.py | |
parent | 6c8e6d1c1dfc626d7e80e1c6dc732fb68fa472b8 (diff) | |
download | paste-9f1d5b07ae899c7fc33cceda9da7754eab787c36.tar.gz |
Updated to be a bit more simple since only retrieving was needed
Diffstat (limited to 'paste/request.py')
-rw-r--r-- | paste/request.py | 147 |
1 files changed, 65 insertions, 82 deletions
diff --git a/paste/request.py b/paste/request.py index 1c9c8de..e6284ee 100644 --- a/paste/request.py +++ b/paste/request.py @@ -357,8 +357,9 @@ class WSGIRequest(object): """ - def __init__(self, environ): + def __init__(self, environ, urlvars={}): self.environ = environ + self.urlvars = urlvars scheme = environ_getter('wsgi.url_scheme') # ? method = environ_getter('REQUEST_METHOD') @@ -372,81 +373,65 @@ class WSGIRequest(object): # SERVER_PORT? Maybe # SERVER_PROTOCOL, SERVER_SOFTWARE, GATEWAY_INTERFACE? Definitely not - def host(): - doc = textwrap.dedent("""\ - Host name provided in HTTP_HOST, with fall-back to - SERVER_NAME - """) - def fget(self): - return self.environ.get('HTTP_HOST', - self.environ.get('SERVER_NAME')) - return locals() - host = property(**host()) - - def get(): - doc = textwrap.dedent("""\ - Dictionary-like object representing the QUERY_STRING - parameters. Always present, if possibly empty. - - If the same key is present in the query string multiple - times, it will be present as a list. - """) - def fget(self): - return parse_dict_querystring(self.environ) - return locals() - get = property(**get()) - - def post(): - doc = textwrap.dedent("""\ - Dictionary-like object representing the POST body. - - Most values are strings, but file uploads can be FieldStorage - objects. If this is not a POST request, or the body is not - encoded fields (e.g., an XMLRPC request) then this will be None. - - This will consume wsgi.input when first accessed if applicable, - but the output will be put in environ['paste.post_vars'] - """) - def fget(self): - formvars = MultiDict() - formvars.update(parse_formvars(self.environ, all_as_list=True, include_get_vars=False)) - return formvars - fget = LazyCache(fget) - return locals() - post = property(**post()) - - def params(): - doc = textwrap.dedent("""\ - MultiDict of keys from POST, GET, URL dicts - - Return a key value from the parameters, they are checked in the - following order: - POST, GET, URL - - Additional methods supported: - - getlist(key) - Returns a list keyed by parameter location of all the - values by that key in that parameter location - """) - def fget(self): - pms = MultiDict() - pms.update(self.post) - pms.update(self.get) - return pms - fget = LazyCache(fget) - return locals() - params = property(**params()) - - def urlvars(): - doc = textwrap.dedent("""\ - Return a plain dictionary representing any variables - captured from the URL parsing (the parsed URL portion is in - SCRIPT_NAME); frequently {}, but never None""") - def fget(self): - pass - return locals() - urlvars = property(**urlvars()) + def host(self): + """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 get(self): + """ + Dictionary-like object representing the QUERY_STRING + parameters. Always present, if possibly empty. + + If the same key is present in the query string multiple + times, it will be present as a list. + """ + return parse_dict_querystring(self.environ) + get = property(get, doc=get.__doc__) + + def post(self): + """Dictionary-like object representing the POST body. + + Most values are strings, but file uploads can be FieldStorage + objects. If this is not a POST request, or the body is not + encoded fields (e.g., an XMLRPC request) then this will be None. + + This will consume wsgi.input when first accessed if applicable, + but the output will be put in environ['paste.post_vars'] + + """ + formvars = MultiDict() + formvars.update(parse_formvars(self.environ, all_as_list=True, include_get_vars=False)) + return formvars + post = property(LazyCache(post), doc=post.__doc__) + + def params(self): + """MultiDict of keys from POST, GET, URL dicts + + Return a key value from the parameters, they are checked in the + following order: + POST, GET, URL + + Additional methods supported: + + getlist(key) + Returns a list keyed by parameter location of all the values by + that key in that parameter location + """ + pms = MultiDict() + pms.update(self.post) + pms.update(self.get) + return pms + params = property(params, doc=params.__doc__) + + def urlvars(self): + """ + Return a plain dictionary representing any variables + captured from the URL parsing (the parsed URL portion is in + SCRIPT_NAME); frequently {}, but never None + """ + return self.urlvars + urlvars = property(urlvars, doc=urlvars.__doc__) def cookies(self): """Dictionary of cookies keyed by cookie name. @@ -456,12 +441,10 @@ class WSGIRequest(object): """ pass - def headers(): - doc = """Access to incoming headers""" - def fget(self): - pass - return locals() - headers = property(**headers()) + def headers(self): + """Access to incoming headers""" + pass + headers = property(headers, doc=headers.__doc__) if __name__ == '__main__': import doctest |