owmeta_core.bundle.loaders.http module

exception owmeta_core.bundle.loaders.http.IndexLoadFailed(response)[source]

Bases: Exception

Thrown when the HTTP bundle loader cannot get its index

class owmeta_core.bundle.loaders.http.HTTPBundleLoader(index_url, cachedir=None, hash_preference=('sha224',), **kwargs)[source]

Bases: Loader

Loads bundles from HTTP(S) resources listed in an index file

Parameters
index_urlstr or owmeta_core.bundle.URLConfig

URL for the index file pointing to the bundle archives

cachedirstr, optional

Directory where the index and any downloaded bundle archive should be cached. If provided, the index and bundle archive is cached in the given directory. If not provided, the index will be cached in memory and the bundle will not be cached.

hash_preferencetuple of str

Preference ordering of hashes to use for checking integrity of files. If none match in the preference ordering, then the first one

**kwargs

Passed on to Loader

can_load(bundle_id, bundle_version=None)[source]

Check the index for an entry for the bundle.

  • If a version is given and the index has an entry for the bundle at that version and that entry gives a URL for the bundle, then we return True.

  • If no version is given and the index has an entry for the bundle at any version and that entry gives a URL for the bundle, then we return True.

  • Otherwise, we return False

Parameters
bundle_idstr

ID of the bundle to look for

bundle_versionint, optional

Version number of the bundle to look for. If not provided, then any version is deemed acceptable

Returns
bool

True if the bundle can be loaded; otherwise, False

classmethod can_load_from(ac)[source]

Returns True for http:// or https:// URLConfigs

Parameters
acAccessorConfig

The config which we may be able to load from

class owmeta_core.bundle.loaders.http.HTTPBundleUploader(upload_url, ssl_context=None, max_retries=1)[source]

Bases: Uploader

Uploads bundles by sending bundle archives in HTTP POST requests

Parameters
upload_urlstr or URLConfig

URL string or accessor config

ssl_contextssl.SSLContext, optional

SSL/TLS context to use for the connection. Overrides any context provided in upload_url

max_retriesint, optional

Maximum number of times to retry the upload after a failure.

upload(bundle_path)[source]

Attempt to upload the bundle. Retries will be attempted when BrokenPipeError is thrown by the http client

class owmeta_core.bundle.loaders.http.HTTPSURLConfig(*args, ssl_context_provider=None, ssl_context=None, **kwargs)[source]

Bases: HTTPURLConfig

HTTPS URL configuration

Parameters
*args

Passed on to HTTPURLConfig

ssl_context_providerstr

Path to a callable that provides a ssl.SSLContext. See https_remote

ssl_contextssl.SSLContext

The SSL/TLS context to use for uploading with this accessor

**kwargs

Passed on to HTTPURLConfig

class owmeta_core.bundle.loaders.http.HTTPURLConfig(*args, session_file_name=None, session_provider=None, cache_dir=None, mem_cache=False, **kwargs)[source]

Bases: URLConfig

HTTP URL configuration

Parameters
*args

Passed on to URLConfig

session_file_namestr, optional

Session file name

session_providerstr, optional

Provider path for a callable that returns a session

cache_dirstr, optional

HTTP cache directory. Supersedes mem_cache

mem_cachebool, optional

Whether to use an in-memory cache. Superseded by cache_dir

**kwargs

Passed on to URLConfig

init_session()[source]

Initialize the HTTP session. Typically you won’t call this, but will just access session

property session

A requests.Session

This will be loaded from session_file_name if a value is set for that. Otherwise, the session will either be obtained from the session_provider or a default session will be created; in either case, any response caching configuration will be applied.

owmeta_core.bundle.loaders.http.http_remote(self, *, cache=None, session_provider=None, session_file_name=None)[source]

Provide additional parameters for HTTP remote accessors

Parameters
cachestr

Either the string “mem” or a file path to a cache directory

session_providerstr

Path to a callable that provides a requests.Session. The format is similar to that for setuptools entry points: path.to.module:path.to.provider.callable. Notably, there’s no name and “extras” are not supported. optional.

session_file_namestr

Path to a file where the HTTP session can be stored

owmeta_core.bundle.loaders.http.https_remote(self, *, ssl_context_provider=None, cache=None, session_provider=None, session_file_name=None)[source]

Provide additional parameters for HTTPS remote accessors

Parameters
ssl_context_providerstr

Path to a callable that provides a ssl.SSLContext used for bundle uploads. The format is similar to that for setuptools entry points: path.to.module:path.to.provider.callable. Notably, there’s no name and “extras” are not supported. optional.

cachestr

Either the string “mem” or a file path to a cache directory

session_providerstr

Path to a callable that provides a requests.Session. The format is similar to that for setuptools entry points: path.to.module:path.to.provider.callable. Notably, there’s no name and “extras” are not supported. optional.

session_file_namestr

Path to a file where the HTTP session can be stored