mirror of
https://github.com/aljazceru/python-teos.git
synced 2026-02-23 15:34:18 +01:00
Reformats code to match code guidelines
This commit is contained in:
@@ -6,11 +6,12 @@ from pisa.encrypted_blob import EncryptedBlob
|
||||
# Basic appointment structure
|
||||
class Appointment:
|
||||
# DISCUSS: 35-appointment-checks
|
||||
def __init__(self, locator, start_time, end_time, dispute_delta, encrypted_blob, cipher, hash_function,
|
||||
triggered=False):
|
||||
def __init__(
|
||||
self, locator, start_time, end_time, dispute_delta, encrypted_blob, cipher, hash_function, triggered=False
|
||||
):
|
||||
self.locator = locator
|
||||
self.start_time = start_time # ToDo: #4-standardize-appointment-fields
|
||||
self.end_time = end_time # ToDo: #4-standardize-appointment-fields
|
||||
self.start_time = start_time # ToDo: #4-standardize-appointment-fields
|
||||
self.end_time = end_time # ToDo: #4-standardize-appointment-fields
|
||||
self.dispute_delta = dispute_delta
|
||||
self.encrypted_blob = EncryptedBlob(encrypted_blob)
|
||||
self.cipher = cipher
|
||||
@@ -20,36 +21,55 @@ class Appointment:
|
||||
@classmethod
|
||||
def from_dict(cls, appointment_data):
|
||||
locator = appointment_data.get("locator")
|
||||
start_time = appointment_data.get("start_time") # ToDo: #4-standardize-appointment-fields
|
||||
end_time = appointment_data.get("end_time") # ToDo: #4-standardize-appointment-fields
|
||||
start_time = appointment_data.get("start_time") # ToDo: #4-standardize-appointment-fields
|
||||
end_time = appointment_data.get("end_time") # ToDo: #4-standardize-appointment-fields
|
||||
dispute_delta = appointment_data.get("dispute_delta")
|
||||
encrypted_blob_data = appointment_data.get("encrypted_blob")
|
||||
cipher = appointment_data.get("cipher")
|
||||
hash_function = appointment_data.get("hash_function")
|
||||
triggered = appointment_data.get("triggered")
|
||||
|
||||
if any(v is None for v in [locator, start_time, end_time, dispute_delta, encrypted_blob_data, cipher,
|
||||
hash_function, triggered]):
|
||||
if any(
|
||||
v is None
|
||||
for v in [
|
||||
locator,
|
||||
start_time,
|
||||
end_time,
|
||||
dispute_delta,
|
||||
encrypted_blob_data,
|
||||
cipher,
|
||||
hash_function,
|
||||
triggered,
|
||||
]
|
||||
):
|
||||
raise ValueError("Wrong appointment data, some fields are missing")
|
||||
|
||||
else:
|
||||
appointment = cls(locator, start_time, end_time, dispute_delta, encrypted_blob_data, cipher, hash_function,
|
||||
triggered)
|
||||
appointment = cls(
|
||||
locator, start_time, end_time, dispute_delta, encrypted_blob_data, cipher, hash_function, triggered
|
||||
)
|
||||
|
||||
return appointment
|
||||
|
||||
def to_dict(self):
|
||||
# ToDO: #3-improve-appointment-structure
|
||||
appointment = {"locator": self.locator, "start_time": self.start_time, "end_time": self.end_time,
|
||||
"dispute_delta": self.dispute_delta, "encrypted_blob": self.encrypted_blob.data,
|
||||
"cipher": self.cipher, "hash_function": self.hash_function, "triggered": self.triggered}
|
||||
appointment = {
|
||||
"locator": self.locator,
|
||||
"start_time": self.start_time,
|
||||
"end_time": self.end_time,
|
||||
"dispute_delta": self.dispute_delta,
|
||||
"encrypted_blob": self.encrypted_blob.data,
|
||||
"cipher": self.cipher,
|
||||
"hash_function": self.hash_function,
|
||||
"triggered": self.triggered,
|
||||
}
|
||||
|
||||
return appointment
|
||||
|
||||
def to_json(self):
|
||||
return json.dumps(self.to_dict(), sort_keys=True, separators=(',', ':'))
|
||||
return json.dumps(self.to_dict(), sort_keys=True, separators=(",", ":"))
|
||||
|
||||
def serialize(self):
|
||||
data = self.to_dict()
|
||||
data.pop("triggered")
|
||||
return json.dumps(data, sort_keys=True, separators=(',', ':')).encode("utf-8")
|
||||
return json.dumps(data, sort_keys=True, separators=(",", ":")).encode("utf-8")
|
||||
|
||||
Reference in New Issue
Block a user