Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
ParsePy
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ParsePy
Commits
99fb1d27
Commit
99fb1d27
authored
Nov 05, 2012
by
David Robinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changes for pep8 compliance
parent
10e3bb94
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
11 deletions
+13
-11
__init__.py
+10
-8
tests.py
+3
-3
No files found.
__init__.py
View file @
99fb1d27
...
...
@@ -118,10 +118,11 @@ class ParseObject(ParseBase):
response_dict
=
self
.
_executeCall
(
uri
,
'GET'
)
self
.
_populateFromDict
(
response_dict
)
def
_isGeoPoint
(
self
,
value
):
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
\\
(
\\
b([-+]?
\\
d*
\\
.
\\
d+|
\\
d+) "
+
"([-+]?
\\
d*
\\
.
\\
d+|
\\
d+)
\\
)"
,
value
,
re
.
I
)
def
_populateFromDict
(
self
,
attrs_dict
):
if
'objectId'
in
attrs_dict
:
self
.
_object_id
=
attrs_dict
[
'objectId'
]
...
...
@@ -151,10 +152,10 @@ class ParseObject(ParseBase):
value
=
{
'__type'
:
'Bytes'
,
'base64'
:
base64
.
b64encode
(
value
)}
elif
self
.
_isGeoPoint
(
value
):
coordinates
=
re
.
findall
(
r'[-+]?\d*\.\d+|\d+'
,
value
)
value
=
{
'__type'
:
'GeoPoint'
,
'latitude'
:
float
(
coordinates
[
0
]),
'longitude'
:
float
(
coordinates
[
1
])}
coordinates
=
re
.
findall
(
r'[-+]?\d*\.\d+|\d+'
,
value
)
value
=
{
'__type'
:
'GeoPoint'
,
'latitude'
:
float
(
coordinates
[
0
]),
'longitude'
:
float
(
coordinates
[
1
])}
return
(
key
,
value
)
...
...
@@ -170,7 +171,8 @@ class ParseObject(ParseBase):
value
=
ParseBinaryDataWrapper
(
base64
.
b64decode
(
value
[
'base64'
]))
elif
value
[
'__type'
]
==
'GeoPoint'
:
value
=
'POINT(
%
s
%
s)'
%
(
value
[
'latitude'
],
value
[
'longitude'
])
value
=
'POINT(
%
s
%
s)'
%
(
value
[
'latitude'
],
value
[
'longitude'
])
else
:
raise
Exception
(
'Invalid __type.'
)
...
...
tests.py
View file @
99fb1d27
...
...
@@ -26,9 +26,9 @@ 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
()
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"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment