From ec03b23fb01638334dacf354e42a105729891290 Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Sat, 20 Jul 2019 18:26:57 +0200 Subject: move AP objects into `objects` package --- pyapd/objects.py | 62 ----------------------------------------------- pyapd/objects/APObject.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++ pyapd/objects/__init__.py | 1 + 3 files changed, 63 insertions(+), 62 deletions(-) delete mode 100644 pyapd/objects.py create mode 100644 pyapd/objects/APObject.py create mode 100644 pyapd/objects/__init__.py diff --git a/pyapd/objects.py b/pyapd/objects.py deleted file mode 100644 index 13284ee..0000000 --- a/pyapd/objects.py +++ /dev/null @@ -1,62 +0,0 @@ -import dataclasses -import json - - -@dataclasses.dataclass -class APObject: - # TODO: assign the correct type - ap_id: str = '' - ap_type: str = '' - ap_attachment: str = '' - ap_attributedTo: str = '' - ap_audience: str = '' - ap_content: str = '' - ap_context: str = '' - ap_contentMap: str = '' - ap_name: str = '' - ap_nameMap: str = '' - ap_endTime: str = '' - ap_generator: str = '' - ap_icon: str = '' - ap_image: str = '' - ap_inReplyTo: str = '' - ap_location: str = '' - ap_preview: str = '' - ap_published: str = '' - ap_replies: str = '' - ap_startTime: str = '' - ap_summary: str = '' - ap_summaryMap: str = '' - ap_tag: str = '' - ap_updated: str = '' - ap_url: str = '' - ap_to: str = '' - ap_bto: str = '' - ap_cc: str = '' - ap_bcc: str = '' - ap_mediaType: str = '' - ap_duration: str = '' - - def __post_init__(self): - if not self.ap_id: - self.ap_id = self._generate_id() - - @classmethod - def from_jsons(cls, data: str): - kw = {} - for k, v in json.loads(data).items(): - kw['ap_'+k] = v - return cls(**kw) - - def to_jsonable(self): - data = { - } - for k, v in dataclasses.asdict(self).items(): - data[k[3:]] = v - return data - - def to_jsons(self): - return json.dumps(self.to_jsonable()) - - def _generate_id(self): - raise NotImplementedError diff --git a/pyapd/objects/APObject.py b/pyapd/objects/APObject.py new file mode 100644 index 0000000..13284ee --- /dev/null +++ b/pyapd/objects/APObject.py @@ -0,0 +1,62 @@ +import dataclasses +import json + + +@dataclasses.dataclass +class APObject: + # TODO: assign the correct type + ap_id: str = '' + ap_type: str = '' + ap_attachment: str = '' + ap_attributedTo: str = '' + ap_audience: str = '' + ap_content: str = '' + ap_context: str = '' + ap_contentMap: str = '' + ap_name: str = '' + ap_nameMap: str = '' + ap_endTime: str = '' + ap_generator: str = '' + ap_icon: str = '' + ap_image: str = '' + ap_inReplyTo: str = '' + ap_location: str = '' + ap_preview: str = '' + ap_published: str = '' + ap_replies: str = '' + ap_startTime: str = '' + ap_summary: str = '' + ap_summaryMap: str = '' + ap_tag: str = '' + ap_updated: str = '' + ap_url: str = '' + ap_to: str = '' + ap_bto: str = '' + ap_cc: str = '' + ap_bcc: str = '' + ap_mediaType: str = '' + ap_duration: str = '' + + def __post_init__(self): + if not self.ap_id: + self.ap_id = self._generate_id() + + @classmethod + def from_jsons(cls, data: str): + kw = {} + for k, v in json.loads(data).items(): + kw['ap_'+k] = v + return cls(**kw) + + def to_jsonable(self): + data = { + } + for k, v in dataclasses.asdict(self).items(): + data[k[3:]] = v + return data + + def to_jsons(self): + return json.dumps(self.to_jsonable()) + + def _generate_id(self): + raise NotImplementedError diff --git a/pyapd/objects/__init__.py b/pyapd/objects/__init__.py new file mode 100644 index 0000000..1959576 --- /dev/null +++ b/pyapd/objects/__init__.py @@ -0,0 +1 @@ +from .APObject import APObject -- cgit v1.2.3