Skip to content

Commit bfe1931

Browse files
committed
PY3 support.
1 parent bfc5de6 commit bfe1931

File tree

7 files changed

+35
-19
lines changed

7 files changed

+35
-19
lines changed

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@
5959
# built documents.
6060
#
6161
# The short X.Y version.
62-
version = '3.14'
62+
version = '3.2'
6363
# The full version, including alpha/beta/rc tags.
64-
release = '3.14'
64+
release = '3.2'
6565

6666
# The language for content autogenerated by Sphinx. Refer to documentation
6767
# for a list of supported languages.

dropbox/client.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77
import base64
88
import re
99
import os
10+
import six
1011
import sys
1112
import urllib
1213
import warnings
1314

14-
PY3 = sys.version_info[0] == 3
15-
16-
if PY3:
15+
if six.PY3:
1716
from io import StringIO
1817
basestring = str
18+
url_path_quote = urllib.parse.quote
1919
else:
2020
from StringIO import StringIO
21+
url_path_quote = urllib.quote
2122

2223
try:
2324
import json
@@ -1293,7 +1294,7 @@ def build_path(self, target, params=None):
12931294
if sys.version_info < (3,) and type(target) == unicode:
12941295
target = target.encode("utf8")
12951296

1296-
target_path = urllib.quote(target)
1297+
target_path = url_path_quote(target)
12971298

12981299
params = params or {}
12991300
params = params.copy()

dropbox/dropbox.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
]
44

55
# TODO(kelkabany): We need to auto populate this as done in the v1 SDK.
6-
__version__ = '3.14'
6+
__version__ = '3.2'
77

88
import json
99
import logging
@@ -14,8 +14,6 @@
1414

1515
import requests
1616

17-
from session import pinned_session
18-
1917
from . import babel_serializers
2018
from .base import DropboxBase
2119
from .exceptions import (
@@ -26,6 +24,7 @@
2624
InternalServerError,
2725
RateLimitError,
2826
)
27+
from .session import pinned_session
2928

3029
class RouteResult(object):
3130
"""The successful result of a call to a route."""

dropbox/oauth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import sys
1414
import urllib
1515

16-
from dropbox import Dropbox
17-
from session import pinned_session
16+
from .dropbox import Dropbox
17+
from .session import pinned_session
1818

1919
OAUTH_ROUTE_VERSION = '1'
2020

dropbox/rest.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import io
1212
import pkg_resources
13+
import six
1314
import socket
1415
import ssl
1516
import sys
@@ -25,8 +26,12 @@
2526
except ImportError:
2627
raise ImportError('Dropbox python client requires urllib3.')
2728

29+
if six.PY3:
30+
url_encode = urllib.parse.urlencode
31+
else:
32+
url_encode = urllib.urlencode
2833

29-
SDK_VERSION = "3.14"
34+
SDK_VERSION = "3.2"
3035

3136
TRUSTED_CERT_FILE = pkg_resources.resource_filename(__name__, 'trusted-certs.crt')
3237

@@ -205,7 +210,7 @@ def request(self, method, url, post_params=None, body=None, headers=None, raw_re
205210

206211
# Reject any headers containing newlines; the error from the server isn't pretty.
207212
for key, value in headers.items():
208-
if isinstance(value, basestring) and '\n' in value:
213+
if isinstance(value, six.string_types) and '\n' in value:
209214
raise ValueError("headers should not contain newlines (%s: %s)" %
210215
(key, value))
211216

@@ -409,9 +414,9 @@ def params_to_urlencoded(params):
409414
objects which are utf8-encoded.
410415
"""
411416
def encode(o):
412-
if isinstance(o, unicode):
417+
if isinstance(o, six.text_type):
413418
return o.encode('utf8')
414419
else:
415420
return str(o)
416-
utf8_params = {encode(k): encode(v) for k, v in params.iteritems()}
417-
return urllib.urlencode(utf8_params)
421+
utf8_params = {encode(k): encode(v) for k, v in params.items()}
422+
return url_encode(utf8_params)

dropbox/session.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
from requests.adapters import HTTPAdapter
66
from requests.packages.urllib3.poolmanager import PoolManager
77

8+
89
_TRUSTED_CERT_FILE = pkg_resources.resource_filename(__name__, 'trusted-certs.crt')
910

11+
1012
# TODO(kelkabany): We probably only want to instantiate this once so that even
1113
# if multiple Dropbox objects are instantiated, they all share the same pool.
1214
class _SSLAdapter(HTTPAdapter):
@@ -34,6 +36,7 @@ def pinned_session(pool_maxsize=8):
3436
"""
3537

3638
import random
39+
import six
3740
import sys
3841
import time
3942
import urllib
@@ -46,6 +49,14 @@ def pinned_session(pool_maxsize=8):
4649

4750
from . import rest
4851

52+
if six.PY3:
53+
url_path_quote = urllib.parse.quote
54+
url_encode = urllib.parse.urlencode
55+
else:
56+
url_path_quote = urllib.quote
57+
url_encode = urllib.urlencode
58+
59+
4960
class OAuthToken(object):
5061
"""
5162
A class representing an OAuth token. Contains two fields: ``key`` and
@@ -116,7 +127,7 @@ def build_path(self, target, params=None):
116127
if sys.version_info < (3,) and type(target) == unicode:
117128
target = target.encode("utf8")
118129

119-
target_path = urllib.quote(target)
130+
target_path = url_path_quote(target)
120131

121132
params = params or {}
122133
params = params.copy()
@@ -125,7 +136,7 @@ def build_path(self, target, params=None):
125136
params['locale'] = self.locale
126137

127138
if params:
128-
return "/%s%s?%s" % (self.API_VERSION, target_path, urllib.urlencode(params))
139+
return "/%s%s?%s" % (self.API_VERSION, target_path, url_encode(params))
129140
else:
130141
return "/%s%s" % (self.API_VERSION, target_path)
131142

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
dist = setup(
2727
name='dropbox',
28-
version='3.14',
28+
version='3.2',
2929
description='Official Dropbox API Client',
3030
author='Dropbox',
3131
author_email='dev-platform@dropbox.com',

0 commit comments

Comments
 (0)