[Python-modules-commits] [osmalchemy] 01/03: New upstream version 0.1.3

Dominik George natureshadow-guest at moszumanska.debian.org
Wed Jan 25 17:19:18 UTC 2017


This is an automated email from the git hooks/post-receive script.

natureshadow-guest pushed a commit to branch master
in repository osmalchemy.

commit a989676df40c7d95b0a8021dfa238f929c6f1030
Author: Dominik George <nik at naturalnet.de>
Date:   Wed Jan 25 17:37:16 2017 +0100

    New upstream version 0.1.3
---
 AUTHORS                         |  3 ++
 CHANGELOG                       |  8 ++++
 MANIFEST.in                     |  1 +
 OSMAlchemy.egg-info/PKG-INFO    |  2 +-
 OSMAlchemy.egg-info/SOURCES.txt |  1 +
 PKG-INFO                        |  2 +-
 osmalchemy/__init__.py          |  2 +-
 osmalchemy/util/online.py       | 43 ++++++++++++-------
 test/test_util_online.py        | 95 ++++++++++++++++++++++++++++++++++++++---
 9 files changed, 131 insertions(+), 26 deletions(-)

diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..b94cd11
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,3 @@
+Dominik George <nik at naturalnet.de>
+Eike „Eckehardt“ Tim Jesinghaus <eike at naturalnet.de>
+mirabilos <t.glaser at tarent.de>
diff --git a/CHANGELOG b/CHANGELOG
index c9ff905..c50ea18 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,14 @@
 Changelog for OSMAlchemy
 ========================
 
+0.1.3
+-----
+
+ * Fix float formatting (avoid scientific notation) for bounding boxes.
+   + Found by mirabilos during Veripeditus development.
+ * Fix support for <= and >= operators in bounding box query.
+ * Fix escaping of tag queries.
+
 0.1.2
 -----
 
diff --git a/MANIFEST.in b/MANIFEST.in
index 988b5e6..7eb3363 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,5 +1,6 @@
 include LICENSE
 include ODBL
 include CHANGELOG
+include AUTHORS
 include test/__init__.py
 include test/data/schwarzrheindorf.osm
diff --git a/OSMAlchemy.egg-info/PKG-INFO b/OSMAlchemy.egg-info/PKG-INFO
index 235c1b8..59b3916 100644
--- a/OSMAlchemy.egg-info/PKG-INFO
+++ b/OSMAlchemy.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: OSMAlchemy
-Version: 0.1.2
+Version: 0.1.3
 Summary: OpenStreetMap to SQLAlchemy bridge
 Home-page: https://github.com/Veripeditus/OSMAlchemy
 Author: Dominik George, Eike Tim Jesinghaus
diff --git a/OSMAlchemy.egg-info/SOURCES.txt b/OSMAlchemy.egg-info/SOURCES.txt
index 3f7d2ed..0171f8e 100644
--- a/OSMAlchemy.egg-info/SOURCES.txt
+++ b/OSMAlchemy.egg-info/SOURCES.txt
@@ -1,3 +1,4 @@
+AUTHORS
 CHANGELOG
 LICENSE
 MANIFEST.in
diff --git a/PKG-INFO b/PKG-INFO
index 235c1b8..59b3916 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: OSMAlchemy
-Version: 0.1.2
+Version: 0.1.3
 Summary: OpenStreetMap to SQLAlchemy bridge
 Home-page: https://github.com/Veripeditus/OSMAlchemy
 Author: Dominik George, Eike Tim Jesinghaus
diff --git a/osmalchemy/__init__.py b/osmalchemy/__init__.py
index d8d2f50..6819229 100644
--- a/osmalchemy/__init__.py
+++ b/osmalchemy/__init__.py
@@ -1,7 +1,7 @@
 # ~*~~ coding: utf-8 ~*~
 
 # Define the version of OSMAlchemy
-__version__ = "0.1.2"
+__version__ = "0.1.3"
 
 # Monkey patch SQLAlchemy to support some query constructs
 from .util.patch import monkey_patch_sqlalchemy, monkey_patch_flask_restless
diff --git a/osmalchemy/util/online.py b/osmalchemy/util/online.py
index d30a426..9e92981 100644
--- a/osmalchemy/util/online.py
+++ b/osmalchemy/util/online.py
@@ -1,8 +1,9 @@
 ## ~*~ coding: utf-8 ~*~
 #-
 # OSMAlchemy - OpenStreetMap to SQLAlchemy bridge
