webtools.request

HTTP request objects. Ported from webapp2, refactored to support Python versions > 2.7, 3.0

class webtools.request.Request(environ, *args, **kwargs)

Abstraction for an HTTP request.

Most extra methods and attributes are ported from webapp. Check the WebOb documentation for the ones not listed here.

app = None

A reference to the active WSGIApplication instance.

response = None

A reference to the active Response instance.

route = None

A reference to the matched Route.

route_args = None

The matched route positional arguments.

route_kwargs = None

The matched route keyword arguments.

registry = None

A dictionary to register objects used during the request lifetime.

get(argument_name, default_value='')

Returns the query or POST argument with the given name.

We parse the query string and POST payload lazily, so this will be a slower operation on the first call.

Parameters:
  • argument_name – The name of the GET, POST, PUT or DELETE argument.
  • default_value – The value to return if the given argument is not present.
Returns:

Returns the first value with the given name given in the request. Use the get_all method to return a list of all values with the specified argument name.

get_all(argument_name, default_value=None)

Returns a list of query or POST arguments with the given name.

We parse the query string and POST payload lazily, so this will be a slower operation on the first call.

Parameters:
  • argument_name – The name of the query or POST argument.
  • default_value – The value to return if the given argument is not present, None may not be used as a default, if it is then an empty list will be returned instead.
Returns:

A (possibly empty) list of values.

arguments()

Returns a list of the arguments provided in the query and/or POST.

The return value is a list of strings.

get_range(name, min_value=None, max_value=None, default=0)

Parses the given int argument, limiting it to the given range.

Parameters:
  • name – The name of the argument.
  • min_value – The minimum int value of the argument (if any).
  • max_value – The maximum int value of the argument (if any).
  • default – The default value of the argument if it is not given.
Returns:

An int within the given range for the argument.

classmethod blank(path, environ=None, base_url=None, headers=None, **kwargs)

Adds parameters compatible with WebOb >= 1.0: POST and **kwargs.

ResponseClass

alias of Response

class webtools.request.RequestContext(app, environ)

Context for a single request.

The context is responsible for setting and cleaning global variables for a request.

app = None

A WSGIApplication instance.

environ = None

WSGI environment dictionary.

Previous topic

webtools.helpers

Next topic

webtools.response

This Page