Internal Python API

Configuration

Logging configuration routines.

sr.comp.http.config.configure_logging(logging_ini: str) None[source]

Configure logging from a file.

sr.comp.http.config.configure_logging_relative(logging_ini: str) None[source]

Configure logging from a relative file.

Errors

exception sr.comp.http.errors.UnknownMatchFilter(name: str)[source]

Bases: BadRequest

description: str | None = 'Unknown match filter.'

Escaping Formatter

class sr.comp.http.escaping_formatter.EscapingFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]

Bases: Formatter

A 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: JSONEncoder

A 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 a TypeError).

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 the default, ensure_ascii, and sort_keys attributes.

Parameters:
  • obj – The data to serialize.

  • kwargs – Passed to json.dumps().

Manager

Routines for managing a Compstate instance.

class sr.comp.http.manager.SRCompManager[source]

Bases: object

An SRComp manager.

get_comp() SRComp[source]
update_time: float | None

The last time we updated our information.

sr.comp.http.manager.exclusive_lock(lock_path: str) IO[str][source]
sr.comp.http.manager.share_lock(lock_path: str) IO[str][source]
sr.comp.http.manager.touch_update_file(compstate_path: str) None[source]
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.

sr.comp.http.manager.update_lock_path(compstate_path: str) str[source]
sr.comp.http.manager.update_pls_path(compstate_path: str) str[source]

Query Utilities

Various utils for working with HTTP.

class sr.comp.http.query_utils.KnockoutMatchInfo[source]

Bases: MatchInfo

arena: ArenaName
display_name: str
knockout_bracket: str
num: MatchNumber
scores: NotRequired[LeagueMatchScore | KnockoutMatchScore]
teams: list[TLA | None]
times: MatchTimings
type: str
class sr.comp.http.query_utils.KnockoutMatchScore[source]

Bases: TypedDict

game: Mapping[TLA, GamePoints]
normalised: Mapping[TLA, LeaguePoints]
ranking: Mapping[TLA, RankedPosition]
class sr.comp.http.query_utils.LeagueMatchScore[source]

Bases: TypedDict

game: Mapping[TLA, GamePoints]
league: Mapping[TLA, LeaguePoints]
ranking: Mapping[TLA, RankedPosition]
class sr.comp.http.query_utils.MatchInfo[source]

Bases: TypedDict

arena: ArenaName
display_name: str
num: MatchNumber
scores: NotRequired[LeagueMatchScore | KnockoutMatchScore]
teams: list[TLA | None]
times: MatchTimings
type: str
class sr.comp.http.query_utils.MatchTimings[source]

Bases: TypedDict

game: Times
slot: Times
staging: StagingTimes
class sr.comp.http.query_utils.StagingTimes[source]

Bases: TypedDict

closes: str
opens: str
signal_shepherds: dict[ShepherdName, str]
signal_teams: str
class sr.comp.http.query_utils.Times[source]

Bases: TypedDict

end: str
start: str
sr.comp.http.query_utils.match_json_info(comp: SRComp, match: Match) MatchInfo | KnockoutMatchInfo[source]

Get match JSON information.

Parameters:
  • comp (sr.comp.comp.SRComp) – A competition instance.

  • match (sr.comp.match_periods.Match) – A match.

Returns:

A dict containing JSON suitable output.

Return type:

dict

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 True if it is in the difference.

Server

sr.comp.http.server.after_request(resp: Response) Response[source]
sr.comp.http.server.arenas() Response[source]
sr.comp.http.server.before_request() None[source]
sr.comp.http.server.config() Response[source]
sr.comp.http.server.corners() Response[source]
sr.comp.http.server.current_state() Response[source]
sr.comp.http.server.error_handler(e: HTTPException) HTTPException | tuple[Response, int][source]
sr.comp.http.server.format_arena(arena: Arena) dict[str, Any][source]
sr.comp.http.server.format_corner(corner: Corner) dict[str, Any][source]
sr.comp.http.server.format_location(location: Region) dict[str, Any][source]
sr.comp.http.server.get_arena(name: str) Response[source]
sr.comp.http.server.get_config_dict(comp: SRComp) dict[str, Any][source]
sr.comp.http.server.get_corner(number: int) Response[source]
sr.comp.http.server.get_location(name: str) Response[source]
sr.comp.http.server.get_team(tla: str) Response[source]
sr.comp.http.server.get_team_image(tla: str) Response[source]
sr.comp.http.server.knockout() Response[source]
sr.comp.http.server.knockout_structure() Response[source]
sr.comp.http.server.last_scored_match() Response[source]
sr.comp.http.server.locations() Response[source]
sr.comp.http.server.match_periods() Response[source]
sr.comp.http.server.matches() Response[source]
sr.comp.http.server.root() Response[source]
sr.comp.http.server.state() Response[source]
sr.comp.http.server.team_info(comp: SRComp, team: Team) dict[str, Any][source]
sr.comp.http.server.teams() Response[source]
sr.comp.http.server.tiebreaker() Response[source]