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: werkzeug.exceptions.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: logging.Formatter

A class that formats log output nicely.

format(record: logging.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 Encoder

Manager

Routines for managing a Compstate instance.

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

Bases: object

An SRComp manager.

get_comp() sr.comp.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.KnockoutMatchScore[source]

Bases: typing_extensions.TypedDict

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

Bases: typing_extensions.TypedDict

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

Bases: sr.comp.http.query_utils._MatchInfo

arena: sr.comp.types.ArenaName
display_name: str
num: sr.comp.types.MatchNumber
scores: Union[sr.comp.http.query_utils.LeagueMatchScore, sr.comp.http.query_utils.KnockoutMatchScore]
teams: list[typing.Optional[sr.comp.types.TLA]]
times: sr.comp.http.query_utils.MatchTimings
type: str
class sr.comp.http.query_utils.MatchTimings[source]

Bases: typing_extensions.TypedDict

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

Bases: typing_extensions.TypedDict

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

Bases: typing_extensions.TypedDict

end: str
start: str
sr.comp.http.query_utils.match_json_info(comp: sr.comp.comp.SRComp, match: sr.comp.match_period.Match) sr.comp.http.query_utils.MatchInfo[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], sr.comp.http.query_utils.TParseable]) Callable[[sr.comp.http.query_utils.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: flask.wrappers.Response) flask.wrappers.Response[source]
sr.comp.http.server.arenas() flask.wrappers.Response[source]
sr.comp.http.server.before_request() None[source]
sr.comp.http.server.config() flask.wrappers.Response[source]
sr.comp.http.server.corners() flask.wrappers.Response[source]
sr.comp.http.server.current_state() flask.wrappers.Response[source]
sr.comp.http.server.error_handler(e: werkzeug.exceptions.HTTPException) Union[werkzeug.exceptions.HTTPException, tuple[flask.wrappers.Response, int]][source]
sr.comp.http.server.format_arena(arena: sr.comp.arenas.Arena) dict[str, typing.Any][source]
sr.comp.http.server.format_corner(corner: sr.comp.arenas.Corner) dict[str, typing.Any][source]
sr.comp.http.server.format_location(location: sr.comp.types.Region) dict[str, typing.Any][source]
sr.comp.http.server.get_arena(name: str) flask.wrappers.Response[source]
sr.comp.http.server.get_config_dict(comp: sr.comp.comp.SRComp) dict[str, typing.Any][source]
sr.comp.http.server.get_corner(number: int) flask.wrappers.Response[source]
sr.comp.http.server.get_location(name: str) flask.wrappers.Response[source]
sr.comp.http.server.get_team(tla: str) flask.wrappers.Response[source]
sr.comp.http.server.get_team_image(tla: str) flask.wrappers.Response[source]
sr.comp.http.server.knockout() flask.wrappers.Response[source]
sr.comp.http.server.last_scored_match() flask.wrappers.Response[source]
sr.comp.http.server.locations() flask.wrappers.Response[source]
sr.comp.http.server.match_periods() flask.wrappers.Response[source]
sr.comp.http.server.matches() flask.wrappers.Response[source]
sr.comp.http.server.root() flask.wrappers.Response[source]
sr.comp.http.server.state() flask.wrappers.Response[source]
sr.comp.http.server.team_info(comp: sr.comp.comp.SRComp, team: sr.comp.teams.Team) dict[str, typing.Any][source]
sr.comp.http.server.teams() flask.wrappers.Response[source]
sr.comp.http.server.tiebreaker() flask.wrappers.Response[source]