Commit 6c3c6b3d by Billy Tobon

fix regex bug

regex wasn't parsing negative latitudes.
parent 99fb1d27
......@@ -120,8 +120,8 @@ class ParseObject(ParseBase):
def _isGeoPoint(self, value):
if isinstance(value, str):
return re.search("\\bPOINT\\(\\b([-+]?\\d*\\.\\d+|\\d+) " +
"([-+]?\\d*\\.\\d+|\\d+)\\)", value, re.I)
return re.search("\\bPOINT\\(([-+]?[0-9]*\\.?[0-9]*) " +
"([-+]?[0-9]*\\.?[0-9]*)\\)", value, re.I)
def _populateFromDict(self, attrs_dict):
if 'objectId' in attrs_dict:
......@@ -152,7 +152,9 @@ class ParseObject(ParseBase):
value = {'__type': 'Bytes',
'base64': base64.b64encode(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',
'latitude': float(coordinates[0]),
'longitude': float(coordinates[1])}
......
......@@ -26,7 +26,7 @@ def test_obj(saved=False):
ret.score = 1337
ret.playerName = "Sean Plott"
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:
ret.save()
return ret
......@@ -49,7 +49,7 @@ class TestParseObjectAndQuery(unittest.TestCase):
# TODO: str vs unicode
#self.assertEqual(o.playerName.__class__, unicode)
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):
"""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