-# Copyright (c) 2016 Dominik George <nik at naturalnet.de>
+# Copyright (c) 2016, 2017 Dominik George <nik at naturalnet.de>
 # Copyright (c) 2016 Eike Tim Jesinghaus <eike at naturalnet.de>
+# Copyright (c) 2017 mirabilos <thorsten.glaser at teckids.org>
 #
 # Permission is hereby granted, free of charge, to any person obtaining a copy
 # of this software and associated documentation files (the "Software"), to deal
@@ -245,7 +246,7 @@ def _trees_to_overpassql(tree_dict):
                     # Parse atom
 
                     # latitude and longitude comparisons form a bounding box
-                    if element[1] == "latitude" and element[0] == ">":
+                    if element[1] == "latitude" and element[0] in [">", ">="]:
                         # South edge
                         if bbox[0] is None:
                             bbox[0] = float(element[2])
@@ -253,7 +254,7 @@ def _trees_to_overpassql(tree_dict):
                             bbox[0] = float(element[2])
                         elif op == "||" and bbox[0] >= element[2]:
                             bbox[0] = float(element[2])
-                    elif element[1] == "latitude" and element[0] == "<":
+                    elif element[1] == "latitude" and element[0] in ["<", "<="]:
                         # North edge
                         if bbox[2] is None:
                             bbox[2] = float(element[2])
@@ -261,7 +262,7 @@ def _trees_to_overpassql(tree_dict):
                             bbox[2] = float(element[2])
                         elif op == "||" and bbox[2] <= element[2]:
                             bbox[2] = float(element[2])
-                    elif element[1] == "longitude" and element[0] == ">":
+                    elif element[1] == "longitude" and element[0] in [">", ">="]:
                         # West edge
                         if bbox[1] is None:
                             bbox[1] = float(element[2])
@@ -269,7 +270,7 @@ def _trees_to_overpassql(tree_dict):
                             bbox[1] = float(element[2])
                         elif op == "||" and bbox[1] >= element[2]:
                             bbox[1] = float(element[2])
-                    elif element[1] == "longitude" and element[0] == "<":
+                    elif element[1] == "longitude" and element[0] in ["<", "<="]:
                         # East edge
                         if bbox[3] is None:
                             bbox[3] = float(element[2])
@@ -301,14 +302,14 @@ def _trees_to_overpassql(tree_dict):
                         if element[0] == "==":
                             # Build query for tag comparison
                             if op == "||":
-                                tagquery = "%s[\"%s\"=\"%s\"]" % (type_, element[1], element[2])
+                                tagquery = "%s[\"%s\"=\"%s\"]" % (type_, _escape_tag(element[1]), _escape_tag(element[2]))
                             elif op == "&&":
-                                tagquery = "[\"%s\"=\"%s\"]" % (element[1], element[2])
+                                tagquery = "[\"%s\"=\"%s\"]" % (_escape_tag(element[1]), _escape_tag(element[2]))
                         elif element[0] == "has":
                             if op == "||":
-                                tagquery = "%s[\"%s\"]" % (type_, element[1])
+                                tagquery = "%s[\"%s\"]" % (type_, _escape_tag(element[1]))
                             elif op == "&&":
-                                tagquery = "[\"%s\"]" % (element[1])
+                                tagquery = "[\"%s\"]" % (_escape_tag(element[1]))
 
                         # Store resulting query and its name
                         set_name = "s%i" % id(tagquery)
@@ -332,9 +333,9 @@ def _trees_to_overpassql(tree_dict):
 
                 # Build query
                 if op == "||":
-                    bboxquery = "%s(%s,%s,%s,%s)" % (type_, bbox[0], bbox[1], bbox[2], bbox[3])
+                    bboxquery = "%s(%.7f,%.7f,%.7f,%.7f)" % (type_, bbox[0], bbox[1], bbox[2], bbox[3])
                 elif op == "&&":
-                    bboxquery = "(%s,%s,%s,%s)" % (bbox[0], bbox[1], bbox[2], bbox[3])
+                    bboxquery = "(%.7f,%.7f,%.7f,%.7f)" % (bbox[0], bbox[1], bbox[2], bbox[3])
                 # Store resulting query and its name
                 set_name = "s%i" % id(bboxquery)
                 if op == "||":
@@ -365,16 +366,16 @@ def _trees_to_overpassql(tree_dict):
             # latitude and longitude are components of a bounding box query
             if tree[1] == "latitude" and tree[0] == ">":
                 # South edge
-                result = "%s(%s,-180.0,90.0,180.0)" % (type_, tree[2])
+                result = "%s(%.7f,-180.0,90.0,180.0)" % (type_, float(tree[2]))
             elif tree[1] == "latitude" and tree[0] == "<":
                 # West edge
