API Reference¶
toolforge package¶
Small library for common tasks on Wikimedia Toolforge
- toolforge.assert_private_file(func: Callable[[IO[Any]], Any]) Callable[[IO[Any]], Any][source]¶
Decorator to assert that a file is not world-readable.
- Parameters:
func – callable to decorate
- Raise:
toolforge.PrivateFileWorldReadableError: When func.args[0] is a world readable file.
- toolforge.connect(dbname: str, cluster: str = 'web', *, extension: str | None = None, **kwargs: str) _Connection[source]¶
Get a database connection for the specified wiki.
- Parameters:
dbname – Database name
cluster – Database cluster (analytics or web)
**kwargs – For
pymysql.connect
- Returns:
- Raise:
toolforge.UnknownClusterError: When cluster value is unknown
- toolforge.dbname(domain: str) str[source]¶
Convert a domain/URL into its database name.
- Parameters:
domain – DNS domain or URL to wiki
- Returns:
Wikimedia database name (like enwiki)
- Raises:
toolforge.UnknownDatabaseError: When dbname mapping for domain is unknown
- toolforge.load_private_yaml(stream)¶
Parse the first YAML document in a stream and produce the corresponding Python object.
Resolve only basic YAML tags. This is known to be safe for untrusted input.
If the given stream is a file, additionally assert that it is not world-readable.
- toolforge.set_user_agent(tool: str, url: str | None = None, email: str | None = None) str[source]¶
Set the default requests user-agent to a better one in accordance with [[meta:User-Agent policy]].
- Parameters:
tool – Toolforge tool name
url – Optional URL
email – Optional email
- Returns:
New User-agent value
- toolforge.toolsdb(dbname: str, **kwargs: str) _Connection[source]¶
Connect to a database hosted on the ToolsDB service.
- Parameters:
dbname – Database name
**kwargs – For
pymysql.connect
- Returns:
- exception toolforge.PrivateFileWorldReadableError(f: IO[Any])[source]¶
Raised when a function decorated with
toolforge.assert_private_file()encounters a world-readable file.