Skip to content

Commit 2e43e45

Browse files
committed
pydrive2: pyupgrade --py37-plus
1 parent 0e70072 commit 2e43e45

File tree

9 files changed

+32
-47
lines changed

9 files changed

+32
-47
lines changed

pydrive2/apiattr.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
from six import Iterator, iteritems
2-
3-
4-
class ApiAttribute(object):
1+
class ApiAttribute:
52
"""A data descriptor that sets and returns values."""
63

74
def __init__(self, name):
@@ -32,7 +29,7 @@ def __del__(self, obj=None):
3229
del obj.dirty[self.name]
3330

3431

35-
class ApiAttributeMixin(object):
32+
class ApiAttributeMixin:
3633
"""Mixin to initialize required global variables to use ApiAttribute."""
3734

3835
def __init__(self):
@@ -54,7 +51,7 @@ class ApiResource(dict):
5451

5552
def __init__(self, *args, **kwargs):
5653
"""Create an instance of ApiResource."""
57-
super(ApiResource, self).__init__()
54+
super().__init__()
5855
self.update(*args, **kwargs)
5956
self.metadata = dict(self)
6057

@@ -79,11 +76,11 @@ def __setitem__(self, key, val):
7976
def __repr__(self):
8077
"""Overwritten method of dictionary."""
8178
dict_representation = dict.__repr__(self)
82-
return "%s(%s)" % (type(self).__name__, dict_representation)
79+
return f"{type(self).__name__}({dict_representation})"
8380

8481
def update(self, *args, **kwargs):
8582
"""Overwritten method of dictionary."""
86-
for k, v in iteritems(dict(*args, **kwargs)):
83+
for k, v in dict(*args, **kwargs).items():
8784
self[k] = v
8885

8986
def UpdateMetadata(self, metadata=None):
@@ -106,7 +103,7 @@ def GetChanges(self):
106103
return dirty
107104

108105

109-
class ApiResourceList(ApiAttributeMixin, ApiResource, Iterator):
106+
class ApiResourceList(ApiAttributeMixin, ApiResource):
110107
"""Abstract class of all api list resources.
111108
112109
Inherits ApiResource and builds iterator to list any API resource.

pydrive2/auth.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import socket
21
import webbrowser
32
import httplib2
43
import oauth2client.clientsecrets as clientsecrets
5-
from six.moves import input
64
import threading
75

86
from googleapiclient.discovery import build
@@ -141,7 +139,7 @@ def _decorated(self, *args, **kwargs):
141139
return _decorated
142140

143141

144-
class GoogleAuth(ApiAttributeMixin, object):
142+
class GoogleAuth(ApiAttributeMixin):
145143
"""Wrapper class for oauth2client library in google-api-python-client.
146144
147145
Loads all settings and credentials from one 'settings.yaml' file
@@ -241,13 +239,13 @@ def LocalWebserverAuth(
241239
httpd = ClientRedirectServer(
242240
(host_name, port), ClientRedirectHandler
243241
)
244-
except socket.error:
242+
except OSError:
245243
pass
246244
else:
247245
success = True
248246
break
249247
if success:
250-
oauth_callback = "http://%s:%s/" % (host_name, port_number)
248+
oauth_callback = f"http://{host_name}:{port_number}/"
251249
else:
252250
print(
253251
"Failed to start a local web server. Please check your firewall"
@@ -381,7 +379,7 @@ def LoadCredentialsFile(self, credentials_file=None):
381379

382380
try:
383381
self.credentials = self._default_storage.get()
384-
except IOError:
382+
except OSError:
385383
raise InvalidCredentialsError(
386384
"Credentials file cannot be symbolic link"
387385
)
@@ -431,7 +429,7 @@ def SaveCredentialsFile(self, credentials_file=None):
431429

432430
try:
433431
storage.put(self.credentials)
434-
except IOError:
432+
except OSError:
435433
raise InvalidCredentialsError(
436434
"Credentials file cannot be symbolic link"
437435
)
@@ -538,7 +536,7 @@ def LoadServiceConfigSettings(self):
538536
]
539537
except KeyError:
540538
err = "Insufficient service config in settings"
541-
err += "\n\nMissing: {} key.".format(config)
539+
err += f"\n\nMissing: {config} key."
542540
raise InvalidConfigError(err)
543541

544542
def LoadClientConfigSettings(self):

pydrive2/drive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from .auth import LoadAuth
55

66

7-
class GoogleDrive(ApiAttributeMixin, object):
7+
class GoogleDrive(ApiAttributeMixin):
88
"""Main Google Drive class."""
99

1010
def __init__(self, auth=None):

pydrive2/files.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
BLOCK_SIZE = 1024
1818
# Usage: MIME_TYPE_TO_BOM['<Google Drive mime type>']['<download mimetype>'].
1919
MIME_TYPE_TO_BOM = {
20-
"application/vnd.google-apps.document": {
21-
"text/plain": "\ufeff".encode("utf8")
22-
}
20+
"application/vnd.google-apps.document": {"text/plain": "\ufeff".encode()}
2321
}
2422

2523

@@ -68,7 +66,7 @@ class GoogleDriveFileList(ApiResourceList):
6866

6967
def __init__(self, auth=None, param=None):
7068
"""Create an instance of GoogleDriveFileList."""
71-
super(GoogleDriveFileList, self).__init__(auth=auth, metadata=param)
69+
super().__init__(auth=auth, metadata=param)
7270

7371
@LoadAuth
7472
def _GetList(self):
@@ -98,7 +96,7 @@ def _GetList(self):
9896
return result
9997

10098

101-
class IoBuffer(object):
99+
class IoBuffer:
102100
"""Lightweight retention of one chunk."""
103101

104102
def __init__(self, encoding):
@@ -116,7 +114,7 @@ def read(self):
116114
)
117115

