Skip to content

Commit

Permalink
Merge pull request #1363 from MVrachev/black-identation
Browse files Browse the repository at this point in the history
Fix black docstring indentation errors
  • Loading branch information
Jussi Kukkonen committed Apr 27, 2021
2 parents ec7173f + 1712b71 commit 878c8c6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
30 changes: 15 additions & 15 deletions tuf/api/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def from_bytes(
return deserializer.deserialize(data)

def to_dict(self) -> Dict[str, Any]:
"""Returns the dict representation of self. """
"""Returns the dict representation of self."""

signatures = []
for sig in self.signatures:
Expand Down Expand Up @@ -397,7 +397,7 @@ def is_expired(self, reference_time: datetime = None) -> bool:

# Modification.
def bump_expiration(self, delta: timedelta = timedelta(days=1)) -> None:
"""Increments the expires attribute by the passed timedelta. """
"""Increments the expires attribute by the passed timedelta."""
self.expires += delta

def bump_version(self) -> None:
Expand Down Expand Up @@ -465,7 +465,7 @@ def __init__(

@classmethod
def from_dict(cls, root_dict: Mapping[str, Any]) -> "Root":
"""Creates Root object from its dict representation. """
"""Creates Root object from its dict representation."""
common_args = cls._common_fields_from_dict(root_dict)
consistent_snapshot = root_dict.pop("consistent_snapshot")
keys = root_dict.pop("keys")
Expand All @@ -474,7 +474,7 @@ def from_dict(cls, root_dict: Mapping[str, Any]) -> "Root":
return cls(*common_args, consistent_snapshot, keys, roles, root_dict)

def to_dict(self) -> Dict[str, Any]:
"""Returns the dict representation of self. """
"""Returns the dict representation of self."""
root_dict = self._common_fields_to_dict()
root_dict.update(
{
Expand All @@ -489,14 +489,14 @@ def to_dict(self) -> Dict[str, Any]:
def add_key(
self, role: str, keyid: str, key_metadata: Mapping[str, Any]
) -> None:
"""Adds new key for 'role' and updates the key store. """
"""Adds new key for 'role' and updates the key store."""
if keyid not in self.roles[role]["keyids"]:
self.roles[role]["keyids"].append(keyid)
self.keys[keyid] = key_metadata

# Remove key for a role.
def remove_key(self, role: str, keyid: str) -> None:
"""Removes key for 'role' and updates the key store. """
"""Removes key for 'role' and updates the key store."""
if keyid in self.roles[role]["keyids"]:
self.roles[role]["keyids"].remove(keyid)
for keyinfo in self.roles.values():
Expand Down Expand Up @@ -543,14 +543,14 @@ def __init__(

@classmethod
def from_dict(cls, timestamp_dict: Mapping[str, Any]) -> "Timestamp":
"""Creates Timestamp object from its dict representation. """
"""Creates Timestamp object from its dict representation."""
common_args = cls._common_fields_from_dict(timestamp_dict)
meta = timestamp_dict.pop("meta")
# All fields left in the timestamp_dict are unrecognized.
return cls(*common_args, meta, timestamp_dict)

def to_dict(self) -> Dict[str, Any]:
"""Returns the dict representation of self. """
"""Returns the dict representation of self."""
timestamp_dict = self._common_fields_to_dict()
timestamp_dict.update({"meta": self.meta})
return timestamp_dict
Expand All @@ -559,7 +559,7 @@ def to_dict(self) -> Dict[str, Any]:
def update(
self, version: int, length: int, hashes: Mapping[str, Any]
) -> None:
"""Assigns passed info about snapshot metadata to meta dict. """
"""Assigns passed info about snapshot metadata to meta dict."""
self.meta["snapshot.json"] = {
"version": version,
"length": length,
Expand Down Expand Up @@ -611,14 +611,14 @@ def __init__(

@classmethod
def from_dict(cls, snapshot_dict: Mapping[str, Any]) -> "Snapshot":
"""Creates Snapshot object from its dict representation. """
"""Creates Snapshot object from its dict representation."""
common_args = cls._common_fields_from_dict(snapshot_dict)
meta = snapshot_dict.pop("meta")
# All fields left in the snapshot_dict are unrecognized.
return cls(*common_args, meta, snapshot_dict)

def to_dict(self) -> Dict[str, Any]:
"""Returns the dict representation of self. """
"""Returns the dict representation of self."""
snapshot_dict = self._common_fields_to_dict()
snapshot_dict.update({"meta": self.meta})
return snapshot_dict
Expand All @@ -631,7 +631,7 @@ def update(
length: Optional[int] = None,
hashes: Optional[Mapping[str, Any]] = None,
) -> None:
"""Assigns passed (delegated) targets role info to meta dict. """
"""Assigns passed (delegated) targets role info to meta dict."""
metadata_fn = f"{rolename}.json"

self.meta[metadata_fn] = {"version": version}
Expand Down Expand Up @@ -719,15 +719,15 @@ def __init__(

@classmethod
def from_dict(cls, targets_dict: Mapping[str, Any]) -> "Targets":
"""Creates Targets object from its dict representation. """
"""Creates Targets object from its dict representation."""
common_args = cls._common_fields_from_dict(targets_dict)
targets = targets_dict.pop("targets")
delegations = targets_dict.pop("delegations")
# All fields left in the targets_dict are unrecognized.
return cls(*common_args, targets, delegations, targets_dict)

def to_dict(self) -> Dict[str, Any]:
"""Returns the dict representation of self. """
"""Returns the dict representation of self."""
targets_dict = self._common_fields_to_dict()
targets_dict.update(
{
Expand All @@ -739,5 +739,5 @@ def to_dict(self) -> Dict[str, Any]:

# Modification.
def update(self, filename: str, fileinfo: Mapping[str, Any]) -> None:
"""Assigns passed target file info to meta dict. """
"""Assigns passed target file info to meta dict."""
self.targets[filename] = fileinfo
16 changes: 8 additions & 8 deletions tuf/api/serialization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,35 @@

# TODO: Should these be in tuf.exceptions or inherit from tuf.exceptions.Error?
class SerializationError(Exception):
"""Error during serialization. """
"""Error during serialization."""


class DeserializationError(Exception):
"""Error during deserialization. """
"""Error during deserialization."""


class MetadataDeserializer(metaclass=abc.ABCMeta):
"""Abstract base class for deserialization of Metadata objects. """
"""Abstract base class for deserialization of Metadata objects."""

@abc.abstractmethod
def deserialize(self, raw_data: bytes) -> "Metadata":
"""Deserialize passed bytes to Metadata object. """
"""Deserialize passed bytes to Metadata object."""
raise NotImplementedError


class MetadataSerializer(metaclass=abc.ABCMeta):
"""Abstract base class for serialization of Metadata objects. """
"""Abstract base class for serialization of Metadata objects."""

@abc.abstractmethod
def serialize(self, metadata_obj: "Metadata") -> bytes:
"""Serialize passed Metadata object to bytes. """
"""Serialize passed Metadata object to bytes."""
raise NotImplementedError


class SignedSerializer(metaclass=abc.ABCMeta):
"""Abstract base class for serialization of Signed objects. """
"""Abstract base class for serialization of Signed objects."""

@abc.abstractmethod
def serialize(self, signed_obj: "Signed") -> bytes:
"""Serialize passed Signed object to bytes. """
"""Serialize passed Signed object to bytes."""
raise NotImplementedError
8 changes: 4 additions & 4 deletions tuf/api/serialization/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@


class JSONDeserializer(MetadataDeserializer):
"""Provides JSON to Metadata deserialize method. """
"""Provides JSON to Metadata deserialize method."""

def deserialize(self, raw_data: bytes) -> Metadata:
"""Deserialize utf-8 encoded JSON bytes into Metadata object. """
"""Deserialize utf-8 encoded JSON bytes into Metadata object."""
try:
json_dict = json.loads(raw_data.decode("utf-8"))
metadata_obj = Metadata.from_dict(json_dict)
Expand All @@ -55,7 +55,7 @@ def __init__(self, compact: bool = False) -> None:
self.compact = compact

def serialize(self, metadata_obj: Metadata) -> bytes:
"""Serialize Metadata object into utf-8 encoded JSON bytes. """
"""Serialize Metadata object into utf-8 encoded JSON bytes."""
try:
indent = None if self.compact else 1
separators = (",", ":") if self.compact else (",", ": ")
Expand All @@ -73,7 +73,7 @@ def serialize(self, metadata_obj: Metadata) -> bytes:


class CanonicalJSONSerializer(SignedSerializer):
"""Provides Signed to OLPC Canonical JSON serialize method. """
"""Provides Signed to OLPC Canonical JSON serialize method."""

def serialize(self, signed_obj: Signed) -> bytes:
"""Serialize Signed object into utf-8 encoded OLPC Canonical JSON
Expand Down

0 comments on commit 878c8c6

Please sign in to comment.