7d2f2b1bda31ead428d3c009772aaf3d2261d60c
Marco Ricci Change the author e-mail ad...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py   1) # SPDX-FileCopyrightText: 2024 Marco Ricci <software@the13thletter.info>
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py    2) #
src/derivepassphrase/types.py    3) # SPDX-License-Identifier: MIT
src/derivepassphrase/types.py    4) 
Marco Ricci Update documentation to use...

Marco Ricci authored 5 months ago

src/derivepassphrase/_types.py   5) """Types used by derivepassphrase."""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py    6) 
src/derivepassphrase/types.py    7) from __future__ import annotations
src/derivepassphrase/types.py    8) 
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 5 months ago

src/derivepassphrase/_types.py   9) import enum
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py  10) import math
Marco Ricci Overhaul the validation fun...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py  11) from typing import TYPE_CHECKING
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

src/derivepassphrase/types.py   12) 
Marco Ricci Support Python 3.10 and PyP...

Marco Ricci authored 5 months ago

src/derivepassphrase/types.py   13) from typing_extensions import (
Marco Ricci Overhaul the validation fun...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py  14)     NamedTuple,
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

src/derivepassphrase/types.py   15)     NotRequired,
src/derivepassphrase/types.py   16)     TypedDict,
Marco Ricci Support Python 3.10 and PyP...

Marco Ricci authored 5 months ago

src/derivepassphrase/types.py   17) )
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py   18) 
Marco Ricci Overhaul the validation fun...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py  19) if TYPE_CHECKING:
src/derivepassphrase/_types.py  20)     from collections.abc import Sequence
src/derivepassphrase/_types.py  21)     from typing import Literal
src/derivepassphrase/_types.py  22) 
src/derivepassphrase/_types.py  23)     from typing_extensions import (
src/derivepassphrase/_types.py  24)         Any,
src/derivepassphrase/_types.py  25)         Required,
src/derivepassphrase/_types.py  26)         TypeIs,
src/derivepassphrase/_types.py  27)     )
src/derivepassphrase/_types.py  28) 
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 5 months ago

src/derivepassphrase/_types.py  29) __all__ = (
src/derivepassphrase/_types.py  30)     'SSH_AGENT',
src/derivepassphrase/_types.py  31)     'SSH_AGENTC',
src/derivepassphrase/_types.py  32)     'KeyCommentPair',
src/derivepassphrase/_types.py  33)     'VaultConfig',
src/derivepassphrase/_types.py  34)     'is_vault_config',
src/derivepassphrase/_types.py  35) )
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py   36) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

src/derivepassphrase/types.py   37) 
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py   38) class VaultConfigGlobalSettings(TypedDict, total=False):
src/derivepassphrase/types.py   39)     r"""Configuration for vault: global settings.
src/derivepassphrase/types.py   40) 
src/derivepassphrase/types.py   41)     Attributes:
src/derivepassphrase/types.py   42)         key:
src/derivepassphrase/types.py   43)             The base64-encoded ssh public key to use, overriding the
src/derivepassphrase/types.py   44)             master passphrase. Optional.
src/derivepassphrase/types.py   45)         phrase:
src/derivepassphrase/types.py   46)             The master passphrase. Optional.
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

src/derivepassphrase/_types.py  47)         unicode_normalization_form:
src/derivepassphrase/_types.py  48)             The preferred Unicode normalization form; we warn the user
src/derivepassphrase/_types.py  49)             if textual passphrases do not match their normalized forms.
src/derivepassphrase/_types.py  50)             Optional, and a `derivepassphrase` extension.
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py   51) 
src/derivepassphrase/types.py   52)     """
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

src/derivepassphrase/types.py   53) 
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py   54)     key: NotRequired[str]
Marco Ricci Enable cross-references on...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py  55)     """"""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py   56)     phrase: NotRequired[str]
Marco Ricci Enable cross-references on...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py  57)     """"""
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

