gpsd-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gpsd-dev] [PATCH 3/4] Fixes gps.gps.gps iterator for Python 3.


From: Fred Wright
Subject: [gpsd-dev] [PATCH 3/4] Fixes gps.gps.gps iterator for Python 3.
Date: Sat, 16 Apr 2016 00:01:12 -0700

Python 3 renames the iterator next() method to __next__().  Without
the new name, attempting to use the object as an iterator doesn't
work.  This didn't surface until trying webgps.py.

For compatibility with both Python 2 and Python 3, both names need to
be provided.  This change renames the existing method to conformto
Python 3 naming, and then adds a wrapper to provide the old name for
Python 2.

TESTED:
Ran webgps.py (with uncommitted fixes) with both Python 2 and Python
3.
---
 gps/gps.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gps/gps.py b/gps/gps.py
index a0868af..46daa9d 100755
--- a/gps/gps.py
+++ b/gps/gps.py
@@ -256,7 +256,8 @@ class gps(gpscommon, gpsdata, gpsjson):
             self.valid |= PACKET_SET
         return 0
 
-    def next(self):
+    def __next__(self):
+        "Python 3 version of next()."
         if self.read() == -1:
             raise StopIteration
         if hasattr(self, "data"):
@@ -264,6 +265,10 @@ class gps(gpscommon, gpsdata, gpsjson):
         else:
             return self.response
 
+    def next(self):
+        "Python 2 backward compatibility."
+        return self.__next__()
+
     def stream(self, flags=0, devpath=None):
         "Ask gpsd to stream reports at your client."
         if (flags & (WATCH_JSON | WATCH_OLDSTYLE | WATCH_NMEA | WATCH_RAW)) == 
0:
-- 
2.8.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]