# glance.common.wsgi module

Utility methods for working with WSGI applications

class glance.common.wsgi.APIMapper(controller_scan=<function controller_scan>, directory=None, always_scan=False, register=True, explicit=True)

  Bases: `Mapper`

  Handle route matching when url is ‘’ because routes.Mapper returns an error in this case.

  routematch(url=None, environ=None)

    Match a URL against against one of the routes contained.

    Will return None if no valid match is found, otherwise a result dict and a route object is returned.

        resultdict, route_obj = m.match('/joe/sixpack')

class glance.common.wsgi.Debug(application)

  Bases: `Middleware`

  Helper class that can be inserted into any WSGI application chain to get information about the request and response.

  static print_generator(app_iter)

    Iterator that prints the contents of a wrapper string iterator when iterated.

class glance.common.wsgi.JSONRequestDeserializer

  Bases: `object`

  default(request)
  from_json(datastring)
  has_body(request)

    Returns whether a Webob.Request object will possess an entity body.

    Parameters:

      request – Webob.Request object

  httpverb_may_have_body = frozenset({'PATCH', 'POST', 'PUT'})
  classmethod is_valid_encoding(request)
  classmethod is_valid_method(request)
  valid_transfer_encoding = frozenset({'chunked', 'compress', 'deflate', 'gzip', 'identity'})

class glance.common.wsgi.JSONResponseSerializer

  Bases: `object`

  default(response, result)
  to_json(data)

class glance.common.wsgi.Middleware(application)

  Bases: `object`

  Base WSGI middleware wrapper. These classes require an application to be initialized that will be called next. By default the middleware will simply call its wrapped app, or you can override __call__ to customize its behavior.

  classmethod factory(global_conf, **local_conf)
  process_request(req)

    Called on each request.

    If this returns None, the next application down the stack will be executed. If it returns a response then that response will be returned and execution will stop here.

  process_response(response)

    Do whatever you’d like to the response.

class glance.common.wsgi.RejectMethodController

  Bases: `object`

  reject(req, allowed_methods, *args, **kwargs)

class glance.common.wsgi.Request(environ, *args, **kwargs)

  Bases: `Request`

  Add some OpenStack API-specific logic to the base webob.Request.

  best_match_content_type()

    Determine the requested response content-type.

  best_match_language()

    Determines best available locale from the Accept-Language header.

    Returns:

      the best language match or None if the ‘Accept-Language’ header was not available in the request.

  property body_file

    Input stream of the request (wsgi.input). Setting this property resets the content_length and seekable flag (unlike setting req.body_file_raw).

  get_content_type(allowed_content_types)

    Determine content type of the request body.

  get_range_from_request(image_size)

    Return the Range in a request.

class glance.common.wsgi.Resource(controller, deserializer=None, serializer=None)

  Bases: `object`

  WSGI app that handles (de)serialization and controller dispatch.

  Reads routing information supplied by RoutesMiddleware and calls the requested action method upon its deserializer, controller, and serializer. Those three objects may implement any of the basic controller action methods (create, update, show, index, delete) along with any that may be specified in the api router. A ‘default’ method may also be implemented to be used in place of any non-implemented actions. Deserializer methods must accept a request argument and return a dictionary. Controller methods must accept a request argument. Additionally, they must also accept keyword arguments that represent the keys returned by the Deserializer. They may raise a webob.exc exception or return a dict, which will be serialized by requested content type.

  dispatch(obj, action, *args, **kwargs)

    Find action-specific method on self and call it.

  get_action_args(request_environment)

    Parse dictionary created by routes library.

class glance.common.wsgi.Router(mapper)

  Bases: `object`

  WSGI middleware that maps incoming requests to WSGI apps.

  classmethod factory(global_conf, **local_conf)

glance.common.wsgi.translate_exception(req, e)

  Translates all translatable elements of the given exception.

this page last updated: 2026-08-19 03:42:39

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.

found an error? report a bug