src/derivepassphrase/_types.py  58)     unicode_normalization_form: NotRequired[
src/derivepassphrase/_types.py  59)         Literal['NFC', 'NFD', 'NFKC', 'NFKD']
src/derivepassphrase/_types.py  60)     ]
Marco Ricci Enable cross-references on...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py  61)     """"""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py   62) 
src/derivepassphrase/types.py   63) 
src/derivepassphrase/types.py   64) class VaultConfigServicesSettings(VaultConfigGlobalSettings, total=False):
src/derivepassphrase/types.py   65)     r"""Configuration for vault: services settings.
src/derivepassphrase/types.py   66) 
src/derivepassphrase/types.py   67)     Attributes:
src/derivepassphrase/types.py   68)         notes:
src/derivepassphrase/types.py   69)             Optional notes for this service, to display to the user when
src/derivepassphrase/types.py   70)             generating the passphrase.
src/derivepassphrase/types.py   71)         length:
src/derivepassphrase/types.py   72)             Desired passphrase length.
src/derivepassphrase/types.py   73)         repeat:
src/derivepassphrase/types.py   74)             The maximum number of immediate character repetitions
src/derivepassphrase/types.py   75)             allowed in the passphrase.  Disabled if set to 0.
src/derivepassphrase/types.py   76)         lower:
src/derivepassphrase/types.py   77)             Optional constraint on ASCII lowercase characters.  If
src/derivepassphrase/types.py   78)             positive, include this many lowercase characters
src/derivepassphrase/types.py   79)             somewhere in the passphrase.  If 0, avoid lowercase
src/derivepassphrase/types.py   80)             characters altogether.
src/derivepassphrase/types.py   81)         upper:
src/derivepassphrase/types.py   82)             Same as `lower`, but for ASCII uppercase characters.
src/derivepassphrase/types.py   83)         number:
src/derivepassphrase/types.py   84)             Same as `lower`, but for ASCII digits.
src/derivepassphrase/types.py   85)         space:
src/derivepassphrase/types.py   86)             Same as `lower`, but for the space character.
src/derivepassphrase/types.py   87)         dash:
src/derivepassphrase/types.py   88)             Same as `lower`, but for the hyphen-minus and underscore
src/derivepassphrase/types.py   89)             characters.
src/derivepassphrase/types.py   90)         symbol:
src/derivepassphrase/types.py   91)             Same as `lower`, but for all other hitherto unlisted
src/derivepassphrase/types.py   92)             ASCII printable characters (except backquote).
src/derivepassphrase/types.py   93) 
src/derivepassphrase/types.py   94)     """
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

src/derivepassphrase/types.py   95) 
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py   96)     notes: NotRequired[str]
Marco Ricci Enable cross-references on...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py  97)     """"""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py   98)     length: NotRequired[int]
Marco Ricci Enable cross-references on...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py  99)     """"""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  100)     repeat: NotRequired[int]
Marco Ricci Enable cross-references on...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 101)     """"""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  102)     lower: NotRequired[int]
Marco Ricci Enable cross-references on...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 103)     """"""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  104)     upper: NotRequired[int]
Marco Ricci Enable cross-references on...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 105)     """"""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  106)     number: NotRequired[int]
Marco Ricci Enable cross-references on...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 107)     """"""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  108)     space: NotRequired[int]
Marco Ricci Enable cross-references on...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 109)     """"""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  110)     dash: NotRequired[int]
Marco Ricci Enable cross-references on...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 111)     """"""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  112)     symbol: NotRequired[int]
Marco Ricci Enable cross-references on...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 113)     """"""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  114) 
src/derivepassphrase/types.py  115) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

src/derivepassphrase/types.py  116) _VaultConfig = TypedDict(
src/derivepassphrase/types.py  117)     '_VaultConfig',
src/derivepassphrase/types.py  118)     {'global': NotRequired[VaultConfigGlobalSettings]},
src/derivepassphrase/types.py  119)     total=False,
src/derivepassphrase/types.py  120) )
src/derivepassphrase/types.py  121) 
src/derivepassphrase/types.py  122) 
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  123) class VaultConfig(TypedDict, _VaultConfig, total=False):
Marco Ricci Enable cross-references on...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 124)     r"""Configuration for vault.  For typing purposes.
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  125) 
src/derivepassphrase/types.py  126)     Usually stored as JSON.
src/derivepassphrase/types.py  127) 
src/derivepassphrase/types.py  128)     Attributes:
src/derivepassphrase/types.py  129)         global (NotRequired[VaultConfigGlobalSettings]):
src/derivepassphrase/types.py  130)             Global settings.
src/derivepassphrase/types.py  131)         services (Required[dict[str, VaultConfigServicesSettings]]):
src/derivepassphrase/types.py  132)             Service-specific settings.
src/derivepassphrase/types.py  133) 
src/derivepassphrase/types.py  134)     """
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

