Base Request Handler
Specific abilities
self.rate_limiters
Array of
q2_sdk.core.RateLimiter
instances. Allows for limiting traffic to the extension either by ip (segment_by_ip=True) or globally (segment_by_ip=False)Useful for mitigating Distributed Denial of Service (DDoS) attacks
- class q2_sdk.core.http_handlers.base_handler.Q2BaseRequestHandler(application, request, **kwargs)[source]
Bases:
RequestHandler
Inherits from Tornado’s RequestHandler, but adds a few Q2 specific niceties.
Handles both gets and posts
If REQUIRED_CONFIGURATIONS is set, ensures the entries are set in the extension’s settings file or the webserver will not start.
REQUIRED_CONFIGURATIONS is a dictionary of key value pairs where the key is the required name and the value is the default value when
q2 generate_config
is calledIf DYNAMIC_CORE_SELECTION is set to True, will prompt for a Core name on installation
OPTIONAL_CONFIGURATIONS work the same was as REQUIRED_CONFIGURATIONS, but will not stop the server from running if omitted
FRONTEND_OVERRIDE_EXTENSION allows using another extension as the frontend for this one
- data_received(_)[source]
Implement this method to handle streamed request data.
Requires the
stream_request_body
decorator.May be a coroutine for flow control.
- async run_async(funcname, *args, **kwargs)[source]
Easy way to run a non_async function in a background thread
Usage:
- def non_async_func(foo, spam=”eggs”):
time_consuming_thing()
await self.run_async(non_async_func, 1, spam=”eggs”)
- Parameters:
funcname (
Callable
) – Function reference (do not instantiate)args – Positional parameters
kwargs – Keyword parameters
- property core: BaseCore
Instantiates a communication object between this extension and the core listed in configuration.settings.CORE Must pip install q2_cores or populate settings.CUSTOM_CORES for this to be accessible
- Returns:
Subclass of q2_sdk.models.cores.BaseCore
- property cache: Q2CacheClient
Instantiates a communication object between this extension and the pymemcache library. Cache can be configured via configuration.settings.CACHE.
This is a factory that instantiates the cache in self.default_cache_level. There is also self.stack_cache, self.service_cache, or self.session_cache for direct access based on your context.
- property service_cache: Q2CacheClient[source]
Q2CacheClient scoped to the loadbalanced running service.
- property stack_cache: Q2CacheClient[source]
Q2CacheClient scoped to the current financial institution stack.
- property session_cache: Q2CacheClient[source]
Same as self.cache but limited to online user session
- get_cache(prefix=None, **kwargs)[source]
- Parameters:
prefix – If defined will be prepended to all keys
- Return type:
- property base_assets_url
Url to use for creating a fully qualified URL to your extension assets
- async get_ui_text(language=None, ui_selection=None, cache_time=60)[source]
Returns any UI Text elements from the database that were inserted as part of self.DB_PLAN
- Return type:
dict
- async prepare()[source]
Fires before any request handling code
By default, will check any Rate Limiter instances in self.rate_limiters and disallow further processing if any are over their specified limit
- log_exception(typ, value, tb)[source]
Override to customize logging of uncaught exceptions.
By default logs instances of
HTTPError
as warnings without stack traces (on thetornado.general
logger), and all other exceptions as errors with stack traces (on thetornado.application
logger). :rtype:None
Added in version 3.1.
- get_template(template_name, replacements_dict)[source]
Used for loading static blocks of text with substitutions. Great for storing large HTML blocks in separate files. Uses jinja behind the scenes (http://jinja.pocoo.org/)
Will search in all templates folders starting with the calling extension, then moving on to the parent class, and so on, preferring the lowest.
- Parameters:
template_name (
str
) – file_name including suffix. ex. initial.htmlreplacements_dict (
dict
) – Key value pairs to replace within template_name
- Return type:
str
- Returns:
Body of template_name file replaced with values in replacements_dict