From dbbfb43929856dfef2c7dbddec39c2e9b8d0f304 Mon Sep 17 00:00:00 2001 From: Benny Lichtner Date: Tue, 16 Jun 2015 17:04:24 -0700 Subject: [PATCH 1/5] `long` is also a valid type --- geojson/geometry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geojson/geometry.py b/geojson/geometry.py index 30facc3..5139d4d 100644 --- a/geojson/geometry.py +++ b/geojson/geometry.py @@ -29,7 +29,7 @@ def clean_coordinates(cls, coords): for coord in coords: if isinstance(coord, (list, tuple)): cls.clean_coordinates(coord) - elif not isinstance(coord, (float, int, Decimal)): + elif not isinstance(coord, (float, int, Decimal, long)): raise ValueError("%r is not JSON compliant number" % coord) From 49d298d2f215fd13aa1c8af1afe6f4aedb8c4358 Mon Sep 17 00:00:00 2001 From: Benny Lichtner Date: Wed, 17 Jun 2015 12:25:55 -0700 Subject: [PATCH 2/5] Different JSON compliant types for python 2 and 3 --- geojson/geometry.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/geojson/geometry.py b/geojson/geometry.py index 5139d4d..fe4a87a 100644 --- a/geojson/geometry.py +++ b/geojson/geometry.py @@ -2,7 +2,6 @@ from geojson.base import GeoJSON - class Geometry(GeoJSON): """ Represents an abstract base class for a WGS84 geometry. @@ -23,13 +22,19 @@ def __init__(self, coordinates=None, crs=None, **extra): self.clean_coordinates(self["coordinates"]) if crs: self["crs"] = self.to_instance(crs, strict=True) + + if (sys.version_info[0] == 3): + # Python 3.x has no long type + self.JSON_compliant_types = (float, int, Decimal) + else: + self.JSON_compliant_types = (float, int, Decimal, long) @classmethod def clean_coordinates(cls, coords): for coord in coords: if isinstance(coord, (list, tuple)): cls.clean_coordinates(coord) - elif not isinstance(coord, (float, int, Decimal, long)): + elif not isinstance(coord, self.JSON_compliant_types): raise ValueError("%r is not JSON compliant number" % coord) From 877b381d82d0e56ea0764f67ba4f846e9c3d788c Mon Sep 17 00:00:00 2001 From: Benny Lichtner Date: Wed, 17 Jun 2015 14:53:25 -0700 Subject: [PATCH 3/5] Use class variable instead of instance variable --- geojson/geometry.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/geojson/geometry.py b/geojson/geometry.py index fe4a87a..ba3e042 100644 --- a/geojson/geometry.py +++ b/geojson/geometry.py @@ -1,12 +1,20 @@ from decimal import Decimal from geojson.base import GeoJSON +import sys + class Geometry(GeoJSON): """ Represents an abstract base class for a WGS84 geometry. """ + if (sys.version_info[0] == 3): + # Python 3.x has no long type + JSON_compliant_types = (float, int, Decimal) + else: + JSON_compliant_types = (float, int, Decimal, long) + def __init__(self, coordinates=None, crs=None, **extra): """ Initialises a Geometry object. @@ -22,19 +30,13 @@ def __init__(self, coordinates=None, crs=None, **extra): self.clean_coordinates(self["coordinates"]) if crs: self["crs"] = self.to_instance(crs, strict=True) - - if (sys.version_info[0] == 3): - # Python 3.x has no long type - self.JSON_compliant_types = (float, int, Decimal) - else: - self.JSON_compliant_types = (float, int, Decimal, long) @classmethod def clean_coordinates(cls, coords): for coord in coords: if isinstance(coord, (list, tuple)): cls.clean_coordinates(coord) - elif not isinstance(coord, self.JSON_compliant_types): + elif not isinstance(coord, cls.JSON_compliant_types): raise ValueError("%r is not JSON compliant number" % coord) From 7dfd4a1d5308cbebc0eca2ecd34cded0c21b322f Mon Sep 17 00:00:00 2001 From: Benny Lichtner Date: Wed, 17 Jun 2015 21:41:21 -0700 Subject: [PATCH 4/5] Make Travis ignore line that fails in Python 3 --- geojson/geometry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geojson/geometry.py b/geojson/geometry.py index ba3e042..9ff89ec 100644 --- a/geojson/geometry.py +++ b/geojson/geometry.py @@ -13,7 +13,7 @@ class Geometry(GeoJSON): # Python 3.x has no long type JSON_compliant_types = (float, int, Decimal) else: - JSON_compliant_types = (float, int, Decimal, long) + JSON_compliant_types = (float, int, Decimal, long) # noqa def __init__(self, coordinates=None, crs=None, **extra): """ From ad2d45304f4cddae9b5e4902b6f7678e9425314b Mon Sep 17 00:00:00 2001 From: Benny Lichtner Date: Wed, 24 Jun 2015 08:33:14 -0700 Subject: [PATCH 5/5] Oops, missing a space --- geojson/geometry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geojson/geometry.py b/geojson/geometry.py index 9ff89ec..fd312c4 100644 --- a/geojson/geometry.py +++ b/geojson/geometry.py @@ -13,7 +13,7 @@ class Geometry(GeoJSON): # Python 3.x has no long type JSON_compliant_types = (float, int, Decimal) else: - JSON_compliant_types = (float, int, Decimal, long) # noqa + JSON_compliant_types = (float, int, Decimal, long) # noqa def __init__(self, coordinates=None, crs=None, **extra): """