Commit 6bdb2866 by Raphael Lullis

Cleaning up the code a little bit, and removing all print statements from code…

Cleaning up the code a little bit, and removing all print statements from code (WSGI does not accept them)
parent 5a774a64
...@@ -36,28 +36,21 @@ class ParseBase(object): ...@@ -36,28 +36,21 @@ class ParseBase(object):
request = urllib2.Request(url, data) request = urllib2.Request(url, data)
request.add_header('Content-type', 'application/json') request.add_header('Content-type', 'application/json')
request.add_header('X-Parse-Application-Id', APPLICATION_ID)
#auth_header = "Basic %s" % base64.b64encode('%s:%s' % request.add_header('X-Parse-REST-API-Key', MASTER_KEY)
# (APPLICATION_ID, MASTER_KEY))
#request.add_header("Authorization", auth_header)
request.add_header("X-Parse-Application-Id", APPLICATION_ID)
request.add_header("X-Parse-REST-API-Key", MASTER_KEY)
request.get_method = lambda: http_verb request.get_method = lambda: http_verb
# TODO: add error handling for server response # TODO: add error handling for server response
response = urllib2.urlopen(request) response = urllib2.urlopen(request)
response_body = response.read() response_body = response.read()
response_dict = json.loads(response_body) return json.loads(response_body)
return response_dict
def _ISO8601ToDatetime(self, date_string): def _ISO8601ToDatetime(self, date_string):
# TODO: verify correct handling of timezone # TODO: verify correct handling of timezone
date_string = date_string[:-1] + 'UTC' date_string = date_string[:-1] + 'UTC'
date = datetime.datetime.strptime(date_string, return datetime.datetime.strptime(date_string, '%Y-%m-%dT%H:%M:%S.%f%Z')
"%Y-%m-%dT%H:%M:%S.%f%Z")
return date
class ParseObject(ParseBase): class ParseObject(ParseBase):
...@@ -120,8 +113,8 @@ class ParseObject(ParseBase): ...@@ -120,8 +113,8 @@ class ParseObject(ParseBase):
def _isGeoPoint(self, value): def _isGeoPoint(self, value):
if isinstance(value, str): if isinstance(value, str):
return re.search("\\bPOINT\\(([-+]?[0-9]*\\.?[0-9]*) " + return re.search('\\bPOINT\\(([-+]?[0-9]*\\.?[0-9]*) ' +
"([-+]?[0-9]*\\.?[0-9]*)\\)", 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,9 +145,7 @@ class ParseObject(ParseBase): ...@@ -152,9 +145,7 @@ 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):
print value coordinates = re.findall('[-+]?[0-9]+\\.?[0-9]*', value)
coordinates = re.findall("[-+]?[0-9]+\\.?[0-9]*", value)
print coordinates
value = {'__type': 'GeoPoint', value = {'__type': 'GeoPoint',
'longitude': float(coordinates[0]), 'longitude': float(coordinates[0]),
'latitude': float(coordinates[1])} 'latitude': float(coordinates[1])}
......
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