diff --git a/platypush/message/__init__.py b/platypush/message/__init__.py index 122f03eb8..a5561229f 100644 --- a/platypush/message/__init__.py +++ b/platypush/message/__init__.py @@ -9,6 +9,9 @@ logger = logging.getLogger(__name__) class Message(object): """ Message generic class """ + def __init__(self, timestamp=None, *args, **kwargs): + self.timestamp = timestamp or time.time() + def __str__(self): """ Overrides the str() operator and converts diff --git a/platypush/message/event/__init__.py b/platypush/message/event/__init__.py index 2a7f7df71..6d70826b1 100644 --- a/platypush/message/event/__init__.py +++ b/platypush/message/event/__init__.py @@ -23,13 +23,13 @@ class Event(Message): kwargs -- Additional arguments for the event [kwDict] """ + super().__init__(timestamp=timestamp) self.id = id if id else self._generate_id() self.target = target if target else Config.get('device_id') self.origin = origin if origin else Config.get('device_id') self.type = '{}.{}'.format(self.__class__.__module__, self.__class__.__name__) self.args = kwargs - self.timestamp = timestamp or time.time() @classmethod def build(cls, msg): diff --git a/platypush/message/request/__init__.py b/platypush/message/request/__init__.py index 63c250b14..04659b36f 100644 --- a/platypush/message/request/__init__.py +++ b/platypush/message/request/__init__.py @@ -35,6 +35,8 @@ class Request(Message): timestamp -- Message creation timestamp [Float] """ + super().__init__(timestamp=timestamp) + self.id = id if id else self._generate_id() self.target = target self.action = action @@ -42,7 +44,6 @@ class Request(Message): self.args = args if args else {} self.backend = backend self.token = token - self.timestamp = timestamp or time.time() @classmethod def build(cls, msg): diff --git a/platypush/message/response/__init__.py b/platypush/message/response/__init__.py index b7e03ae84..530bf4697 100644 --- a/platypush/message/response/__init__.py +++ b/platypush/message/response/__init__.py @@ -18,11 +18,11 @@ class Response(Message): timestamp -- Message timestamp [Float] """ + super().__init__(timestamp=timestamp) self.target = target self.output = self._parse_msg(output) self.errors = self._parse_msg(errors) self.origin = origin - self.timestamp = timestamp or time.time() self.id = id def is_error(self):