@@ -75,21 +75,22 @@ def __init__(
7575 self .signed = signed
7676 self .signatures = signatures
7777
78- def as_dict (self ) -> JsonDict :
79- """Returns the JSON-serializable dictionary representation of self. """
80- return {
81- 'signatures' : self .signatures ,
82- 'signed' : self .signed .as_dict ()
83- }
8478
85- def as_json (self , compact : bool = False ) -> None :
79+ def to_json (self , compact : bool = False ) -> None :
8680 """Returns the optionally compacted JSON representation of self. """
8781 return json .dumps (
88- self .as_dict (),
82+ self .to_dict (),
8983 indent = (None if compact else 1 ),
9084 separators = ((',' , ':' ) if compact else (',' , ': ' )),
9185 sort_keys = True )
9286
87+ def to_dict (self ) -> JsonDict :
88+ """Returns the JSON-serializable dictionary representation of self. """
89+ return {
90+ 'signatures' : self .signatures ,
91+ 'signed' : self .signed .to_dict ()
92+ }
93+
9394 def sign (self , key : JsonDict , append : bool = False ) -> JsonDict :
9495 """Creates signature over 'signed' and assigns it to 'signatures'.
9596
@@ -151,9 +152,8 @@ def verify(self, key: JsonDict) -> bool:
151152
152153 return True
153154
154-
155155 @classmethod
156- def read_from_json (
156+ def from_json_file (
157157 cls , filename : str ,
158158 storage_backend : Optional [StorageBackendInterface ] = None
159159 ) -> 'Metadata' :
@@ -196,7 +196,7 @@ def read_from_json(
196196 signed = inner_cls (** signable ['signed' ]),
197197 signatures = signable ['signatures' ])
198198
199- def write_to_json (
199+ def to_json_file (
200200 self , filename : str , compact : bool = False ,
201201 storage_backend : StorageBackendInterface = None ) -> None :
202202 """Writes the JSON representation of self to file storage.
@@ -214,10 +214,9 @@ def write_to_json(
214214
215215 """
216216 with tempfile .TemporaryFile () as f :
217- f .write (self .as_json (compact ).encode ('utf-8' ))
217+ f .write (self .to_json (compact ).encode ('utf-8' ))
218218 persist_temp_file (f , filename , storage_backend )
219219
220-
221220class Signed :
222221 """A base class for the signed part of TUF metadata.
223222
@@ -278,7 +277,7 @@ def bump_version(self) -> None:
278277 """Increments the metadata version number by 1."""
279278 self .version += 1
280279
281- def as_dict (self ) -> JsonDict :
280+ def to_dict (self ) -> JsonDict :
282281 """Returns the JSON-serializable dictionary representation of self. """
283282 return {
284283 '_type' : self ._type ,
@@ -312,9 +311,9 @@ def __init__(self, meta: JsonDict = None, **kwargs) -> None:
312311 # TODO: Is there merit in creating classes for dict fields?
313312 self .meta = meta
314313
315- def as_dict (self ) -> JsonDict :
314+ def to_dict (self ) -> JsonDict :
316315 """Returns the JSON-serializable dictionary representation of self. """
317- json_dict = super ().as_dict ()
316+ json_dict = super ().to_dict ()
318317 json_dict .update ({
319318 'meta' : self .meta
320319 })
@@ -361,9 +360,9 @@ def __init__(self, meta: JsonDict = None, **kwargs) -> None:
361360 super ().__init__ (** kwargs )
362361 self .meta = meta
363362
364- def as_dict (self ) -> JsonDict :
363+ def to_dict (self ) -> JsonDict :
365364 """Returns the JSON-serializable dictionary representation of self. """
366- json_dict = super ().as_dict ()
365+ json_dict = super ().to_dict ()
367366 json_dict .update ({
368367 'meta' : self .meta
369368 })
@@ -446,9 +445,9 @@ def __init__(
446445 self .targets = targets
447446 self .delegations = delegations
448447
449- def as_dict (self ) -> JsonDict :
448+ def to_dict (self ) -> JsonDict :
450449 """Returns the JSON-serializable dictionary representation of self. """
451- json_dict = super ().as_dict ()
450+ json_dict = super ().to_dict ()
452451 json_dict .update ({
453452 'targets' : self .targets ,
454453 'delegations' : self .delegations ,
0 commit comments