konnect.curl.certificates.files module

File storage helper class for encoded cryptographic formats

final class EncodedFile(contents: konnect.curl.certificates.files.T, path: pathlib.Path)[source]

Bases: Generic[konnect.curl.certificates.files.T]

Combines decoding data with file path information

classmethod read(path: pathlib.Path, encoding: type[konnect.curl.certificates.files.C], /, maxsize: int = 65536) konnect.curl.certificates.files.EncodedFile[konnect.curl.certificates.files.C][source]

Read encoded data from the file path if it exists and return an EncodedFile

The value of ‘maxsize’ is a safety net to prevent arbitrarily large files being read into memory. The default should be suitable for most certificate and key files but can be overridden to allow unusually large files to be read (probably ASCII armored files containing many items).

Can raise the normal range of OSError exceptions that may occur when opening and reading a file.

static write(path: pathlib.Path, contents: konnect.curl.certificates.files.C, /, *, exists_ok: bool = False) konnect.curl.certificates.files.EncodedFile[konnect.curl.certificates.files.C][source]

Write encoded data to the file path

If ‘exists_ok’ is false the file will be opened in create-only mode, raising FileExistsError if there is already a file at the path; otherwise the file is opened in normal write mode and truncated before writing the encoded data. Either way the data is never appended to the file.

Can raise the normal range of OSError exceptions that may occur when opening and writing to a file.