base
Utility functions and types.
The HTTP status codes exported here are spelled out rather than imported from the standard library http client, which is expensive to import under IronPython and is not otherwise needed to describe a request or a response.
Attributes
OK = 200
module-attribute
ACCEPTED = 202
module-attribute
NO_CONTENT = 204
module-attribute
INTERNAL_SERVER_ERROR = 500
module-attribute
DEFAULT_SOURCE = 'pyrevit.routes'
module-attribute
Classes
CaseInsensitiveHeaders(*args, **kwargs)
Bases: dict
A mapping of HTTP header names to values that ignores key case.
HTTP field names are case-insensitive (RFC 9110, section 5.1), but the
casing a handler is handed depends on the engine that parsed the request.
IronPython 2 parses headers into a mimetools.Message, which lower-cases
every field name, while CPython 3 parses them into an
email.message.Message, which preserves the casing the client sent.
Normalizing here is what lets headers.get("Authorization") resolve to the
same value on both engines.
Note
Names are normalized to lower case on the way in, so iterating the mapping yields lower-cased names rather than the ones the client sent.
Invariant
A repeated field name collapses into a single entry. The wire format
lets a client send a name more than once - Cookie and Accept are
routinely repeated - and which of the repeats survives here is decided
by the order the engine reports them in, which IronPython 2 does not
define.
Build the mapping from an optional mapping or iterable of pairs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
An optional mapping, or an iterable of key:value pairs. |
()
|
|
**kwargs
|
Additional header names and values. |
{}
|
Source code in pyrevitlib/pyrevit/routes/server/base.py
Methods:
get(key, default=None)
Look up a header value without regard to the case of the name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Header name. |
required |
default
|
Value returned when the header is absent. |
None
|
Returns:
| Type | Description |
|---|---|
|
The header value, or |
Source code in pyrevitlib/pyrevit/routes/server/base.py
pop(key, *args)
Remove a header and return its value, ignoring the case of the name.
setdefault(key, default=None)
Return the value for a header, setting it to default if it is absent.
Source code in pyrevitlib/pyrevit/routes/server/base.py
update(*args, **kwargs)
Add several headers at once, each name normalized on the way in.
Request(path='/', method='GET', data=None, params=None, query_params=None)
Bases: object
Request wrapper object.
Source code in pyrevitlib/pyrevit/routes/server/base.py
Attributes
path = path
instance-attribute
method = method
instance-attribute
data = data
instance-attribute
headers
property
Request headers, looked up without regard to the case of the name.
params
property
Request parameters.
query_params
property
Request query string parameters as a dictionary.
callback_url
property
Request callback url, if provided in payload.
Methods:
add_header(key, value)
Add new header key:value, replacing any value already held for the name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Header name, matched without regard to case. |
required |
value
|
str
|
Header value. |
required |
Source code in pyrevitlib/pyrevit/routes/server/base.py
Response(status=200, data=None, headers=None)
Bases: object
Response wrapper object.
Source code in pyrevitlib/pyrevit/routes/server/base.py
Attributes
status = status
instance-attribute
data = data
instance-attribute
headers
property
Response headers dict.