-                result = "%s(-90.0,-180.0,%s,180.0)" % (type_, tree[2])
+                result = "%s(-90.0,-180.0,%.7f,180.0)" % (type_, float(tree[2]))
             elif tree[1] == "longitude" and tree[0] == ">":
                 # North edge
-                result = "%s(-90.0,%s,-90.0,180.0)" % (type_, tree[2])
+                result = "%s(-90.0,%.7f,-90.0,180.0)" % (type_, float(tree[2]))
             elif tree[1] == "longitude" and tree[0] == "<":
                 # East edge
-                result = "%s(-90.0,-180.0,-90.0,%s)" % (type_, tree[2])
+                result = "%s(-90.0,-180.0,-90.0,%.7f)" % (type_, float(tree[2]))
             # Query for an id
             elif tree[1] == "id" and tree[0] == "==":
                 result = "%s(%i)" % (type_, tree[2])
@@ -383,7 +384,7 @@ def _trees_to_overpassql(tree_dict):
                 raise ValueError("id can only be queried with equality")
             # Everything else must be a tag query
             else:
-                result = "%s[\"%s\"=\"%s\"]" % (type_, tree[1], tree[2])
+                result = "%s[\"%s\"=\"%s\"]" % (type_, _escape_tag(tree[1]), _escape_tag(tree[2]))
 
         # generate a name for the complete set and return it, along with the query
         set_name = id(result)
@@ -423,3 +424,13 @@ def _normalise_overpassql(oql):
             return match.group()
 
     return re.sub(r'"[^"]*"|([^"]*)', replace_setname, oql)
+
+def _escape_tag(tag):
+    """ Escapes special characters in a tag query component. """
+
+    res = tag
+
+    res = res.replace('\\', '\\\\')
+    res = res.replace('"', '\\"')
+
+    return res
diff --git a/test/test_util_online.py b/test/test_util_online.py
index 47471e3..9c42b4a 100644
--- a/test/test_util_online.py
+++ b/test/test_util_online.py
@@ -2,7 +2,7 @@
 # ~*~ coding: utf-8 ~*~
 #-
 # OSMAlchemy - OpenStreetMap to SQLAlchemy bridge
-# Copyright (c) 2016 Dominik George <nik at naturalnet.de>
+# Copyright (c) 2016, 2017 Dominik George <nik at naturalnet.de>
 #
 # Permission is hereby granted, free of charge, to any person obtaining a copy
 # of this software and associated documentation files (the "Software"), to deal
@@ -43,7 +43,24 @@ class OSMAlchemyUtilOnlineSQLToOverpassQLTests(unittest.TestCase):
                                    (">", "longitude", 7.0), ("<", "longitude", 8.0)])}
 
         # Expected result regex
-        expected = r"^node\(51\.0,7\.0,52\.0,8\.0\)->\.s[0-9]+;\(\.s[0-9]+;\);$"
+        expected = r"^node\(51\.0000000,7\.0000000,52\.0000000,8\.0000000\)->\.s[0-9]+;\(\.s[0-9]+;\);$"
+
+        # Run transformation
+        res = _trees_to_overpassql(tree)
+
+        # Check result
+        self.assertRegexpMatches(res, expected)
+
+    def test_trees_to_overpassql_bbox_node_le_ge(self):
+        # Import function to test
+        from osmalchemy.util.online import _trees_to_overpassql
+
+        # Test input
+        tree = {"OSMNode": ("&&", [(">=", "latitude", 51.0), ("<=", "latitude", 52.0),
+                                   (">=", "longitude", 7.0), ("<=", "longitude", 8.0)])}
+
+        # Expected result regex
+        expected = r"^node\(51\.0000000,7\.0000000,52\.0000000,8\.0000000\)->\.s[0-9]+;\(\.s[0-9]+;\);$"
 
         # Run transformation
         res = _trees_to_overpassql(tree)
@@ -60,7 +77,7 @@ class OSMAlchemyUtilOnlineSQLToOverpassQLTests(unittest.TestCase):
                                    (">", "longitude", 7.0)])}
 
         # Expected result regex
-        expected = r"^node\(51\.0,7\.0,52\.0,180\.0\)->\.s[0-9]+;\(\.s[0-9]+;\);$"
+        expected = r"^node\(51\.0000000,7\.0000000,52\.0000000,180\.0000000\)->\.s[0-9]+;\(\.s[0-9]+;\);$"
 
         # Run transformation
         res = _trees_to_overpassql(tree)