src/derivepassphrase/types.py  135) 
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  136)     services: Required[dict[str, VaultConfigServicesSettings]]
src/derivepassphrase/types.py  137) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

src/derivepassphrase/types.py  138) 
Marco Ricci Overhaul the validation fun...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 139) def validate_vault_config(  # noqa: C901,PLR0912,PLR0915
src/derivepassphrase/_types.py 140)     obj: Any,  # noqa: ANN401
src/derivepassphrase/_types.py 141)     /,
src/derivepassphrase/_types.py 142)     *,
src/derivepassphrase/_types.py 143)     allow_unknown_settings: bool = False,
src/derivepassphrase/_types.py 144)     allow_derivepassphrase_extensions: bool = False,
src/derivepassphrase/_types.py 145) ) -> None:
src/derivepassphrase/_types.py 146)     """Check that `obj` is a valid vault config.
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  147) 
src/derivepassphrase/types.py  148)     Args:
Marco Ricci Overhaul the validation fun...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 149)         obj:
src/derivepassphrase/_types.py 150)             The object to test.
src/derivepassphrase/_types.py 151)         allow_unknown_settings:
src/derivepassphrase/_types.py 152)             If false, abort on unknown settings.
src/derivepassphrase/_types.py 153)         allow_derivepassphrase_extensions:
src/derivepassphrase/_types.py 154)             If true, allow `derivepassphrase` extensions.
src/derivepassphrase/_types.py 155) 
src/derivepassphrase/_types.py 156)     Raises:
src/derivepassphrase/_types.py 157)         TypeError:
src/derivepassphrase/_types.py 158)             An entry in the vault config, or the vault config itself,
src/derivepassphrase/_types.py 159)             has the wrong type.
src/derivepassphrase/_types.py 160)         ValueError:
src/derivepassphrase/_types.py 161)             An entry in the vault config is not allowed, or has a
src/derivepassphrase/_types.py 162)             disallowed value.
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  163) 
src/derivepassphrase/types.py  164)     """
Marco Ricci Overhaul the validation fun...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 165) 
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 166)     def maybe_quote(x: str) -> str:
src/derivepassphrase/_types.py 167)         chars = (
src/derivepassphrase/_types.py 168)             frozenset('abcdefghijklmnopqrstuvwxyz')
src/derivepassphrase/_types.py 169)             | frozenset('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
src/derivepassphrase/_types.py 170)             | frozenset('0123456789')
src/derivepassphrase/_types.py 171)             | frozenset('_')
src/derivepassphrase/_types.py 172)         )
src/derivepassphrase/_types.py 173)         initial = (
src/derivepassphrase/_types.py 174)             frozenset('abcdefghijklmnopqrstuvwxyz')
src/derivepassphrase/_types.py 175)             | frozenset('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
src/derivepassphrase/_types.py 176)             | frozenset('_')
src/derivepassphrase/_types.py 177)         )
src/derivepassphrase/_types.py 178)         return (
src/derivepassphrase/_types.py 179)             x if x and set(x).issubset(chars) and x[:1] in initial else repr(x)
src/derivepassphrase/_types.py 180)         )
src/derivepassphrase/_types.py 181) 
Marco Ricci Overhaul the validation fun...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 182)     def as_json_path_string(json_path: Sequence[str], /) -> str:
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 183)         return ''.join('.' + maybe_quote(x) for x in json_path)
Marco Ricci Overhaul the validation fun...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 184) 
src/derivepassphrase/_types.py 185)     err_obj_not_a_dict = 'vault config is not a dict'
src/derivepassphrase/_types.py 186)     err_non_str_service_name = (
src/derivepassphrase/_types.py 187)         'vault config contains non-string service name {!r}'
src/derivepassphrase/_types.py 188)     )
src/derivepassphrase/_types.py 189) 
src/derivepassphrase/_types.py 190)     def err_not_a_dict(json_path: Sequence[str], /) -> str:
src/derivepassphrase/_types.py 191)         json_path_str = as_json_path_string(json_path)
src/derivepassphrase/_types.py 192)         return f'vault config entry {json_path_str} is not a dict'
src/derivepassphrase/_types.py 193) 
src/derivepassphrase/_types.py 194)     def err_not_a_string(json_path: Sequence[str], /) -> str:
src/derivepassphrase/_types.py 195)         json_path_str = as_json_path_string(json_path)
src/derivepassphrase/_types.py 196)         return f'vault config entry {json_path_str} is not a string'
src/derivepassphrase/_types.py 197) 
src/derivepassphrase/_types.py 198)     def err_not_an_int(json_path: Sequence[str], /) -> str:
src/derivepassphrase/_types.py 199)         json_path_str = as_json_path_string(json_path)
src/derivepassphrase/_types.py 200)         return f'vault config entry {json_path_str} is not an integer'
src/derivepassphrase/_types.py 201) 
src/derivepassphrase/_types.py 202)     def err_derivepassphrase_extension(
src/derivepassphrase/_types.py 203)         key: str, json_path: Sequence[str], /
src/derivepassphrase/_types.py 204)     ) -> str:
src/derivepassphrase/_types.py 205)         json_path_str = as_json_path_string(json_path)
src/derivepassphrase/_types.py 206)         return (
src/derivepassphrase/_types.py 207)             f'vault config entry {json_path_str} uses '
src/derivepassphrase/_types.py 208)             f'`derivepassphrase` extension {key!r}'
src/derivepassphrase/_types.py 209)         )
src/derivepassphrase/_types.py 210) 
src/derivepassphrase/_types.py 211)     def err_unknown_setting(key: str, json_path: Sequence[str], /) -> str:
src/derivepassphrase/_types.py 212)         json_path_str = as_json_path_string(json_path)
src/derivepassphrase/_types.py 213)         return (
src/derivepassphrase/_types.py 214)             f'vault config entry {json_path_str} uses '
src/derivepassphrase/_types.py 215)             f'unknown setting {key!r}'
src/derivepassphrase/_types.py 216)         )
src/derivepassphrase/_types.py 217) 
src/derivepassphrase/_types.py 218)     def err_bad_number(
src/derivepassphrase/_types.py 219)         key: str,
src/derivepassphrase/_types.py 220)         json_path: Sequence[str],
src/derivepassphrase/_types.py 221)         /,
src/derivepassphrase/_types.py 222)         *,
src/derivepassphrase/_types.py 223)         strictly_positive: bool = False,
src/derivepassphrase/_types.py 224)     ) -> str:
src/derivepassphrase/_types.py 225)         json_path_str = as_json_path_string((*json_path, key))
src/derivepassphrase/_types.py 226)         return f'vault config entry {json_path_str} is ' + (
src/derivepassphrase/_types.py 227)             'not positive' if strictly_positive else 'negative'
src/derivepassphrase/_types.py 228)         )
src/derivepassphrase/_types.py 229) 
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  230)     if not isinstance(obj, dict):
Marco Ricci Overhaul the validation fun...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 231)         raise TypeError(err_obj_not_a_dict)
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 232)     queue_to_check: list[tuple[dict[str, Any], tuple[str, ...]]] = []
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  233)     if 'global' in obj:
src/derivepassphrase/types.py  234)         o_global = obj['global']
src/derivepassphrase/types.py  235)         if not isinstance(o_global, dict):
Marco Ricci Overhaul the validation fun...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 236)             raise TypeError(err_not_a_dict(['global']))
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 237)         queue_to_check.append((o_global, ('global',)))
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  238)     if not isinstance(obj.get('services'), dict):
Marco Ricci Overhaul the validation fun...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 239)         raise TypeError(err_not_a_dict(['services']))
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  240)     for sv_name, service in obj['services'].items():
src/derivepassphrase/types.py  241)         if not isinstance(sv_name, str):
Marco Ricci Overhaul the validation fun...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 242)             raise TypeError(err_non_str_service_name.format(sv_name))
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  243)         if not isinstance(service, dict):
Marco Ricci Overhaul the validation fun...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 244)             raise TypeError(err_not_a_dict(['services', sv_name]))
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 245)         queue_to_check.append((service, ('services', sv_name)))
src/derivepassphrase/_types.py 246)     for settings, path in queue_to_check:
src/derivepassphrase/_types.py 247)         for key, value in settings.items():
Marco Ricci Add support for Python 3.9

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 248)             # Use match/case here once Python 3.9 becomes unsupported.
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 249)             if key in {'key', 'phrase'}:
Marco Ricci Add support for Python 3.9

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 250)                 if not isinstance(value, str):
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 251)                     raise TypeError(err_not_a_string((*path, key)))
src/derivepassphrase/_types.py 252)             elif key == 'unicode_normalization_form' and path == ('global',):
src/derivepassphrase/_types.py 253)                 if not isinstance(value, str):
src/derivepassphrase/_types.py 254)                     raise TypeError(err_not_a_string((*path, key)))
src/derivepassphrase/_types.py 255)                 if not allow_derivepassphrase_extensions:
src/derivepassphrase/_types.py 256)                     raise ValueError(err_derivepassphrase_extension(key, path))
src/derivepassphrase/_types.py 257)             elif key == 'notes' and path != ('global',):
src/derivepassphrase/_types.py 258)                 if not isinstance(value, str):
src/derivepassphrase/_types.py 259)                     raise TypeError(err_not_a_string((*path, key)))
Marco Ricci Add support for Python 3.9

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 260)             elif key == 'length':
src/derivepassphrase/_types.py 261)                 if not isinstance(value, int):
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 262)                     raise TypeError(err_not_an_int((*path, key)))
Marco Ricci Add support for Python 3.9

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 263)                 if value < 1:
src/derivepassphrase/_types.py 264)                     raise ValueError(
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 265)                         err_bad_number(key, path, strictly_positive=True)
Marco Ricci Add support for Python 3.9

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 266)                     )
src/derivepassphrase/_types.py 267)             elif key in {
src/derivepassphrase/_types.py 268)                 'repeat',
src/derivepassphrase/_types.py 269)                 'lower',
src/derivepassphrase/_types.py 270)                 'upper',
src/derivepassphrase/_types.py 271)                 'number',
src/derivepassphrase/_types.py 272)                 'space',
src/derivepassphrase/_types.py 273)                 'dash',
src/derivepassphrase/_types.py 274)                 'symbol',
src/derivepassphrase/_types.py 275)             }:
src/derivepassphrase/_types.py 276)                 if not isinstance(value, int):
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 277)                     raise TypeError(err_not_an_int((*path, key)))
Marco Ricci Add support for Python 3.9

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 278)                 if value < 0:
Marco Ricci Overhaul the validation fun...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 279)                     raise ValueError(
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 280)                         err_bad_number(key, path, strictly_positive=False)
Marco Ricci Overhaul the validation fun...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 281)                     )
Marco Ricci Add support for Python 3.9

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 282)             elif not allow_unknown_settings:
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 283)                 raise ValueError(err_unknown_setting(key, path))
Marco Ricci Overhaul the validation fun...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 284) 
src/derivepassphrase/_types.py 285) 
src/derivepassphrase/_types.py 286) def is_vault_config(obj: Any) -> TypeIs[VaultConfig]:  # noqa: ANN401
src/derivepassphrase/_types.py 287)     """Check if `obj` is a valid vault config, according to typing.
src/derivepassphrase/_types.py 288) 
src/derivepassphrase/_types.py 289)     Args:
src/derivepassphrase/_types.py 290)         obj: The object to test.
src/derivepassphrase/_types.py 291) 
src/derivepassphrase/_types.py 292)     Returns:
src/derivepassphrase/_types.py 293)         True if this is a vault config, false otherwise.
src/derivepassphrase/_types.py 294) 
src/derivepassphrase/_types.py 295)     """
src/derivepassphrase/_types.py 296)     try:
src/derivepassphrase/_types.py 297)         validate_vault_config(
src/derivepassphrase/_types.py 298)             obj,
src/derivepassphrase/_types.py 299)             allow_unknown_settings=True,
src/derivepassphrase/_types.py 300)             allow_derivepassphrase_extensions=True,
src/derivepassphrase/_types.py 301)         )
src/derivepassphrase/_types.py 302)     except (TypeError, ValueError) as exc:
src/derivepassphrase/_types.py 303)         if 'vault config ' not in str(exc):  # pragma: no cover
src/derivepassphrase/_types.py 304)             raise  # noqa: DOC501
src/derivepassphrase/_types.py 305)         return False
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  306)     return True
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 5 months ago

