1919
2020The above principle means that a ``Metadata`` object represents a single
2121metadata file, and has a ``signed`` attribute that is an instance of one of the
22- four top level signed classes (``Root``, ``Timestamp``, ``Snapshot`` and ``Targets``).
23- To make Python type annotations useful ``Metadata`` can be type constrained: e.g. the
24- signed attribute of ``Metadata[Root]`` is known to be ``Root``.
22+ four top level signed classes (``Root``, ``Timestamp``, ``Snapshot`` and
23+ ``Targets``). To make Python type annotations useful ``Metadata`` can be
24+ type constrained: e.g. the signed attribute of ``Metadata[Root]``
25+ is known to be ``Root``.
2526
2627Currently Metadata API supports JSON as the file format.
2728
@@ -101,8 +102,8 @@ class Metadata(Generic[T]):
101102
102103 Using a type constraint is not required but not doing so means T is not a
103104 specific type so static typing cannot happen. Note that the type constraint
104- ``[Root]`` is not validated at runtime (as pure annotations are not available
105- then).
105+ ``[Root]`` is not validated at runtime (as pure annotations are not
106+ available then).
106107
107108 New Metadata instances can be created from scratch with::
108109
@@ -227,6 +228,7 @@ def from_file(
227228 storage_backend: Object that implements
228229 ``securesystemslib.storage.StorageBackendInterface``.
229230 Default is ``FilesystemBackend`` (i.e. a local file).
231+
230232 Raises:
231233 StorageError: The file cannot be read.
232234 tuf.api.serialization.DeserializationError:
@@ -357,9 +359,10 @@ def sign(
357359 """Create signature over ``signed`` and assigns it to ``signatures``.
358360
359361 Args:
360- signer: A ``securesystemslib.signer.Signer`` object that provides a private
361- key and signing implementation to generate the signature. A standard
362- implementation is available in ``securesystemslib.signer.SSlibSigner``.
362+ signer: A ``securesystemslib.signer.Signer`` object that provides a
363+ private key and signing implementation to generate the signature. A
364+ standard implementation is available in
365+ ``securesystemslib.signer.SSlibSigner``.
363366 append: ``True`` if the signature should be appended to
364367 the list of signatures or replace any existing signatures. The
365368 default behavior is to replace signatures.
@@ -403,7 +406,8 @@ def verify_delegate(
403406 threshold of keys for ``delegated_role``.
404407
405408 .. deprecated:: 3.1.0
406- Please use ``Root.verify_delegate()`` or ``Targets.verify_delegate()``.
409+ Please use ``Root.verify_delegate()`` or
410+ ``Targets.verify_delegate()``.
407411 """
408412
409413 if self .signed .type not in ["root" , "targets" ]:
@@ -522,7 +526,9 @@ def to_dict(self) -> Dict[str, Any]:
522526 @classmethod
523527 @abc .abstractmethod
524528 def from_dict (cls , signed_dict : Dict [str , Any ]) -> "Signed" :
525- """Deserialization helper, creates object from json/dict representation."""
529+ """Deserialization helper, creates object from json/dict
530+ representation.
531+ """
526532 raise NotImplementedError
527533
528534 @classmethod
@@ -533,7 +539,8 @@ def _common_fields_from_dict(
533539 representation, and returns an ordered list to be passed as leading
534540 positional arguments to a subclass constructor.
535541
536- See ``{Root, Timestamp, Snapshot, Targets}.from_dict`` methods for usage.
542+ See ``{Root, Timestamp, Snapshot, Targets}.from_dict``
543+ methods for usage.
537544
538545 """
539546 _type = signed_dict .pop ("_type" )
@@ -551,7 +558,8 @@ def _common_fields_from_dict(
551558 return version , spec_version , expires
552559
553560 def _common_fields_to_dict (self ) -> Dict [str , Any ]:
554- """Return a dict representation of common fields of ``Signed`` instances.
561+ """Return a dict representation of common fields of
562+ ``Signed`` instances.
555563
556564 See ``{Root, Timestamp, Snapshot, Targets}.to_dict`` methods for usage.
557565
@@ -700,19 +708,27 @@ def __bool__(self) -> bool:
700708
701709 @property
702710 def verified (self ) -> bool :
703- """True if threshold of signatures is met in both underlying VerificationResults."""
711+ """True if threshold of signatures is met in both underlying
712+ VerificationResults.
713+ """
704714 return self .first .verified and self .second .verified
705715
706716 @property
707717 def signed (self ) -> Dict [str , Key ]:
708- """Dictionary of all signing keys that have signed, from both VerificationResults"""
709- # return a union of all signed (in python<3.9 this requires dict unpacking)
718+ """Dictionary of all signing keys that have signed, from both
719+ VerificationResults.
720+ return a union of all signed (in python<3.9 this requires
721+ dict unpacking)
722+ """
710723 return {** self .first .signed , ** self .second .signed }
711724
712725 @property
713726 def unsigned (self ) -> Dict [str , Key ]:
714- """Dictionary of all signing keys that have not signed, from both VerificationResults"""
715- # return a union of all unsigned (in python<3.9 this requires dict unpacking)
727+ """Dictionary of all signing keys that have not signed, from both
728+ VerificationResults.
729+ return a union of all unsigned (in python<3.9 this requires
730+ dict unpacking)
731+ """
716732 return {** self .first .unsigned , ** self .second .unsigned }
717733
718734
@@ -828,8 +844,8 @@ class Root(Signed, _DelegatorMixin):
828844 roles: Dictionary of role names to Roles. Defines which keys are
829845 required to sign the metadata for a specific role. Default is
830846 a dictionary of top level roles without keys and threshold of 1.
831- consistent_snapshot: ``True`` if repository supports consistent snapshots.
832- Default is True.
847+ consistent_snapshot: ``True`` if repository supports consistent
848+ snapshots. Default is True.
833849 unrecognized_fields: Dictionary of all attributes that are not managed
834850 by TUF Metadata API
835851
@@ -1191,6 +1207,7 @@ def from_data(
11911207 data: Metadata bytes that the metafile represents.
11921208 hash_algorithms: Hash algorithms to create the hashes with. If not
11931209 specified, the securesystemslib default hash algorithm is used.
1210+
11941211 Raises:
11951212 ValueError: The hash algorithms list contains an unsupported
11961213 algorithm.
@@ -1234,7 +1251,8 @@ class Timestamp(Signed):
12341251 """A container for the signed part of timestamp metadata.
12351252
12361253 TUF file format uses a dictionary to contain the snapshot information:
1237- this is not the case with ``Timestamp.snapshot_meta`` which is a ``MetaFile``.
1254+ this is not the case with ``Timestamp.snapshot_meta`` which is a
1255+ ``MetaFile``.
12381256
12391257 *All parameters named below are not just constructor arguments but also
12401258 instance attributes.*
@@ -1366,12 +1384,13 @@ class DelegatedRole(Role):
13661384
13671385 A delegation can happen in two ways:
13681386
1369- - ``paths`` is set: delegates targets matching any path pattern in ``paths``
1370- - ``path_hash_prefixes`` is set: delegates targets whose target path hash
1371- starts with any of the prefixes in ``path_hash_prefixes``
1387+ - ``paths`` is set: delegates targets matching any path pattern in
1388+ ``paths``
1389+ - ``path_hash_prefixes`` is set: delegates targets whose target path
1390+ hash starts with any of the prefixes in ``path_hash_prefixes``
13721391
1373- ``paths`` and ``path_hash_prefixes`` are mutually exclusive: both cannot be
1374- set, at least one of them must be set.
1392+ ``paths`` and ``path_hash_prefixes`` are mutually exclusive:
1393+ both cannot be set, at least one of them must be set.
13751394
13761395 *All parameters named below are not just constructor arguments but also
13771396 instance attributes.*
@@ -1491,10 +1510,10 @@ def is_delegated_path(self, target_filepath: str) -> bool:
14911510 """Determine whether the given ``target_filepath`` is in one of
14921511 the paths that ``DelegatedRole`` is trusted to provide.
14931512
1494- The ``target_filepath`` and the ``DelegatedRole`` paths are expected to be
1495- in their canonical forms, so e.g. "a/b" instead of "a//b" . Only "/" is
1496- supported as target path separator. Leading separators are not handled
1497- as special cases (see `TUF specification on targetpath
1513+ The ``target_filepath`` and the ``DelegatedRole`` paths are expected to
1514+ be in their canonical forms, so e.g. "a/b" instead of "a//b" . Only "/"
1515+ is supported as target path separator. Leading separators are not
1516+ handled as special cases (see `TUF specification on targetpath
14981517 <https://theupdateframework.github.io/specification/latest/#targetpath>`_).
14991518
15001519 Args:
@@ -1613,7 +1632,8 @@ def to_dict(self) -> Dict[str, Any]:
16131632 }
16141633
16151634 def get_role_for_target (self , target_filepath : str ) -> str :
1616- """Calculate the name of the delegated role responsible for ``target_filepath``.
1635+ """Calculate the name of the delegated role responsible for
1636+ ``target_filepath``.
16171637
16181638 The target at path ``target_filepath`` is assigned to a bin by casting
16191639 the left-most ``bit_length`` of bits of the file path hash digest to
@@ -1897,6 +1917,7 @@ def from_file(
18971917 local_path: Local path to target file content.
18981918 hash_algorithms: Hash algorithms to calculate hashes with. If not
18991919 specified the securesystemslib default hash algorithm is used.
1920+
19001921 Raises:
19011922 FileNotFoundError: The file doesn't exist.
19021923 ValueError: The hash algorithms list contains an unsupported
0 commit comments