Skip to content

Commit

Permalink
Formatting cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mbogosian authored and posita committed Mar 23, 2017
1 parent 77d20cf commit 2b2b8bf
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[MESSAGES CONTROL]
disable=C,R,fixme,locally-disabled,protected-access,useless-else-on-loop
disable=C,R,file-ignored,fixme,locally-disabled,protected-access,useless-else-on-loop
enable=useless-suppression

[REPORTS]
Expand Down
2 changes: 1 addition & 1 deletion dropbox/babel_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def validate(self, val):
raise ValidationError('expected timestamp, got %s'
% generic_type_name(val))
elif val.tzinfo is not None and \
val.tzinfo.utcoffset(val).total_seconds() != 0:
val.tzinfo.utcoffset(val).total_seconds() != 0:
raise ValidationError('timestamp should have either a UTC '
'timezone or none set at all')
return val
Expand Down
26 changes: 15 additions & 11 deletions dropbox/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def __init__(self, oauth2_access_token, locale=None, rest_client=None):
'You are using a deprecated client. Please use the new v2 client '
'located at dropbox.Dropbox.', DeprecationWarning, stacklevel=2)

if rest_client is None: rest_client = RESTClient
if rest_client is None:
rest_client = RESTClient
if isinstance(oauth2_access_token, basestring):
if not _OAUTH2_ACCESS_TOKEN_PATTERN.match(oauth2_access_token):
raise ValueError("invalid format for oauth2_access_token: %r"
Expand Down Expand Up @@ -118,7 +119,7 @@ def request(self, target, params=None, method='POST',
A tuple of ``(url, params, headers)`` that should be used to make the request.
OAuth will be added as needed within these fields.
"""
assert method in ['GET','POST', 'PUT'], "Only 'GET', 'POST', and 'PUT' are allowed."
assert method in ['GET', 'POST', 'PUT'], "Only 'GET', 'POST', and 'PUT' are allowed."
assert not (content_server and notification_server), \
"Cannot construct request simultaneously for content and notification servers."

Expand Down Expand Up @@ -219,7 +220,7 @@ def get_chunked_uploader(self, file_obj, length):
return ChunkedUploader(self, file_obj, length)

def upload_chunk(self, file_obj, length=None, offset=0, # pylint: disable=unused-argument
upload_id=None):
upload_id=None):
"""Uploads a single chunk of data from a string or file-like object. The majority of users
should use the :class:`ChunkedUploader` object, which provides a simpler interface to the
chunked_upload API endpoint.
Expand Down Expand Up @@ -486,7 +487,8 @@ def __parse_metadata_as_dict(dropbox_raw_response):
metadata = json.loads(header_val)
except ValueError:
raise ErrorResponse(dropbox_raw_response, '')
if not metadata: raise ErrorResponse(dropbox_raw_response, '')
if not metadata:
raise ErrorResponse(dropbox_raw_response, '')
return metadata

def delta(self, cursor=None, path_prefix=None, include_media_info=False):
Expand Down Expand Up @@ -930,12 +932,11 @@ def thumbnail(self, from_path, size='m', format='JPEG'): # pylint: disable=rede
- 415: Image is invalid and cannot be thumbnailed.
"""
assert format in ['JPEG', 'PNG'], \
"expected a thumbnail format of 'JPEG' or 'PNG', got %s" % format
"expected a thumbnail format of 'JPEG' or 'PNG', got %s" % format

path = "/thumbnails/%s%s" % (self.session.root, format_path(from_path))

url, _, headers = self.request(path, {'size': size, 'format': format},
method='GET', content_server=True)
method='GET', content_server=True)
return self.rest_client.request("GET", url, headers=headers, raw_response=True)

def thumbnail_and_metadata(self, from_path, size='m', format='JPEG'): # noqa: E501; pylint: disable=redefined-builtin
Expand Down Expand Up @@ -1373,7 +1374,8 @@ def __init__(self, consumer_key, consumer_secret, locale=None, rest_client=None)
Optional :class:`dropbox.rest.RESTClient`-like object to use for making
requests.
"""
if rest_client is None: rest_client = RESTClient
if rest_client is None:
rest_client = RESTClient
super(DropboxOAuth2FlowNoRedirect, self).__init__(consumer_key, consumer_secret,
locale, rest_client)

Expand Down Expand Up @@ -1480,7 +1482,8 @@ def __init__(self, consumer_key, consumer_secret, redirect_uri, session,
Optional :class:`dropbox.rest.RESTClient`-like object to use for making
requests.
"""
if rest_client is None: rest_client = RESTClient
if rest_client is None:
rest_client = RESTClient
super(DropboxOAuth2Flow, self).__init__(consumer_key, consumer_secret, locale, rest_client)
self.redirect_uri = redirect_uri
self.session = session
Expand Down Expand Up @@ -1578,7 +1581,7 @@ def finish(self, query_params):
url_state = None
else:
given_csrf_token = state[0:split_pos]
url_state = state[split_pos+1:]
url_state = state[split_pos + 1:]

if not _safe_equals(csrf_token_from_session, given_csrf_token):
raise self.CsrfException("expected %r, got %r" % (csrf_token_from_session,
Expand Down Expand Up @@ -1654,7 +1657,8 @@ class ProviderException(Exception):


def _safe_equals(a, b):
if len(a) != len(b): return False
if len(a) != len(b):
return False
res = 0
for ca, cb in zip(a, b):
res |= ord(ca) ^ ord(cb)
Expand Down
5 changes: 3 additions & 2 deletions dropbox/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def finish(self, query_params):
url_state = None
else:
given_csrf_token = state[0:split_pos]
url_state = state[split_pos+1:]
url_state = state[split_pos + 1:]

if not _safe_equals(csrf_token_from_session, given_csrf_token):
raise CsrfException('expected %r, got %r' %
Expand Down Expand Up @@ -475,7 +475,8 @@ class ProviderException(Exception):


def _safe_equals(a, b):
if len(a) != len(b): return False
if len(a) != len(b):
return False
res = 0
for ca, cb in zip(a, b):
res |= ord(ca) ^ ord(cb)
Expand Down
5 changes: 2 additions & 3 deletions dropbox/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,8 @@ def build_access_headers(self, params=None, request_token=None):
@classmethod
def _oauth_sign_request(cls, params, consumer_pair, token_pair):
params.update({'oauth_signature_method': 'PLAINTEXT',
'oauth_signature': ('%s&%s' % (consumer_pair.secret, token_pair.secret)
if token_pair is not None else
'%s&' % (consumer_pair.secret,))})
'oauth_signature': ('%s&%s' % (consumer_pair.secret, token_pair.secret)
if token_pair is not None else '%s&' % (consumer_pair.secret,))})

@classmethod
def _generate_oauth_timestamp(cls):
Expand Down
9 changes: 5 additions & 4 deletions dropbox/stone_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def encode_primitive(self, validator, value):
else:
return base64.b64encode(value).decode('ascii')
elif isinstance(validator, bv.Integer) \
and isinstance(value, bool):
and isinstance(value, bool):
# bool is sub-class of int so it passes Integer validation,
# but we want the bool to be encoded as ``0`` or ``1``, rather
# than ``False`` or ``True``, respectively
Expand Down Expand Up @@ -302,8 +302,8 @@ def encode_union(self, validator, value):

field_validator = validator.definition._tagmap[value._tag]
is_none = isinstance(field_validator, bv.Void) \
or (isinstance(field_validator, bv.Nullable)
and value._value is None)
or (isinstance(field_validator, bv.Nullable)
and value._value is None)

def encode_sub(sub_validator, sub_value, parent_tag):
try:
Expand Down Expand Up @@ -361,7 +361,8 @@ def encode(self, validator, value):
# functions.

def json_encode(data_type, obj, alias_validators=None, old_style=False):
"""Encodes an object into JSON based on its type.
"""
Encodes an object into JSON based on its type.
Args:
data_type (Validator): Validator for obj.
Expand Down
2 changes: 1 addition & 1 deletion dropbox/stone_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def validate(self, val):
raise ValidationError('expected timestamp, got %s'
% generic_type_name(val))
elif val.tzinfo is not None and \
val.tzinfo.utcoffset(val).total_seconds() != 0:
val.tzinfo.utcoffset(val).total_seconds() != 0:
raise ValidationError('timestamp should have either a UTC '
'timezone or none set at all')
return val
Expand Down
43 changes: 27 additions & 16 deletions test/test_dropbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ def test_bad_upload_types(self, dbx):
def test_team(self, dbxt):
dbxt.team_groups_list()
r = dbxt.team_members_list()
if r.members: # pylint: disable=no-member
if r.members:
# Only test assuming a member if there is a member
team_member_id = r.members[0].profile.team_member_id # pylint: disable=no-member
team_member_id = r.members[0].profile.team_member_id
dbxt.as_user(team_member_id).files_list_folder('')


Expand Down Expand Up @@ -190,7 +190,7 @@ def test_account_info(self, dbx_client):
@dbx_v1_client_from_env_with_test_dir
def test_put_file(self, dbx_client, test_dir):
"""Tests if put_file returns the expected metadata"""
def test_put(file, path): # pylint: disable=redefined-builtin,useless-suppression
def test_put(file, path): # pylint: disable=redefined-builtin
file_path = posixpath.join(test_dir, path)
f = open(file, "rb")
metadata = dbx_client.put_file(file_path, f)
Expand Down Expand Up @@ -218,7 +218,7 @@ def test_put_file_overwrite(self, dbx_client, test_dir):
@dbx_v1_client_from_env_with_test_dir
def test_get_file(self, dbx_client, test_dir):
"""Tests if storing and retrieving a file returns the same file"""
def test_get(file, path): # pylint: disable=redefined-builtin,useless-suppression
def test_get(file, path): # pylint: disable=redefined-builtin
file_path = posixpath.join(test_dir, path)
self.upload_file(dbx_client, file, file_path)
downloaded = dbx_client.get_file(file_path).read()
Expand All @@ -232,7 +232,7 @@ def test_get(file, path): # pylint: disable=redefined-builtin,useless-suppressi
@dbx_v1_client_from_env_with_test_dir
def test_get_partial_file(self, dbx_client, test_dir):
"""Tests if storing a file and retrieving part of it returns the correct part"""
def test_get(file, path, start_frac, download_frac): # noqa: E501; pylint: disable=redefined-builtin,useless-suppression
def test_get(file, path, start_frac, download_frac): # noqa: E501; pylint: disable=redefined-builtin
file_path = posixpath.join(test_dir, path)
self.upload_file(dbx_client, file, file_path)
local = open(file, "rb").read()
Expand All @@ -241,7 +241,7 @@ def test_get(file, path, start_frac, download_frac): # noqa: E501; pylint: disa
download_start = int(start_frac * local_len) if start_frac is not None else None
download_length = int(download_frac * local_len) if download_frac is not None else None
downloaded = dbx_client.get_file(file_path, start=download_start,
length=download_length).read()
length=download_length).read()

local_file = open(file, "rb")
if download_start:
Expand Down Expand Up @@ -489,13 +489,20 @@ def test_chunked_upload2(self, dbx_client, test_dir):
self.assertEqual(new_offset, chunk_size)
self.assertIsNotNone(upload_id)

new_offset, upload_id2 = dbx_client.upload_chunk(BytesIO(random_data2), 0,
new_offset, upload_id)
new_offset, upload_id2 = dbx_client.upload_chunk(
BytesIO(random_data2),
0,
new_offset,
upload_id,
)
self.assertEqual(new_offset, chunk_size * 2)
self.assertEqual(upload_id2, upload_id)

metadata = dbx_client.commit_chunked_upload('/auto' + target_path, upload_id,
overwrite=True)
metadata = dbx_client.commit_chunked_upload(
'/auto' + target_path,
upload_id,
overwrite=True,
)
self.dict_has(metadata, bytes=chunk_size * 2, path=target_path)

downloaded = dbx_client.get_file(target_path).read()
Expand Down Expand Up @@ -544,12 +551,14 @@ def test_delta(self, dbx_client, test_dir):
cursor = None
while True:
r = dbx_client.delta(cursor)
if r['reset']: entries = set()
if r['reset']:
entries = set()
for path_lc, md in r['entries']:
if path_lc.startswith(prefix_lc+'/') or path_lc == prefix_lc:
if path_lc.startswith(prefix_lc + '/') or path_lc == prefix_lc:
assert md is not None, "we should never get deletes under 'prefix'"
entries.add(path_lc)
if not r['has_more']: break
if not r['has_more']:
break
cursor = r['cursor']

self.assertEqual(expected, entries)
Expand All @@ -560,12 +569,14 @@ def test_delta(self, dbx_client, test_dir):
cursor = None
while True:
r = dbx_client.delta(cursor, path_prefix=c)
if r['reset']: entries = set()
if r['reset']:
entries = set()
for path_lc, md in r['entries']:
assert path_lc.startswith(c_lc+'/') or path_lc == c_lc
assert path_lc.startswith(c_lc + '/') or path_lc == c_lc
assert md is not None, "we should never get deletes"
entries.add(path_lc)
if not r['has_more']: break
if not r['has_more']:
break
cursor = r['cursor']

self.assertEqual(expected, entries)
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ pypy3 = lint

[flake8]

ignore = E127,E128,E226,E231,E301,E302,E305,E402,E701,W503
# See <https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes>
ignore = E128,E301,E302,E305,E402,W503
max-line-length = 100


Expand Down

0 comments on commit 2b2b8bf

Please sign in to comment.