src/derivepassphrase/_types.py 307) 
src/derivepassphrase/_types.py 308) 
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 309) def js_truthiness(value: Any, /) -> bool:  # noqa: ANN401
src/derivepassphrase/_types.py 310)     """Return the truthiness of the value, according to JavaScript/ECMAScript.
src/derivepassphrase/_types.py 311) 
src/derivepassphrase/_types.py 312)     Like Python, ECMAScript considers certain values to be false in
src/derivepassphrase/_types.py 313)     a boolean context, and every other value to be true.  These
src/derivepassphrase/_types.py 314)     considerations do not agree: ECMAScript considers [`math.nan`][] to
src/derivepassphrase/_types.py 315)     be false too, and empty arrays and objects/dicts to be true,
src/derivepassphrase/_types.py 316)     contrary to Python.  Because of these discrepancies, we cannot defer
src/derivepassphrase/_types.py 317)     to [`bool`][] for ECMAScript truthiness checking, and need
src/derivepassphrase/_types.py 318)     a separate, explicit predicate.
src/derivepassphrase/_types.py 319) 
src/derivepassphrase/_types.py 320)     (Some falsy values in ECMAScript aren't defined in Python:
src/derivepassphrase/_types.py 321)     `undefined`, and `document.all`.  We do not implement support for
src/derivepassphrase/_types.py 322)     those.)
src/derivepassphrase/_types.py 323) 
src/derivepassphrase/_types.py 324)     !!! note
src/derivepassphrase/_types.py 325) 
src/derivepassphrase/_types.py 326)         We cannot use a simple `value not in falsy_values` check,
src/derivepassphrase/_types.py 327)         because [`math.nan`][] behaves in annoying and obstructive ways.
src/derivepassphrase/_types.py 328)         In general, `float('NaN') == float('NaN')` is false, and
src/derivepassphrase/_types.py 329)         `float('NaN') != math.nan` and `math.nan != math.nan` are true.
src/derivepassphrase/_types.py 330)         CPython says `float('NaN') in [math.nan]` is false, PyPy3 says
src/derivepassphrase/_types.py 331)         it is true.  Seemingly the only reliable and portable way to
src/derivepassphrase/_types.py 332)         check for [`math.nan`][] is to use [`math.isnan`][] directly.
src/derivepassphrase/_types.py 333) 
src/derivepassphrase/_types.py 334)     Args:
src/derivepassphrase/_types.py 335)         value: The value to test.
src/derivepassphrase/_types.py 336) 
src/derivepassphrase/_types.py 337)     """  # noqa: RUF002
src/derivepassphrase/_types.py 338)     try:
src/derivepassphrase/_types.py 339)         if value in {None, False, 0, 0.0, ''}:
src/derivepassphrase/_types.py 340)             return False
src/derivepassphrase/_types.py 341)     except TypeError:
src/derivepassphrase/_types.py 342)         # All falsy values are hashable, so this can't be falsy.
src/derivepassphrase/_types.py 343)         return True
src/derivepassphrase/_types.py 344)     return not (isinstance(value, float) and math.isnan(value))
src/derivepassphrase/_types.py 345) 
src/derivepassphrase/_types.py 346) 
src/derivepassphrase/_types.py 347) def clean_up_falsy_vault_config_values(obj: Any) -> None:  # noqa: ANN401,C901,PLR0912
src/derivepassphrase/_types.py 348)     """Convert falsy values in a vault config to correct types, in-place.
src/derivepassphrase/_types.py 349) 
src/derivepassphrase/_types.py 350)     Needed for compatibility with vault(1), which sometimes uses only
src/derivepassphrase/_types.py 351)     truthiness checks.
src/derivepassphrase/_types.py 352) 
src/derivepassphrase/_types.py 353)     If vault(1) considered `obj` to be valid, then after clean up,
src/derivepassphrase/_types.py 354)     `obj` will be valid as per [`validate_vault_config`][].
src/derivepassphrase/_types.py 355) 
src/derivepassphrase/_types.py 356)     Args:
src/derivepassphrase/_types.py 357)         obj:
src/derivepassphrase/_types.py 358)             A presumed valid vault configuration save for using falsy
src/derivepassphrase/_types.py 359)             values of the wrong type.
src/derivepassphrase/_types.py 360) 
src/derivepassphrase/_types.py 361)     """
src/derivepassphrase/_types.py 362)     if (  # pragma: no cover
src/derivepassphrase/_types.py 363)         not isinstance(obj, dict)
src/derivepassphrase/_types.py 364)         or 'services' not in obj
src/derivepassphrase/_types.py 365)         or not isinstance(obj['services'], dict)
src/derivepassphrase/_types.py 366)     ):
src/derivepassphrase/_types.py 367)         # config is invalid
src/derivepassphrase/_types.py 368)         return
src/derivepassphrase/_types.py 369)     service_objects = list(obj['services'].values())
src/derivepassphrase/_types.py 370)     if not all(  # pragma: no cover
src/derivepassphrase/_types.py 371)         isinstance(service_obj, dict) for service_obj in service_objects
src/derivepassphrase/_types.py 372)     ):
src/derivepassphrase/_types.py 373)         # config is invalid
src/derivepassphrase/_types.py 374)         return
src/derivepassphrase/_types.py 375)     if 'global' in obj:
src/derivepassphrase/_types.py 376)         if isinstance(obj['global'], dict):
src/derivepassphrase/_types.py 377)             service_objects.append(obj['global'])
src/derivepassphrase/_types.py 378)         else:  # pragma: no cover
src/derivepassphrase/_types.py 379)             # config is invalid
src/derivepassphrase/_types.py 380)             return
src/derivepassphrase/_types.py 381)     for service_obj in service_objects:
src/derivepassphrase/_types.py 382)         for key, value in list(service_obj.items()):
src/derivepassphrase/_types.py 383)             # Use match/case here once Python 3.9 becomes unsupported.
src/derivepassphrase/_types.py 384)             if key == 'phrase':
src/derivepassphrase/_types.py 385)                 if not js_truthiness(value):
src/derivepassphrase/_types.py 386)                     service_obj[key] = ''
src/derivepassphrase/_types.py 387)             elif key in {'notes', 'key', 'length', 'repeat'}:
src/derivepassphrase/_types.py 388)                 if not js_truthiness(value):
src/derivepassphrase/_types.py 389)                     service_obj.pop(key)
src/derivepassphrase/_types.py 390)             elif key in {  # noqa: SIM102
src/derivepassphrase/_types.py 391)                 'lower',
src/derivepassphrase/_types.py 392)                 'upper',
src/derivepassphrase/_types.py 393)                 'number',
src/derivepassphrase/_types.py 394)                 'space',
src/derivepassphrase/_types.py 395)                 'dash',
src/derivepassphrase/_types.py 396)                 'symbol',
src/derivepassphrase/_types.py 397)             }:
src/derivepassphrase/_types.py 398)                 if not js_truthiness(value) and value != 0:
src/derivepassphrase/_types.py 399)                     service_obj.pop(key)
src/derivepassphrase/_types.py 400) 
src/derivepassphrase/_types.py 401) 
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 5 months ago

