Commit 6c3c6b3d by Billy Tobon

fix regex bug

regex wasn't parsing negative latitudes.
parent 99fb1d27
...@@ -120,8 +120,8 @@ class ParseObject(ParseBase): ...@@ -120,8 +120,8 @@ class ParseObject(ParseBase):
def _isGeoPoint(self, value): def _isGeoPoint(self, value):
if isinstance(value, str): if isinstance(value, str):
return re.search("\\bPOINT\\(\\b([-+]?\\d*\\.\\d+|\\d+) " + return re.search("\\bPOINT\\(([-+]?[0-9]*\\.?[0-9]*) " +
"([-+]?\\d*\\.\\d+|\\d+)\\)", value, re.I) "([-+]?[0-9]*\\.?[0-9]*)\\)", value, re.I)
def _populateFromDict(self, attrs_dict): def _populateFromDict(self, attrs_dict):
if 'objectId' in attrs_dict: if 'objectId' in attrs_dict:
...@@ -152,7 +152,9 @@ class ParseObject(ParseBase): ...@@ -152,7 +152,9 @@ class ParseObject(ParseBase):
value = {'__type': 'Bytes', value = {'__type': 'Bytes',
'base64': base64.b64encode(value)} 'base64': base64.b64encode(value)}
elif self._isGeoPoint(value): elif self._isGeoPoint(value):
coordinates = re.findall(r'[-+]?\d*\.\d+|\d+', value) print value
coordinates = re.findall("[-+]?[0-9]+\\.?[0-9]*", value)
print coordinates
value = {'__type': 'GeoPoint', value = {'__type': 'GeoPoint',
'latitude': float(coordinates[0]), 'latitude': float(coordinates[0]),
'longitude': float(coordinates[1])} 'longitude': float(coordinates[1])}
......
...@@ -26,7 +26,7 @@ def test_obj(saved=False): ...@@ -26,7 +26,7 @@ def test_obj(saved=False):
ret.score = 1337 ret.score = 1337
ret.playerName = "Sean Plott" ret.playerName = "Sean Plott"
ret.cheatMode = False ret.cheatMode = False
ret.location = "POINT(30.0 -43.21)" # "POINT(30 -43.21)" ret.location = "POINT(-30.0 43.21)" # "POINT(30 -43.21)"
if saved: if saved:
ret.save() ret.save()
return ret return ret
...@@ -49,7 +49,7 @@ class TestParseObjectAndQuery(unittest.TestCase): ...@@ -49,7 +49,7 @@ class TestParseObjectAndQuery(unittest.TestCase):
# TODO: str vs unicode # TODO: str vs unicode
#self.assertEqual(o.playerName.__class__, unicode) #self.assertEqual(o.playerName.__class__, unicode)
self.assertEqual(o.cheatMode.__class__, bool) self.assertEqual(o.cheatMode.__class__, bool)
self.assertEqual(o.location, "POINT(30.0 -43.21)") self.assertEqual(o.location, "POINT(-30.0 43.21)")
def test_object(self): def test_object(self):
"""Test the creation, retrieval and updating of a ParseObject""" """Test the creation, retrieval and updating of a ParseObject"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment