Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 support #26

Merged
merged 1 commit into from Aug 7, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 13 additions & 6 deletions parse_rest/connection.py
Expand Up @@ -11,8 +11,15 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import urllib2
import urllib
try:
from urllib2 import Request, urlopen, HTTPError
from urllib import urlencode
except ImportError:
# is Python3
from urllib.request import Request, urlopen
from urllib.error import HTTPError
from urllib.parse import urlencode

import json

import core
Expand Down Expand Up @@ -70,10 +77,10 @@ def execute(cls, uri, http_verb, extra_headers=None, batch=False, **kw):
url = uri if uri.startswith(API_ROOT) else cls.ENDPOINT_ROOT + uri
data = kw and json.dumps(kw) or "{}"
if http_verb == 'GET' and data:
url += '?%s' % urllib.urlencode(kw)
url += '?%s' % urlencode(kw)
data = None

request = urllib2.Request(url, data, headers)
request = Request(url, data, headers)
request.add_header('Content-type', 'application/json')
request.add_header('X-Parse-Application-Id', app_id)
request.add_header('X-Parse-REST-API-Key', rest_key)
Expand All @@ -84,8 +91,8 @@ def execute(cls, uri, http_verb, extra_headers=None, batch=False, **kw):
request.get_method = lambda: http_verb

try:
response = urllib2.urlopen(request)
except urllib2.HTTPError, e:
response = urlopen(request)
except HTTPError as e:
exc = {
400: core.ResourceRequestBadRequest,
401: core.ResourceRequestLoginRequired,
Expand Down
4 changes: 4 additions & 0 deletions parse_rest/query.py
Expand Up @@ -15,6 +15,10 @@
import collections
import copy

try:
unicode = unicode
except NameError:
unicode = str

class QueryResourceDoesNotExist(Exception):
'''Query returned no results'''
Expand Down
12 changes: 9 additions & 3 deletions parse_rest/tests.py
Expand Up @@ -24,6 +24,12 @@
sys.exit('You must create a settings_local.py file with APPLICATION_ID, ' \
'REST_API_KEY, MASTER_KEY variables set')

try:
unicode = unicode
except NameError:
# is python3
unicode = str

register(
getattr(settings_local, 'APPLICATION_ID'),
getattr(settings_local, 'REST_API_KEY'),
Expand Down Expand Up @@ -318,9 +324,9 @@ def setUp(self):
settings_local.MASTER_KEY))
try:
subprocess.call(["parse", "deploy"])
except OSError, why:
print "parse command line tool must be installed " \
"(see https://www.parse.com/docs/cloud_code_guide)"
except OSError as why:
print("parse command line tool must be installed " \
"(see https://www.parse.com/docs/cloud_code_guide)")
self.skipTest(why)
os.chdir(original_dir)

Expand Down