Replace usage of six.moves.urllib with urllib

Also organize some of the imports. Now that Servo only uses Python 3,
this module is unnecessary. This is part of the gradual migration to
using only Python 3.
This commit is contained in:
Martin Robinson 2023-04-10 12:47:39 +02:00
parent 53218621e9
commit e9942bddb0
10 changed files with 37 additions and 35 deletions

View file

@ -10,7 +10,7 @@ import os
import distro import distro
import subprocess import subprocess
import six import six
import six.moves.urllib as urllib import urllib
from subprocess import PIPE from subprocess import PIPE
from zipfile import BadZipfile from zipfile import BadZipfile

View file

@ -10,6 +10,7 @@
from __future__ import absolute_import, print_function, unicode_literals from __future__ import absolute_import, print_function, unicode_literals
import base64 import base64
import glob
import json import json
import os import os
import os.path as path import os.path as path
@ -18,8 +19,7 @@ import re
import subprocess import subprocess
import sys import sys
import traceback import traceback
import six.moves.urllib as urllib import urllib
import glob
from mach.decorators import ( from mach.decorators import (
CommandArgument, CommandArgument,

View file

@ -15,11 +15,11 @@ import os
import os.path as path import os.path as path
import platform import platform
import shutil import shutil
import stat
import subprocess import subprocess
import sys import sys
import six.moves.urllib as urllib import urllib
import zipfile import zipfile
import stat
from time import time from time import time

View file

@ -9,35 +9,36 @@
from __future__ import print_function from __future__ import print_function
from errno import ENOENT as NO_SUCH_FILE_OR_DIRECTORY import contextlib
from glob import glob import distro
import shutil import functools
import gzip import gzip
import itertools import itertools
import json
import locale import locale
import os import os
from os import path
import platform import platform
import distro
import re import re
import contextlib import shutil
import subprocess
from subprocess import PIPE
import six import six
import subprocess
import sys import sys
import tarfile import tarfile
import urllib
import zipfile import zipfile
import functools
from errno import ENOENT as NO_SUCH_FILE_OR_DIRECTORY
from glob import glob
from os import path
from subprocess import PIPE
import toml
from xml.etree.ElementTree import XML from xml.etree.ElementTree import XML
from servo.util import download_file from servo.util import download_file
import six.moves.urllib as urllib
from .bootstrap import check_gstreamer_lib from .bootstrap import check_gstreamer_lib
from mach.decorators import CommandArgument from mach.decorators import CommandArgument
from mach.registrar import Registrar from mach.registrar import Registrar
import toml
import json
from servo.packages import WINDOWS_MSVC as msvc_deps from servo.packages import WINDOWS_MSVC as msvc_deps
from servo.util import host_triple from servo.util import host_triple

View file

@ -11,12 +11,12 @@ from __future__ import print_function, unicode_literals
from os import path, listdir, getcwd from os import path, listdir, getcwd
from time import time from time import time
import json
import signal import signal
import subprocess
import sys import sys
import tempfile import tempfile
import six.moves.urllib as urllib import urllib
import json
import subprocess
from mach.decorators import ( from mach.decorators import (
CommandArgument, CommandArgument,

View file

@ -21,7 +21,7 @@ import shutil
import subprocess import subprocess
import sys import sys
import tempfile import tempfile
import six.moves.urllib as urllib import urllib
import xml import xml
from mach.decorators import ( from mach.decorators import (

View file

@ -14,14 +14,14 @@ import os
import os.path import os.path
import platform import platform
import shutil import shutil
from socket import error as socket_error
import stat import stat
from io import BytesIO
import sys import sys
import time import time
import urllib
import zipfile import zipfile
import six.moves.urllib as urllib
from io import BytesIO
from socket import error as socket_error
try: try:
from ssl import HAS_SNI from ssl import HAS_SNI

View file

@ -14,7 +14,7 @@ import six.moves.BaseHTTPServer
import six.moves.SimpleHTTPServer import six.moves.SimpleHTTPServer
import six.moves.socketserver import six.moves.socketserver
import threading import threading
import six.moves.urllib.parse import urllib
import six import six
# List of jQuery modules that will be tested. # List of jQuery modules that will be tested.
@ -149,13 +149,13 @@ def run_http_server():
path = self.translate_path(self.path) path = self.translate_path(self.path)
f = None f = None
if os.path.isdir(path): if os.path.isdir(path):
parts = six.moves.urllib.parse.urlsplit(self.path) parts = urllib.parse.urlsplit(self.path)
if not parts.path.endswith('/'): if not parts.path.endswith('/'):
# redirect browser - doing basically what apache does # redirect browser - doing basically what apache does
self.send_response(301) self.send_response(301)
new_parts = (parts[0], parts[1], parts[2] + '/', new_parts = (parts[0], parts[1], parts[2] + '/',
parts[3], parts[4]) parts[3], parts[4])
new_url = six.moves.urllib.parse.urlunsplit(new_parts) new_url = urllib.parse.urlunsplit(new_parts)
self.send_header("Location", new_url) self.send_header("Location", new_url)
self.end_headers() self.end_headers()
return None return None

View file

@ -5,7 +5,8 @@
from __future__ import print_function from __future__ import print_function
import json import json
from six.moves.urllib.parse import urljoin import urllib
requests = None requests = None
class GitHubError(Exception): class GitHubError(Exception):
@ -36,7 +37,7 @@ class GitHub(object):
return self._request("PUT", path, data=data) return self._request("PUT", path, data=data)
def _request(self, method, path, data=None): def _request(self, method, path, data=None):
url = urljoin(self.url_base, path) url = urllib.parse.urljoin(self.url_base, path)
kwargs = {"headers": self.headers, kwargs = {"headers": self.headers,
"auth": self.auth} "auth": self.auth}
@ -96,7 +97,7 @@ class GitHubRepo(object):
return PullRequest.from_number(self, number) return PullRequest.from_number(self, number)
def path(self, suffix): def path(self, suffix):
return urljoin(self.url_base, suffix) return urllib.parse.urljoin(self.url_base, suffix)
class PullRequest(object): class PullRequest(object):
@ -126,7 +127,7 @@ class PullRequest(object):
return cls(repo, data) return cls(repo, data)
def path(self, suffix): def path(self, suffix):
return urljoin(self.repo.path("pulls/%i/" % self.number), suffix) return urllib.parse.urljoin(self.repo.path("pulls/%i/" % self.number), suffix)
@property @property
def issue(self): def issue(self):
@ -160,7 +161,7 @@ class Issue(object):
return cls(repo, data) return cls(repo, data)
def path(self, suffix): def path(self, suffix):
return urljoin(self.repo.path("issues/%i/" % self.number), suffix) return urllib.parse.urljoin(self.repo.path("issues/%i/" % self.number), suffix)
def add_label(self, label): def add_label(self, label):
"""Add a label to the issue. """Add a label to the issue.

View file

@ -4,7 +4,7 @@ import os
import re import re
import subprocess import subprocess
import sys import sys
import six.moves.urllib as urllib import urllib
from six.moves import input from six.moves import input
from six import iteritems from six import iteritems