Internal Python API¶
Configuration¶
Logging configuration routines.
Errors¶
Escaping Formatter¶
- class sr.comp.http.escaping_formatter.EscapingFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]¶
Bases:
FormatterA class that formats log output nicely.
- format(record: LogRecord) str[source]¶
Format the specified record as text.
The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.
JSON Provider¶
JSON formatting routines.
- class sr.comp.http.json_provider.JsonEncoder(*args: Any, **kwargs: Any)[source]¶
Bases:
JSONEncoderA JSON encoder that deals with various types used in SRComp.
- default(obj: object) Any[source]¶
Implement this method in a subclass such that it returns a serializable object for
o, or calls the base implementation (to raise aTypeError).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) return JSONEncoder.default(self, o)
- class sr.comp.http.json_provider.JsonProvider(app: App)[source]¶
Bases:
DefaultJSONProvider- dumps(*args: Any, **kwargs: Any) str[source]¶
Serialize data as JSON to a string.
Keyword arguments are passed to
json.dumps(). Sets some parameter defaults from thedefault,ensure_ascii, andsort_keysattributes.- Parameters:
obj – The data to serialize.
kwargs – Passed to
json.dumps().
Manager¶
Routines for managing a Compstate instance.
- sr.comp.http.manager.update_lock(compstate_path: str) Iterator[None][source]¶
Acquire a lock on the given compstate for the purposes of updating it.
- Returns:
A context manager object which will remove the lock when __exit__ed and, if a clean exit, touch the update file. In turn that triggers the manager to re load the information it has.
Query Utilities¶
Various utils for working with HTTP.
- class sr.comp.http.query_utils.KnockoutMatchInfo[source]¶
Bases:
MatchInfo- arena: ArenaName¶
- num: MatchNumber¶
- scores: NotRequired[LeagueMatchScore | KnockoutMatchScore]¶
- times: MatchTimings¶
- class sr.comp.http.query_utils.MatchInfo[source]¶
Bases:
TypedDict- arena: ArenaName¶
- num: MatchNumber¶
- scores: NotRequired[LeagueMatchScore | KnockoutMatchScore]¶
- times: MatchTimings¶
- class sr.comp.http.query_utils.MatchTimings[source]¶
Bases:
TypedDict- staging: StagingTimes¶
- sr.comp.http.query_utils.match_json_info(comp: SRComp, match: Match) MatchInfo | KnockoutMatchInfo[source]¶
Get match JSON information.
- sr.comp.http.query_utils.parse_difference_string(string: str, type_converter: Callable[[str], TParseable]) Callable[[TParseable], bool][source]¶
- sr.comp.http.query_utils.parse_difference_string(string: str, type_converter: Callable[[str], int] = int) Callable[[int], bool]
Parse a difference string (x..x, ..x, x.., x) and return a function that accepts a single argument and returns
Trueif it is in the difference.