@@ -77,7 +94,7 @@ class OSMAlchemyUtilOnlineSQLToOverpassQLTests(unittest.TestCase):
                                    ("<", "longitude", 8.0)])}
 
         # Expected result regex
-        expected = r"^node\(51\.0,-180\.0,52\.0,8\.0\)->\.s[0-9]+;\(\.s[0-9]+;\);$"
+        expected = r"^node\(51\.0000000,-180\.0000000,52\.0000000,8\.0000000\)->\.s[0-9]+;\(\.s[0-9]+;\);$"
 
         # Run transformation
         res = _trees_to_overpassql(tree)
@@ -94,7 +111,7 @@ class OSMAlchemyUtilOnlineSQLToOverpassQLTests(unittest.TestCase):
                                    (">", "longitude", 7.0), ("<", "longitude", 8.0)])}
 
         # Expected result regex
-        expected = r"^node\(51\.0,7\.0,90\.0,8\.0\)->\.s[0-9]+;\(\.s[0-9]+;\);$"
+        expected = r"^node\(51\.0000000,7\.0000000,90\.0000000,8\.0000000\)->\.s[0-9]+;\(\.s[0-9]+;\);$"
 
         # Run transformation
         res = _trees_to_overpassql(tree)
@@ -111,7 +128,7 @@ class OSMAlchemyUtilOnlineSQLToOverpassQLTests(unittest.TestCase):
                                    (">", "longitude", 7.0), ("<", "longitude", 8.0)])}
 
         # Expected result regex
-        expected = r"^node\(-90\.0,7\.0,52\.0,8\.0\)->\.s[0-9]+;\(\.s[0-9]+;\);$"
+        expected = r"^node\(-90\.0000000,7\.0000000,52\.0000000,8\.0000000\)->\.s[0-9]+;\(\.s[0-9]+;\);$"
 
         # Run transformation
         res = _trees_to_overpassql(tree)
@@ -189,7 +206,7 @@ class OSMAlchemyUtilOnlineSQLToOverpassQLTests(unittest.TestCase):
                                    (">", "longitude", 7.0), ("<", "longitude", 8.0)])}
 
         # Expected result regex
-        expected = r"^node\[\"amenity\"=\"pub\"\]\[\"name\"=\"Bruchbude\"\]\(51\.0,7\.0,52\.0,8\.0\)->\.s[0-9]+;\(\.s[0-9]+;\);$"
+        expected = r"^node\[\"amenity\"=\"pub\"\]\[\"name\"=\"Bruchbude\"\]\(51\.0000000,7\.0000000,52\.0000000,8\.0000000\)->\.s[0-9]+;\(\.s[0-9]+;\);$"
 
         # Run transformation
         res = _trees_to_overpassql(tree)
@@ -229,6 +246,70 @@ class OSMAlchemyUtilOnlineSQLToOverpassQLTests(unittest.TestCase):
         # Check result
         self.assertEqual(res, normalised_oql)
 
+    def test_escape_tag_nothing(self):
+        # Import function to test
+        from osmalchemy.util.online import _escape_tag
+
+        # Test string
+        tag = "foobar"
+
+        # Expected result
+        escaped_tag = "foobar"
+
+        # Run function
+        res = _escape_tag(tag)
+
+        # Check result
+        self.assertEqual(res, escaped_tag)
+
+    def test_escape_tag_quote(self):
+        # Import function to test
+        from osmalchemy.util.online import _escape_tag
+
+        # Test string
+        tag = "foo\"bar"
+
+        # Expected result
+        escaped_tag = "foo\\\"bar"
+
+        # Run function
+        res = _escape_tag(tag)
+
+        # Check result
+        self.assertEqual(res, escaped_tag)
+
+    def test_escape_tag_backslash(self):
+        # Import function to test
+        from osmalchemy.util.online import _escape_tag
+
+        # Test string
+        tag = "foo\\bar"
+
+        # Expected result
+        escaped_tag = "foo\\\\bar"
+
+        # Run function
+        res = _escape_tag(tag)
+
+        # Check result
+        self.assertEqual(res, escaped_tag)
+
+    def test_escape_tag_quote_backslash(self):
+        # Import function to test
+        from osmalchemy.util.online import _escape_tag
+
+        # Test string
+        tag = "foo\\\"bar"
+
+        # Expected result
+        escaped_tag = "foo\\\\\\\"bar"
+
+        # Run function
+        res = _escape_tag(tag)
+
+        # Check result
+        self.assertEqual(res, escaped_tag)
+
 # Make runnable as standalone script
 if __name__ == "__main__":
     unittest.main()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/osmalchemy.git



More information about the Python-modules-commits mailing list