118116

119-
class MediaIoReadable(object):
117+
class MediaIoReadable:
120118
def __init__(
121119
self,
122120
request,

pydrive2/settings.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ def LoadSettingsFile(filename=SETTINGS_FILE):
103103
:raises: SettingsError
104104
"""
105105
try:
106-
with open(filename, "r") as stream:
106+
with open(filename) as stream:
107107
data = load(stream, Loader=Loader)
108-
except (YAMLError, IOError) as e:
108+
except (YAMLError, OSError) as e:
109109
raise SettingsError(e)
110110
return data
111111

@@ -158,9 +158,7 @@ def _ValidateSettingsElement(data, struct, key):
158158
data[key] = default
159159
# If data exists, Check type of the data
160160
elif type(value) is not data_type:
161-
raise InvalidConfigError(
162-
"Setting %s should be type %s" % (key, data_type)
163-
)
161+
raise InvalidConfigError(f"Setting {key} should be type {data_type}")
164162
# If type of this data is dict, check if structure of the data is valid.
165163
if data_type is dict:
166164
_ValidateSettingsStruct(data[key], struct[key]["struct"])

pydrive2/test/test_drive.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import unittest
32

43
from pydrive2.auth import GoogleAuth

pydrive2/test/test_file.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import filecmp
32
import os
43
import unittest
@@ -8,7 +7,6 @@
87
from tempfile import mkdtemp
98
from time import time
109

11-
from six.moves import range
1210
import timeout_decorator
1311
from concurrent.futures import ThreadPoolExecutor, as_completed
1412
from googleapiclient import errors
@@ -699,22 +697,22 @@ def test_Gfile_Conversion_Add_Remove_BOM(self):
699697

700698
def test_InsertPrefix(self):
701699
# Create BytesIO.
702-
file_obj = BytesIO("abc".encode("utf8"))
700+
file_obj = BytesIO(b"abc")
703701
original_length = len(file_obj.getvalue())
704-
char_to_insert = "\ufeff".encode("utf8")
702+
char_to_insert = "\ufeff".encode()
705703

706704
# Insert the prefix.
707705
GoogleDriveFile._InsertPrefix(file_obj, char_to_insert)
708706
modified_length = len(file_obj.getvalue())
709707
self.assertGreater(modified_length, original_length)
710-
self.assertEqual(file_obj.getvalue(), "\ufeffabc".encode("utf8"))
708+
self.assertEqual(file_obj.getvalue(), "\ufeffabc".encode())
711709

712710
def test_InsertPrefixLarge(self):
713711
# Create BytesIO.
714712
test_content = "abc" * 800
715713
file_obj = BytesIO(test_content.encode("utf-8"))
716714
original_length = len(file_obj.getvalue())
717-
char_to_insert = "\ufeff".encode("utf8")
715+
char_to_insert = "\ufeff".encode()
718716

719717
# Insert the prefix.
720718
GoogleDriveFile._InsertPrefix(file_obj, char_to_insert)
@@ -725,22 +723,22 @@ def test_InsertPrefixLarge(self):
725723

726724
def test_RemovePrefix(self):
727725
# Create BytesIO.
728-
file_obj = BytesIO("\ufeffabc".encode("utf8"))
726+
file_obj = BytesIO("\ufeffabc".encode())
729727
original_length = len(file_obj.getvalue())
730-
char_to_remove = "\ufeff".encode("utf8")
728+
char_to_remove = "\ufeff".encode()
731729

732730
# Insert the prefix.
733731
GoogleDriveFile._RemovePrefix(file_obj, char_to_remove)
734732
modified_length = len(file_obj.getvalue())
735733
self.assertLess(modified_length, original_length)
736-
self.assertEqual(file_obj.getvalue(), "abc".encode("utf8"))
734+
self.assertEqual(file_obj.getvalue(), b"abc")
737735

738736
def test_RemovePrefixLarge(self):
739737
# Create BytesIO.
740738
test_content = "\ufeff" + "abc" * 800
741739
file_obj = BytesIO(test_content.encode("utf8"))
742740
original_length = len(file_obj.getvalue())
743-
char_to_remove = "\ufeff".encode("utf8")
741+
char_to_remove = "\ufeff".encode()
744742

745743
# Insert the prefix.
746744
GoogleDriveFile._RemovePrefix(file_obj, char_to_remove)

pydrive2/test/test_filelist.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import os
32
import unittest
43

@@ -28,7 +27,7 @@ def setup_class(cls):
2827

2928
def test_01_Files_List_GetList(self):
3029
drive = GoogleDrive(self.ga)
31-
query = "title = '{}' and trashed = false".format(self.title)
30+
query = f"title = '{self.title}' and trashed = false"
3231
for file1 in pydrive_list_item(drive, query):
3332
found = False
3433
for file2 in pydrive_list_item(drive, query):
@@ -38,7 +37,7 @@ def test_01_Files_List_GetList(self):
3837

3938
def test_02_Files_List_ForLoop(self):
4039
drive = GoogleDrive(self.ga)
41-
query = "title = '{}' and trashed = false".format(self.title)
40+
query = f"title = '{self.title}' and trashed = false"
4241
files = []
4342
for x in pydrive_list_item(
4443
drive, query, 2
@@ -84,7 +83,7 @@ def test_File_List_Folders(self):
8483
)
8584
pydrive_retry(folder1.Upload)
8685
self.file_list.append(folder1)
87-
query = "title = '{}' and trashed = false".format(self.title)
86+
query = f"title = '{self.title}' and trashed = false"
8887
count = 0
8988
for file1 in pydrive_list_item(drive, query):
9089
self.assertFileInFileList(file1)

setup.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
from setuptools import setup
32

43
# Extra dependecies to run tests
@@ -11,8 +10,7 @@
1110
"pytest-mock",
1211
]
1312

14-
if sys.version_info >= (3, 6):
15-
tests_requirements.append("black==22.3.0")
13+
tests_requirements.append("black==22.3.0")
1614

1715
setup(
1816
name="PyDrive2",

0 commit comments

Comments
 (0)