src/derivepassphrase/_types.py 402) class KeyCommentPair(NamedTuple):
src/derivepassphrase/_types.py 403)     """SSH key plus comment pair.  For typing purposes.
src/derivepassphrase/_types.py 404) 
src/derivepassphrase/_types.py 405)     Attributes:
src/derivepassphrase/_types.py 406)         key: SSH key.
src/derivepassphrase/_types.py 407)         comment: SSH key comment.
src/derivepassphrase/_types.py 408) 
src/derivepassphrase/_types.py 409)     """
src/derivepassphrase/_types.py 410) 
src/derivepassphrase/_types.py 411)     key: bytes | bytearray
Marco Ricci Enable cross-references on...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 412)     """"""
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 5 months ago

src/derivepassphrase/_types.py 413)     comment: bytes | bytearray
Marco Ricci Enable cross-references on...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 414)     """"""
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 5 months ago

src/derivepassphrase/_types.py 415) 
src/derivepassphrase/_types.py 416) 
src/derivepassphrase/_types.py 417) class SSH_AGENTC(enum.Enum):  # noqa: N801
src/derivepassphrase/_types.py 418)     """SSH agent protocol numbers: client requests.
src/derivepassphrase/_types.py 419) 
src/derivepassphrase/_types.py 420)     Attributes:
src/derivepassphrase/_types.py 421)         REQUEST_IDENTITIES:
Marco Ricci Generate nicer documentatio...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 422)             List identities.  Expecting
src/derivepassphrase/_types.py 423)             [`SSH_AGENT.IDENTITIES_ANSWER`][].
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 5 months ago

src/derivepassphrase/_types.py 424)         SIGN_REQUEST:
Marco Ricci Generate nicer documentatio...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 425)             Sign data.  Expecting [`SSH_AGENT.SIGN_RESPONSE`][].
Marco Ricci Add principal support for u...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 426)         ADD_IDENTITY:
src/derivepassphrase/_types.py 427)             Add an (SSH2) identity.
src/derivepassphrase/_types.py 428)         REMOVE_IDENTITY:
src/derivepassphrase/_types.py 429)             Remove an (SSH2) identity.
src/derivepassphrase/_types.py 430)         ADD_ID_CONSTRAINED:
src/derivepassphrase/_types.py 431)             Add an (SSH2) identity, including key constraints.
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 5 months ago

src/derivepassphrase/_types.py 432) 
src/derivepassphrase/_types.py 433)     """
src/derivepassphrase/_types.py 434) 
src/derivepassphrase/_types.py 435)     REQUEST_IDENTITIES: int = 11
Marco Ricci Enable cross-references on...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 436)     """"""
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 5 months ago

