twine.utils module¶
- twine.utils.get_config(path: str) Dict[str, Dict[str, str | None]] [source]¶
Read repository configuration from a file (i.e. ~/.pypirc).
Format: https://packaging.python.org/specifications/pypirc/
If the default config file doesn’t exist, return a default configuration for pypyi and testpypi.
- twine.utils.sanitize_url(url: str) str [source]¶
Sanitize a URL.
Sanitize URLs, removing any user:password combinations and replacing them with asterisks. Returns the original URL if the string is a non-matching pattern.
- Parameters:
url – str containing a URL to sanitize.
- return:
str either sanitized or as entered depending on pattern match.
- twine.utils._validate_repository_url(repository_url: str) None [source]¶
Validate the given url for allowed schemes and components.
- twine.utils.get_repository_from_config(config_file: str, repository: str, repository_url: str | None = None) Dict[str, str | None] [source]¶
Get repository config command-line values or the .pypirc file.
- twine.utils.get_file_size(filename: str) str [source]¶
Return the size of a file in KB, or MB if >= 1024 KB.
- twine.utils.check_status_code(response: Response, verbose: bool) None [source]¶
Generate a helpful message based on the response from the repository.
Raise a custom exception for recognized errors. Otherwise, print the response content (based on the verbose option) before re-raising the HTTPError.
- twine.utils.get_userpass_value(cli_value: str | None, config: Dict[str, str | None], key: str, prompt_strategy: Callable[[], str] | None = None) str | None [source]¶
Get a credential (e.g. a username or password) from the configuration.
Uses the following rules:
If
cli_value
is specified, use that.If
config[key]
is specified, use that.If
prompt_strategy
is specified, use its return value.Otherwise return
None
- Parameters:
cli_value – The value supplied from the command line.
config – A dictionary of repository configuration values.
key – The credential to look up in
config
, e.g."username"
or"password"
.prompt_strategy – An argumentless function to get the value, e.g. from keyring or by prompting the user.
- Returns:
The credential value, i.e. the username or password.
- twine.utils.get_cacert(cli_value: str | None, config: Dict[str, str | None], *, key: str = 'ca_cert', prompt_strategy: Callable[[], str] | None = None) str | None ¶
Get the CA bundle via
get_userpass_value()
.
- twine.utils.get_clientcert(cli_value: str | None, config: Dict[str, str | None], *, key: str = 'client_cert', prompt_strategy: Callable[[], str] | None = None) str | None ¶
Get the client certificate via
get_userpass_value()
.