pyiem.webutil module#
Utility functions for iemwebfarm applications.
- class pyiem.webutil.TELEMETRY(timing, status_code, client_addr, app, request_uri, vhost)#
Bases:
tuple- app#
Alias for field number 3
- client_addr#
Alias for field number 2
- request_uri#
Alias for field number 4
- status_code#
Alias for field number 1
- timing#
Alias for field number 0
- vhost#
Alias for field number 5
- class pyiem.webutil.CGIModel[source]#
Bases:
BaseModelA Pydantic model that parses CGI arguments.
- model_config = {'arbitrary_types_allowed': True}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- pyiem.webutil.model_to_rst(model)[source]#
Convert a Pydantic model to a reStructuredText table.
- Parameters:
model (BaseModel) – The Pydantic model to convert
- Return type:
Returns: A reStructuredText table
- pyiem.webutil.ensure_list(environ, key, parse_commas=True)[source]#
Ensure that we get something that is at least an empty list.
- Parameters:
environ – the WSGI environ
key – the key to look for
parse_commas – split each found value based on commas, default True.
- Return type:
- pyiem.webutil.log_request(environ, multiplier=1)[source]#
Log the request to database for future processing.
- pyiem.webutil.add_to_environ(environ, form, **kwargs)[source]#
Build out some things auto-parsed from the request.
- pyiem.webutil.iemapp(**kwargs)[source]#
Attempt to do all kinds of nice things for the user and the developer.
- kwargs:
default_tz: The default timezone to use for timestamps, the default is
America/Chicago.enable_telemetry: Enable telemetry logging, default
True.help: Default help text, default
Help not available.parse_times: Parse the form for timestamps, default
True.schema (BaseModel): A Pydantic model to parse the form with.
memcachekey (str or callable): A memcache key to use for caching the response. If the callable returns None, no caching is done.
memcacheexpire (int or callable): The number of seconds to cache the response, defaults to 3600.
content_type (str or callable): The content type to use for the response.
allowed_as_list (list): CGI parameters that are permitted to be lists.
- What all this does:
Attempts to catch database connection errors and handle nicely
Updates environ with some auto-parsed values + form content.
If the wrapped function returns a str or bytes, it will be encoded and made into a list for the WSGI response.
Notes
raise NoDataFound to have a nice error message generated