gpsd-dev
[Top][All Lists]
Advanced

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

Fw: [Git][gpsd/gpsd][master] gegps: Simplify open() fix.


From: Gary E. Miller
Subject: Fw: [Git][gpsd/gpsd][master] gegps: Simplify open() fix.
Date: Tue, 12 Dec 2023 23:15:43 -0800

Yo Fred!

Thatg's not gonna work.  Python 2.7 does not allow open(,encoding=_'

RGDS
GARY
---------------------------------------------------------------------------
Gary E. Miller Rellim 109 NW Wilmington Ave., Suite E, Bend, OR 97703
        gem@rellim.com  Tel:+1 541 382 8588

            Veritas liberabit vos. -- Quid est veritas?
    "If you can't measure it, you can't improve it." - Lord Kelvin


Begin forwarded message:

Date: Wed, 13 Dec 2023 06:29:26 +0000
From: "Fred Wright (@fhgwright)" <gitlab@mg.gitlab.com>
To: gem@rellim.com
Subject: [Git][gpsd/gpsd][master] gegps: Simplify open() fix.


Fred Wright pushed to branch master at gpsd / gpsd


Commits:
69e99cd8 by Fred Wright at 2023-12-12T22:21:01-08:00
gegps: Simplify open() fix.

The real issue with ec0c69569 was that Python earlier than 3.9
doesn&#39;t allow parens around &#39;with&#39; args, which are
superfluous anyway. There&#39;s no need for extra code to hide the
encoding arg from Python 2.

TESTED:
Still &quot;works&quot; (expected error with no gpsd running) with
Python 2.6, 2.7, and 3.2-3.12.

- - - - -


1 changed file:

- clients/gegps.py.in


Changes:

=====================================
clients/gegps.py.in
=====================================
@@ -50,14 +50,6 @@ KML_OPEN_IN_GE = '''\
 </kml>
 '''
 
-if str is bytes:
-    polyopen = open
-else:
-
-    def polyopen(filename, mode):
-        """Open a file with utf-8 encoding to silence linters."""
-        return open(filename, mode, encoding="utf-8")
-
 
 def kmlize(tpv):
     """Kmlize.
@@ -189,9 +181,9 @@ if __name__ == "__main__":
             sys.exit(0)
 
     if options.initialize:
-        with polyopen(os.path.join(options.kmldir,
-                      'Open_in_Google_Earth_RT_GPS.kml'), 'w',
-                      ) as f:
+        with open(os.path.join(options.kmldir,
+                  'Open_in_Google_Earth_RT_GPS.kml'), 'w',
+                  encoding="utf8") as f:
             f.write(KML_OPEN_IN_GE)
         sys.exit(0)
 
@@ -211,8 +203,8 @@ if __name__ == "__main__":
                 continue
 
             if 'TPV' == session.data['class']:
-                with polyopen(os.path.join(options.kmldir,
-                              'Realtime_GPS.kml'), 'w') as f:
+                with open(os.path.join(options.kmldir,
+                          'Realtime_GPS.kml'), 'w', encoding="utf8")
as f: f.write(kmlize(session.data))
     except KeyboardInterrupt:
         print('gegps stopped ')



View it on GitLab:
https://gitlab.com/gpsd/gpsd/-/commit/69e99cd86b0844a35a49d99780e4e3bf72f352f3




RGDS
GARY
---------------------------------------------------------------------------
Gary E. Miller Rellim 109 NW Wilmington Ave., Suite E, Bend, OR 97703
        gem@rellim.com  Tel:+1 541 382 8588

            Veritas liberabit vos. -- Quid est veritas?
    "If you can't measure it, you can't improve it." - Lord Kelvin

Fred Wright pushed to branch master at gpsd / gpsd

Commits:

  • 69e99cd8
    by Fred Wright at 2023-12-12T22:21:01-08:00
    gegps: Simplify open() fix.
    
    The real issue with ec0c69569 was that Python earlier than 3.9 doesn't
    allow parens around 'with' args, which are superfluous anyway.
    There's no need for extra code to hide the encoding arg from Python 2.
    
    TESTED:
    Still "works" (expected error with no gpsd running) with Python 2.6,
    2.7, and 3.2-3.12.
    

1 changed file:

Changes:

  • clients/gegps.py.in
    ... ... @@ -50,14 +50,6 @@ KML_OPEN_IN_GE = '''\
    50 50
     </kml>
    
    51 51
     '''
    
    52 52
     
    
    53
    -if str is bytes:
    
    54
    -    polyopen = open
    
    55
    -else:
    
    56
    -
    
    57
    -    def polyopen(filename, mode):
    
    58
    -        """Open a file with utf-8 encoding to silence linters."""
    
    59
    -        return open(filename, mode, encoding="utf-8")
    
    60
    -
    
    61 53
     
    
    62 54
     def kmlize(tpv):
    
    63 55
         """Kmlize.
    
    ... ... @@ -189,9 +181,9 @@ if __name__ == "__main__":
    189 181
                 sys.exit(0)
    
    190 182
     
    
    191 183
         if options.initialize:
    
    192
    -        with polyopen(os.path.join(options.kmldir,
    
    193
    -                      'Open_in_Google_Earth_RT_GPS.kml'), 'w',
    
    194
    -                      ) as f:
    
    184
    +        with open(os.path.join(options.kmldir,
    
    185
    +                  'Open_in_Google_Earth_RT_GPS.kml'), 'w',
    
    186
    +                  encoding="utf8") as f:
    
    195 187
                 f.write(KML_OPEN_IN_GE)
    
    196 188
             sys.exit(0)
    
    197 189
     
    
    ... ... @@ -211,8 +203,8 @@ if __name__ == "__main__":
    211 203
                     continue
    
    212 204
     
    
    213 205
                 if 'TPV' == session.data['class']:
    
    214
    -                with polyopen(os.path.join(options.kmldir,
    
    215
    -                              'Realtime_GPS.kml'), 'w') as f:
    
    206
    +                with open(os.path.join(options.kmldir,
    
    207
    +                          'Realtime_GPS.kml'), 'w', encoding="utf8") as f:
    
    216 208
                         f.write(kmlize(session.data))
    
    217 209
         except KeyboardInterrupt:
    
    218 210
             print('gegps stopped ')
    

  • Attachment: pgpWPOym5oDRw.pgp
    Description: OpenPGP digital signature


    reply via email to

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