types - basic types¶
This module contains a collection of various basic types and classes used throughout the package.
- class SortedStack[source]¶
Bases:
Sized,IterableA sorted collection (stack) of items.
>>> stack = SortedStack({'dogs': 12, 'sobaki': 5}) >>> stack = SortedStack(stack) >>> stack.extend(SortedStack({'cats': 5}))
Selection:
>>> stack.select(8) ['sobaki', 'cats']
>>> stack.rselect(8) ['dogs']
Insertion and removal:
>>> stack.insert(1, 'koty') >>> stack.pop_many(3) ['koty']
>>> stack.pop() 'sobaki'
>>> len(stack) 2
>>> stack.clear() >>> bool(stack) False
- property lowest_score¶
Get the lowest score in the stack.
- select(score_threshold, /) list[source]¶
Select and return items without removing them from the lowest score to score_threshold.
The values are guaranteed to be in order.
- rselect(score_threshold, /) list[source]¶
Select and return items without removing them from the highest score to score_threshold.
The values are guaranteed to be in order.
- pop()[source]¶
Pop a single element which has the lowest score.
- Raises:
StopIteration – if there are no values to return.
- rpop()[source]¶
Pop a single element which has the highest score.
- Raises:
StopIteration – if there are no values to return.
- pop_many(score_threshold, /) list[source]¶
Pop and return values with scores less than score_threshold.
The returned values are guaranteed to be in order. Returns an empty list if no values.
- class RestrictedDict[source]¶
Bases:
dictSame as a normal mapping but forbids key updates.
>>> m = RestrictedDict(a=1, b=2) >>> m['c'] = 3 >>> 'c' in m True
Resetting a key raises a ValueError:
>>> m['c'] = 5 Traceback (most recent call last): ... ValueError:
>>> m.update({'c': 5}) Traceback (most recent call last): ... NotImplementedError:
So as trying to remove it:
>>> m.pop('c') Traceback (most recent call last): ... NotImplementedError:
- class Namespace[source]¶
Bases:
MappingNamespace can be used for shared key and name management.
Create namespaces.
>>> ns = Namespace(env='dev', name='app') >>> sub_ns = ns / 'sub' # eq to .create_namespace('sub') >>> str(sub_ns) 'dev.app.sub'
Get keys.
>>> sub_ns.get_key('key') 'dev.app.sub.key'
- env: str¶
Environment: dev, prod, etc.
- name: str¶
Application or scope name.
- namespaces: dict[str, kaiju_tools.types.Namespace]¶
Sub-namespaces.
- classmethod join(*args)[source]¶
Join arguments in a namespace key.
You should use NSKey.get_key instead of this when possible.
- __init__(env: str, name: str) None¶
- class RequestContext[source]¶
Bases:
TypedDictRequest context for an RPC request.
Each request going through the RPC server has a unique context assigned to the context variable.
- correlation_id: str¶
request chain correlation id header
- session_id: str | None¶
user session id
- request_deadline: int | None¶
unix time deadline for this request chain
- data: dict | None¶
arbitrary user data
- class Session[source]¶
Bases:
SerializableUser session data.
- __init__(*, id: str, h_agent: bytes | None, user_id: UUID | None, expires: int, permissions: frozenset[str], data: dict, created: datetime, _stored: bool, _changed: bool, _loaded: bool)[source]¶
Initialize.
- Parameters:
id – session id
h_agent – user agent hash
user_id – user id in users table
expires – unix timestamp when this session should expire
permissions – a set of session-bound permissions
data – additional stored data
created – timestamp
- user_id¶
current user (or None)
- expires¶
expiration unix timestamp
- permissions¶
a set of user permissions
- data¶
session data
- property stored: bool¶
Session should be stored.
- property changed: bool¶
Session has changed.
- property loaded: bool¶
Session has been loaded from db.