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

Update Dependency from "diskutils" to "packaging" for Python 3.12 Compatibility #1766

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"selenium>=4.9.0",
"requests",
"websockets",
"packaging",
],
package_data={"undetected_chromedriver": [os.path.join("example", "example.py")]},
url="https://github.com/ultrafunkamsterdam/undetected-chromedriver",
Expand Down
18 changes: 9 additions & 9 deletions undetected_chromedriver/patcher.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# this module is part of undetected_chromedriver

from distutils.version import LooseVersion
from packaging import version
import io
import json
import logging
Expand Down Expand Up @@ -173,7 +173,7 @@ def auto(self, executable_path=None, force=False, version_main=None, _=None):
pass

release = self.fetch_release_number()
self.version_main = release.version[0]
self.version_main = release.major
self.version_full = release
self.unzip_package(self.fetch_package())
return self.patch()
Expand Down Expand Up @@ -233,14 +233,14 @@ def fetch_release_number(self):
"""
Gets the latest major version available, or the latest major version of self.target_version if set explicitly.
:return: version string
:rtype: LooseVersion
:rtype: packaging.version.Version
"""
# Endpoint for old versions of Chromedriver (114 and below)
if self.is_old_chromedriver:
path = f"/latest_release_{self.version_main}"
path = path.upper()
logger.debug("getting release number from %s" % path)
return LooseVersion(urlopen(self.url_repo + path).read().decode())
return version.parse(urlopen(self.url_repo + path).read().decode())

# Endpoint for new versions of Chromedriver (115+)
if not self.version_main:
Expand All @@ -251,7 +251,7 @@ def fetch_release_number(self):
response = conn.read().decode()

last_versions = json.loads(response)
return LooseVersion(last_versions["channels"]["Stable"]["version"])
return version.parse(last_versions["channels"]["Stable"]["version"])

# Fetch the latest minor version of the major version provided
path = "/latest-versions-per-milestone-with-downloads.json"
Expand All @@ -260,14 +260,14 @@ def fetch_release_number(self):
response = conn.read().decode()

major_versions = json.loads(response)
return LooseVersion(major_versions["milestones"][str(self.version_main)]["version"])
return version.parse(major_versions["milestones"][str(self.version_main)]["version"])

def parse_exe_version(self):
with io.open(self.executable_path, "rb") as f:
for line in iter(lambda: f.readline(), b""):
match = re.search(rb"platform_handle\x00content\x00([0-9.]*)", line)
if match:
return LooseVersion(match[1].decode())
return version.parse(match[1].decode())

def fetch_package(self):
"""
Expand All @@ -277,11 +277,11 @@ def fetch_package(self):
"""
zip_name = f"chromedriver_{self.platform_name}.zip"
if self.is_old_chromedriver:
download_url = "%s/%s/%s" % (self.url_repo, self.version_full.vstring, zip_name)
download_url = "%s/%s/%s" % (self.url_repo, self.version_full, zip_name)
else:
zip_name = zip_name.replace("_", "-", 1)
download_url = "https://storage.googleapis.com/chrome-for-testing-public/%s/%s/%s"
download_url %= (self.version_full.vstring, self.platform_name, zip_name)
download_url %= (self.version_full, self.platform_name, zip_name)

logger.debug("downloading from %s" % download_url)
return urlretrieve(download_url)[0]
Expand Down