Navigation Menu

Skip to content

Commit

Permalink
add self.get_arguments() modeled after self.get_argument() for retrie…
Browse files Browse the repository at this point in the history
…ving multiple url query parameters
  • Loading branch information
jehiah committed Apr 7, 2010
1 parent 70347b6 commit cbe2eeb
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tornado/web.py
Expand Up @@ -198,6 +198,27 @@ def get_argument(self, name, default=_ARG_DEFAULT, strip=True):
if strip: value = value.strip()
return value

def get_arguments(self, name, default=[], strip=True):
"""Returns the value of the arguments with the given name.
If default is not provided, the argument is considered to be
required, and we throw an HTTP 404 exception if it is missing.
The returned values are always unicode.
"""
values = self.request.arguments.get(name, None)
if values is None:
if default is []:
raise HTTPError(404, "Missing argument %s" % name)
return default
# Get rid of any weird control chars
values = [re.sub(r"[\x00-\x08\x0e-\x1f]", " ", x) for x in values]
values = [_unicode(x) for x in values]
if strip:
values = [x.strip() for x in values]
return values


@property
def cookies(self):
"""A dictionary of Cookie.Morsel objects."""
Expand Down

0 comments on commit cbe2eeb

Please sign in to comment.