src/derivepassphrase/_types.py 437)     SIGN_REQUEST: int = 13
Marco Ricci Enable cross-references on...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 438)     """"""
Marco Ricci Add principal support for u...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 439)     ADD_IDENTITY: int = 17
Marco Ricci Enable cross-references on...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 440)     """"""
Marco Ricci Add principal support for u...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 441)     REMOVE_IDENTITY: int = 18
Marco Ricci Enable cross-references on...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 442)     """"""
Marco Ricci Add principal support for u...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 443)     ADD_ID_CONSTRAINED: int = 25
Marco Ricci Enable cross-references on...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 444)     """"""
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 5 months ago

src/derivepassphrase/_types.py 445) 
src/derivepassphrase/_types.py 446) 
src/derivepassphrase/_types.py 447) class SSH_AGENT(enum.Enum):  # noqa: N801
src/derivepassphrase/_types.py 448)     """SSH agent protocol numbers: server replies.
src/derivepassphrase/_types.py 449) 
src/derivepassphrase/_types.py 450)     Attributes:
Marco Ricci Add a specific error class...

Marco Ricci authored 4 months ago

src/derivepassphrase/_types.py 451)         FAILURE:
src/derivepassphrase/_types.py 452)             Generic failure code.
src/derivepassphrase/_types.py 453)         SUCCESS:
src/derivepassphrase/_types.py 454)             Generic success code.
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 5 months ago

src/derivepassphrase/_types.py 455)         IDENTITIES_ANSWER:
Marco Ricci Generate nicer documentatio...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 456)             Successful answer to [`SSH_AGENTC.REQUEST_IDENTITIES`][].
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 5 months ago

src/derivepassphrase/_types.py 457)         SIGN_RESPONSE:
Marco Ricci Generate nicer documentatio...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 458)             Successful answer to [`SSH_AGENTC.SIGN_REQUEST`][].
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 5 months ago

src/derivepassphrase/_types.py 459) 
src/derivepassphrase/_types.py 460)     """
src/derivepassphrase/_types.py 461) 
Marco Ricci Add a specific error class...

Marco Ricci authored 4 months ago

src/derivepassphrase/_types.py 462)     FAILURE: int = 5
Marco Ricci Enable cross-references on...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 463)     """"""
Marco Ricci Add a specific error class...

Marco Ricci authored 4 months ago

src/derivepassphrase/_types.py 464)     SUCCESS: int = 6
Marco Ricci Enable cross-references on...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 465)     """"""
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 5 months ago

src/derivepassphrase/_types.py 466)     IDENTITIES_ANSWER: int = 12
Marco Ricci Enable cross-references on...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 467)     """"""
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 5 months ago

src/derivepassphrase/_types.py 468)     SIGN_RESPONSE: int = 14