[Git][debian-gis-team/python-osmapi][upstream] New upstream version 1.3.0

Bas Couwenberg gitlab at salsa.debian.org
Mon Oct 5 04:46:53 BST 2020



Bas Couwenberg pushed to branch upstream at Debian GIS Project / python-osmapi


Commits:
4e87497e by Bas Couwenberg at 2020-10-05T05:38:16+02:00
New upstream version 1.3.0
- - - - -


7 changed files:

- .gitignore
- CHANGELOG.md
- osmapi/OsmApi.py
- osmapi/__init__.py
- tests/changeset_tests.py
- + tests/fixtures/passwordfile_colon.txt
- tests/helper_tests.py


Changes:

=====================================
.gitignore
=====================================
@@ -4,3 +4,4 @@ MANIFEST
 *.egg-info
 .coverage
 .tox
+.pycache/*


=====================================
CHANGELOG.md
=====================================
@@ -4,6 +4,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
 
 ## [Unreleased][unreleased]
 
+## 1.3.0 - 2020-10-05
+### Added
+- Add close() method to close the underlying http session (see issue #107)
+- Add context manager to automatically open and close the http session (see issue #107)
+
+### Fixed
+- Correctly parse password file (thanks [Julien Palard](https://github.com/JulienPalard), see pull request #106)
+
 ## 1.2.2 - 2018-11-05
 ### Fixed
 - Update PyPI password for deployment


=====================================
osmapi/OsmApi.py
=====================================
@@ -206,17 +206,19 @@ class OsmApi:
         if username:
             self._username = username
         elif passwordfile:
-            pass_line = open(passwordfile).readline()
+            with open(passwordfile) as f:
+                pass_line = f.readline()
             self._username = pass_line.split(":")[0].strip()
 
         # Get password
         if password:
             self._password = password
         elif passwordfile:
-            for line in open(passwordfile).readlines():
-                line = line.strip().split(":")
-                if line[0] == self._username:
-                    self._password = line[1]
+            with open(passwordfile) as f:
+                for line in f:
+                    line = line.strip().split(":", 1)
+                    if line[0] == self._username:
+                        self._password = line[1]
 
         # Changest informations
         # auto create and close changesets
@@ -249,13 +251,26 @@ class OsmApi:
         self._session = self._get_http_session()
 
     def __del__(self):
+        self.close()
+
+        return None
+
+    def __enter__(self):
+        self._session = self._get_http_session()
+        return self
+
+    def __exit__(self, *args):
+        self.close()
+
+    def close(self):
         try:
             if self._changesetauto:
                 self._changesetautoflush(True)
         except ResponseEmptyApiError:
             pass
 
-        return None
+        if self._session:
+            self._session.close()
 
     ##################################################
     # Capabilities                                   #


=====================================
osmapi/__init__.py
=====================================
@@ -1,5 +1,5 @@
 from __future__ import (absolute_import, print_function, unicode_literals)
 
-__version__ = '1.2.2'
+__version__ = '1.3.0'
 
 from .OsmApi import *  # noqa


=====================================
tests/changeset_tests.py
=====================================
@@ -92,10 +92,10 @@ class TestOsmApiChangeset(osmapi_tests.TestOsmApi):
             xmltosorteddict(kwargs['data']),
             xmltosorteddict(
                 b'<?xml version="1.0" encoding="UTF-8"?>\n'
-                b'<osm version="0.6" generator="osmapi/1.2.2">\n'
+                b'<osm version="0.6" generator="osmapi/1.3.0">\n'
                 b'  <changeset visible="true">\n'
                 b'    <tag k="test" v="foobar"/>\n'
-                b'    <tag k="created_by" v="osmapi/1.2.2"/>\n'
+                b'    <tag k="created_by" v="osmapi/1.3.0"/>\n'
                 b'  </changeset>\n'
                 b'</osm>\n'
             )
@@ -125,7 +125,7 @@ class TestOsmApiChangeset(osmapi_tests.TestOsmApi):
             xmltosorteddict(kwargs['data']),
             xmltosorteddict(
                 b'<?xml version="1.0" encoding="UTF-8"?>\n'
-                b'<osm version="0.6" generator="osmapi/1.2.2">\n'
+                b'<osm version="0.6" generator="osmapi/1.3.0">\n'
                 b'  <changeset visible="true">\n'
                 b'    <tag k="test" v="foobar"/>\n'
                 b'    <tag k="created_by" v="MyTestOSMApp"/>\n'
@@ -163,10 +163,10 @@ class TestOsmApiChangeset(osmapi_tests.TestOsmApi):
             xmltosorteddict(kwargs['data']),
             xmltosorteddict(
                 b'<?xml version="1.0" encoding="UTF-8"?>\n'
-                b'<osm version="0.6" generator="osmapi/1.2.2">\n'
+                b'<osm version="0.6" generator="osmapi/1.3.0">\n'
                 b'  <changeset visible="true">\n'
                 b'    <tag k="foobar" v="A new test changeset"/>\n'
-                b'    <tag k="created_by" v="osmapi/1.2.2"/>\n'
+                b'    <tag k="created_by" v="osmapi/1.3.0"/>\n'
                 b'  </changeset>\n'
                 b'</osm>\n'
             )
@@ -190,7 +190,7 @@ class TestOsmApiChangeset(osmapi_tests.TestOsmApi):
             xmltosorteddict(kwargs['data']),
             xmltosorteddict(
                 b'<?xml version="1.0" encoding="UTF-8"?>\n'
-                b'<osm version="0.6" generator="osmapi/1.2.2">\n'
+                b'<osm version="0.6" generator="osmapi/1.3.0">\n'
                 b'  <changeset visible="true">\n'
                 b'    <tag k="foobar" v="A new test changeset"/>\n'
                 b'    <tag k="created_by" v="CoolTestApp"/>\n'
@@ -276,7 +276,7 @@ class TestOsmApiChangeset(osmapi_tests.TestOsmApi):
             xmltosorteddict(kwargs['data']),
             xmltosorteddict(
                 b'<?xml version="1.0" encoding="UTF-8"?>\n'
-                b'<osmChange version="0.6" generator="osmapi/1.2.2">\n'
+                b'<osmChange version="0.6" generator="osmapi/1.3.0">\n'
                 b'<create>\n'
                 b'  <node lat="47.123" lon="8.555" visible="true" '
                 b'changeset="4444">\n'
@@ -350,7 +350,7 @@ class TestOsmApiChangeset(osmapi_tests.TestOsmApi):
             xmltosorteddict(kwargs['data']),
             xmltosorteddict(
                 b'<?xml version="1.0" encoding="UTF-8"?>\n'
-                b'<osmChange version="0.6" generator="osmapi/1.2.2">\n'
+                b'<osmChange version="0.6" generator="osmapi/1.3.0">\n'
                 b'<modify>\n'
                 b'  <way id="4294967296" version="2" visible="true" '
                 b'changeset="4444">\n'
@@ -434,7 +434,7 @@ class TestOsmApiChangeset(osmapi_tests.TestOsmApi):
             xmltosorteddict(kwargs['data']),
             xmltosorteddict(
                 b'<?xml version="1.0" encoding="UTF-8"?>\n'
-                b'<osmChange version="0.6" generator="osmapi/1.2.2">\n'
+                b'<osmChange version="0.6" generator="osmapi/1.3.0">\n'
                 b'<delete>\n'
                 b'  <relation id="676" version="2" visible="true" '
                 b'changeset="4444">\n'


=====================================
tests/fixtures/passwordfile_colon.txt
=====================================
@@ -0,0 +1,2 @@
+testosm:testpass
+testuser:test:userpass


=====================================
tests/helper_tests.py
=====================================
@@ -23,6 +23,7 @@ class TestOsmApiHelper(osmapi_tests.TestOsmApi):
         mock_response.reason = "test reason"
         mock_response.content = 'test response'
         self.api._session.request = mock.Mock(return_value=mock_response)
+        self.api._session.close = mock.Mock()
         self.api._username = 'testuser'
         self.api._password = 'testpassword'
 
@@ -46,6 +47,25 @@ class TestOsmApiHelper(osmapi_tests.TestOsmApi):
         self.assertEquals('testuser', my_api._username)
         self.assertEquals('testuserpass', my_api._password)
 
+    def test_passwordfile_with_colon(self):
+        path = os.path.join(
+            __location__,
+            'fixtures',
+            'passwordfile_colon.txt'
+        )
+        my_api = osmapi.OsmApi(username='testuser', passwordfile=path)
+        self.assertEquals('testuser', my_api._username)
+        self.assertEquals('test:userpass', my_api._password)
+
+    def test_close_call(self):
+        self.api.close()
+        self.assertEquals(self.api._session.close.call_count, 1)
+
+    def test_close_context_manager(self):
+        with osmapi.OsmApi() as my_api:
+            my_api._session.close = mock.Mock()
+        self.assertEquals(my_api._session.close.call_count, 1)
+
     def test_http_request_get(self):
         response = self.api._http_request(
             'GET',



View it on GitLab: https://salsa.debian.org/debian-gis-team/python-osmapi/-/commit/4e87497e0ad42d547d4487e9f575fd20fe68211e

-- 
View it on GitLab: https://salsa.debian.org/debian-gis-team/python-osmapi/-/commit/4e87497e0ad42d547d4487e9f575fd20fe68211e
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-grass-devel/attachments/20201005/cfb8b414/attachment-0001.html>


More information about the Pkg-grass-devel mailing list