[packages/python-pushover] - poll fix

arekm arekm at pld-linux.org
Mon Apr 11 11:12:18 CEST 2016


commit 53e08cb5fd73ba75a890f156b334d75588e2e0fd
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Mon Apr 11 11:12:14 2016 +0200

    - poll fix

 poll.patch           | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 python-pushover.spec |  2 ++
 2 files changed, 82 insertions(+)
---
diff --git a/python-pushover.spec b/python-pushover.spec
index 3627da9..3432f0a 100644
--- a/python-pushover.spec
+++ b/python-pushover.spec
@@ -12,6 +12,7 @@ License:	GPL v3+
 Group:		Libraries/Python
 Source0:	https://github.com/Thibauth/python-pushover/archive/v%{version}.tar.gz
 # Source0-md5:	8cb91ab69e6c58a2e831e35f2c092001
+Patch0:		poll.patch
 URL:		https://github.com/Thibauth/python-pushover
 BuildRequires:	rpm-pythonprov
 BuildRequires:	rpmbuild(macros) >= 1.713
@@ -41,6 +42,7 @@ service.
 
 %prep
 %setup -q
+%patch0 -p1
 
 %build
 %if %{with python2}
diff --git a/poll.patch b/poll.patch
new file mode 100644
index 0000000..a3d6bd3
--- /dev/null
+++ b/poll.patch
@@ -0,0 +1,80 @@
+From 8c9c32f9a72b0e49e67e4e5bd7cfcb3565c87597 Mon Sep 17 00:00:00 2001
+From: Filip Lundborg <filip at filipl.se>
+Date: Sun, 26 Oct 2014 19:52:29 +0100
+Subject: [PATCH] Fix consistency in MessageRequest.poll
+
+The help, example and actual code had different opinions on how the function
+should behave. This commit make them agree.
+
+poll() will return the base Request object until the receipt has expired, been
+acknowledged or called_back upon. Once one of those three things has occurred
+it returns None.
+
+The example now has expire=120 and retry=60 since without those arguments it is
+unable to send a message with priority=2.
+
+The expired_at does not exist, it is called expires_at in the Pushover API.
+This is fixed as well.
+
+The values of expires_at, acknowledged_at and called_back_at can be found as
+attributes in the MessageRequest object like before.
+---
+ AUTHORS.rst |  1 +
+ pushover.py | 22 ++++++++++++----------
+ 2 files changed, 13 insertions(+), 10 deletions(-)
+
+diff --git a/AUTHORS.rst b/AUTHORS.rst
+index ff143a0..704cb48 100644
+--- a/AUTHORS.rst
++++ b/AUTHORS.rst
+@@ -4,3 +4,4 @@ Contributors
+ * Sam Birch <sam.m.birch at gmail.com>
+ * Crupuk
+ * Thibaut Horel <thibaut.horel at gmail.com>
++* Filip Lundborg <filip at filipl.se>
+diff --git a/pushover.py b/pushover.py
+index a62609f..b670266 100644
+--- a/pushover.py
++++ b/pushover.py
+@@ -129,10 +129,12 @@ def __init__(self, payload):
+         self.receipt = None
+         if payload.get("priority", 0) == 2:
+             self.receipt = self.answer["receipt"]
+-        self.parameters = ["expired", "called_back", "acknowledged"]
+-        for parameter in self.parameters:
+-            setattr(self, parameter, False)
+-            setattr(self, parameter + "_at", 0)
++        self.parameters = {"expired": "expires_at",
++                           "called_back": "called_back_at",
++                           "acknowledged": "acknowledged_at"}
++        for param, when in self.parameters.iteritems():
++            setattr(self, param, False)
++            setattr(self, when, 0)
+ 
+     def poll(self):
+         """If the message request has a priority of 2, Pushover will keep
+@@ -147,18 +149,18 @@ def poll(self):
+         acknowledged, so that a typical handling of a priority-2 notification
+         can look like this::
+ 
+-            request = client.send_message("Urgent notification", priority=2)
+-            while not request.poll():
++            request = client.send_message("Urgent notification", priority=2,
++                                          expire=120, retry=60)
++            while request.poll():
+                 # do something
+                 time.sleep(5)
+         """
+         if (self.receipt and not any(getattr(self, parameter)
+                                      for parameter in self.parameters)):
+             request = Request("get", RECEIPT_URL + self.receipt + ".json", {})
+-            for parameter in self.parameters:
+-                setattr(self, parameter, request.answer[parameter])
+-                setattr(self, parameter + "_at",
+-                        request.answer[parameter + "_at"])
++            for param, when in self.parameters.iteritems():
++                setattr(self, param, bool(request.answer[param]))
++                setattr(self, when, request.answer[when])
+             return request
+ 
+ 
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/python-pushover.git/commitdiff/53e08cb5fd73ba75a890f156b334d75588e2e0fd



More information about the pld-cvs-commit mailing list