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

Use line length of 88 instead of 79 #299

Merged
merged 1 commit into from
Jan 20, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions gdown/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ def main():
sys.exit(1)
except requests.exceptions.ProxyError as e:
print(
"Failed to use proxy:\n\n{}\n\n"
"Please check your proxy settings.".format(
"Failed to use proxy:\n\n{}\n\n" "Please check your proxy settings.".format(
indent("\n".join(textwrap.wrap(str(e))), prefix="\t")
),
file=sys.stderr,
Expand Down
8 changes: 2 additions & 6 deletions gdown/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ def download(

if url == url_origin and res.status_code == 500:
# The file could be Google Docs or Spreadsheets.
url = "https://drive.google.com/open?id={id}".format(
id=gdrive_file_id
)
url = "https://drive.google.com/open?id={id}".format(id=gdrive_file_id)
continue

if res.headers["Content-Type"].startswith("text/html"):
Expand Down Expand Up @@ -241,9 +239,7 @@ def download(
raise FileURLRetrievalError(message)

if gdrive_file_id and is_gdrive_download_link:
content_disposition = urllib.parse.unquote(
res.headers["Content-Disposition"]
)
content_disposition = urllib.parse.unquote(res.headers["Content-Disposition"])
m = re.search(r"filename\*=UTF-8''(.*)", content_disposition)
filename_from_url = m.groups()[0]
filename_from_url = filename_from_url.replace(osp.sep, "_")
Expand Down
28 changes: 7 additions & 21 deletions gdown/download_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,12 @@ def _parse_google_drive_file(url, content):

if "_DRIVE_ivd" in inner_html:
# first js string is _DRIVE_ivd, the second one is the encoded arr
regex_iter = re.compile(r"'((?:[^'\\]|\\.)*)'").finditer(
inner_html
)
regex_iter = re.compile(r"'((?:[^'\\]|\\.)*)'").finditer(inner_html)
# get the second elem in the iter
try:
encoded_data = next(
itertools.islice(regex_iter, 1, None)
).group(1)
encoded_data = next(itertools.islice(regex_iter, 1, None)).group(1)
except StopIteration:
raise RuntimeError(
"Couldn't find the folder encoded JS string"
)
raise RuntimeError("Couldn't find the folder encoded JS string")
break

if encoded_data is None:
Expand Down Expand Up @@ -175,17 +169,11 @@ def _get_directory_structure(gdrive_file, previous_path):
for file in gdrive_file.children:
file.name = file.name.replace(osp.sep, "_")
if file.is_folder():
directory_structure.append(
(None, osp.join(previous_path, file.name))
)
for i in _get_directory_structure(
file, osp.join(previous_path, file.name)
):
directory_structure.append((None, osp.join(previous_path, file.name)))
for i in _get_directory_structure(file, osp.join(previous_path, file.name)):
directory_structure.append(i)
elif not file.children:
directory_structure.append(
(file.id, osp.join(previous_path, file.name))
)
directory_structure.append((file.id, osp.join(previous_path, file.name)))
return directory_structure


Expand Down Expand Up @@ -248,9 +236,7 @@ def download_folder(
# We need to use different user agent for folder download c.f., file
user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36" # NOQA: E501

sess = _get_session(
proxy=proxy, use_cookies=use_cookies, user_agent=user_agent
)
sess = _get_session(proxy=proxy, use_cookies=use_cookies, user_agent=user_agent)

if not quiet:
print("Retrieving folder contents", file=sys.stderr)
Expand Down
3 changes: 1 addition & 2 deletions gdown/extractall.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def extractall(path, to=None):
opener, mode = tarfile.open, "r:bz2"
else:
raise ValueError(
"Could not extract '%s' as no appropriate "
"extractor is found" % path
"Could not extract '%s' as no appropriate " "extractor is found" % path
)

def namelist(f):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ exclude = [
"src",
]

line-length = 79 # 88
line-length = 88
indent-width = 4

[tool.ruff.lint]
Expand Down
4 changes: 1 addition & 3 deletions tests/test_parse_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def test_parse_url():
False,
),
(
"https://drive.google.com/file/d/{}/view?usp=sharing".format(
file_id
), # NOQA
"https://drive.google.com/file/d/{}/view?usp=sharing".format(file_id),
(file_id, False),
True,
),
Expand Down