mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-07-29 03:46:55 +00:00
Python code modernization, 3/n (#1157)
* Remove __metaclass__ = type. for i in $(grep -REl '__metaclass__ = type' plugins/ tests/); do sed -e '/^__metaclass__ = type/d' -i $i; done * Remove super arguments, and stop inheriting from object.
This commit is contained in:
@@ -30,10 +30,10 @@ try:
|
||||
except ImportError:
|
||||
REQUESTS_IMPORT_ERROR = traceback.format_exc()
|
||||
|
||||
class Session(object):
|
||||
class Session:
|
||||
__attrs__ = []
|
||||
|
||||
class HTTPAdapter(object):
|
||||
class HTTPAdapter:
|
||||
__attrs__ = []
|
||||
|
||||
class HTTPError(Exception):
|
||||
@@ -57,13 +57,13 @@ except ImportError:
|
||||
except ImportError:
|
||||
URLLIB3_IMPORT_ERROR = traceback.format_exc()
|
||||
|
||||
class _HTTPConnectionPool(object):
|
||||
class _HTTPConnectionPool:
|
||||
pass
|
||||
|
||||
class _HTTPConnection(object):
|
||||
class _HTTPConnection:
|
||||
pass
|
||||
|
||||
class FakeURLLIB3(object):
|
||||
class FakeURLLIB3:
|
||||
def __init__(self):
|
||||
self._collections = self
|
||||
self.poolmanager = self
|
||||
@@ -75,7 +75,7 @@ except ImportError:
|
||||
self.match_hostname = object()
|
||||
self.HTTPConnectionPool = _HTTPConnectionPool
|
||||
|
||||
class FakeURLLIB3Connection(object):
|
||||
class FakeURLLIB3Connection:
|
||||
def __init__(self):
|
||||
self.HTTPConnection = _HTTPConnection
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ class APIClient(_Session, DaemonApiMixin):
|
||||
use_ssh_client=False,
|
||||
max_pool_size=DEFAULT_MAX_POOL_SIZE,
|
||||
):
|
||||
super(APIClient, self).__init__()
|
||||
super().__init__()
|
||||
|
||||
fail_on_missing_imports()
|
||||
|
||||
@@ -493,7 +493,7 @@ class APIClient(_Session, DaemonApiMixin):
|
||||
|
||||
def get_adapter(self, url):
|
||||
try:
|
||||
return super(APIClient, self).get_adapter(url)
|
||||
return super().get_adapter(url)
|
||||
except _InvalidSchema as e:
|
||||
if self._custom_adapter:
|
||||
return self._custom_adapter
|
||||
|
||||
@@ -17,7 +17,7 @@ from .. import auth
|
||||
from ..utils.decorators import minimum_version
|
||||
|
||||
|
||||
class DaemonApiMixin(object):
|
||||
class DaemonApiMixin:
|
||||
@minimum_version("1.25")
|
||||
def df(self):
|
||||
"""
|
||||
|
||||
@@ -33,7 +33,7 @@ def create_default_context():
|
||||
)
|
||||
|
||||
|
||||
class ContextAPI(object):
|
||||
class ContextAPI:
|
||||
"""Context API.
|
||||
Contains methods for context management:
|
||||
create, list, remove, get, inspect.
|
||||
|
||||
@@ -28,7 +28,7 @@ from .config import (
|
||||
IN_MEMORY = "IN MEMORY"
|
||||
|
||||
|
||||
class Context(object):
|
||||
class Context:
|
||||
"""A context."""
|
||||
|
||||
def __init__(
|
||||
|
||||
@@ -19,7 +19,7 @@ from . import constants, errors
|
||||
from .utils import create_environment_dict, find_executable
|
||||
|
||||
|
||||
class Store(object):
|
||||
class Store:
|
||||
def __init__(self, program, environment=None):
|
||||
"""Create a store object that acts as an interface to
|
||||
perform the basic operations for storing, retrieving
|
||||
|
||||
@@ -55,12 +55,12 @@ class APIError(_HTTPError, DockerException):
|
||||
def __init__(self, message, response=None, explanation=None):
|
||||
# requests 1.2 supports response as a keyword argument, but
|
||||
# requests 1.1 does not
|
||||
super(APIError, self).__init__(message)
|
||||
super().__init__(message)
|
||||
self.response = response
|
||||
self.explanation = explanation
|
||||
|
||||
def __str__(self):
|
||||
message = super(APIError, self).__str__()
|
||||
message = super().__str__()
|
||||
|
||||
if self.is_client_error():
|
||||
message = f"{self.response.status_code} Client Error for {self.response.url}: {self.response.reason}"
|
||||
@@ -152,7 +152,7 @@ class ContainerError(DockerException):
|
||||
err = f": {stderr}" if stderr is not None else ""
|
||||
msg = f"Command '{command}' in image '{image}' returned non-zero exit status {exit_status}{err}"
|
||||
|
||||
super(ContainerError, self).__init__(msg)
|
||||
super().__init__(msg)
|
||||
|
||||
|
||||
class StreamParseError(RuntimeError):
|
||||
@@ -162,7 +162,7 @@ class StreamParseError(RuntimeError):
|
||||
|
||||
class BuildError(DockerException):
|
||||
def __init__(self, reason, build_log):
|
||||
super(BuildError, self).__init__(reason)
|
||||
super().__init__(reason)
|
||||
self.msg = reason
|
||||
self.build_log = build_log
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ from . import errors
|
||||
from .transport.ssladapter import SSLHTTPAdapter
|
||||
|
||||
|
||||
class TLSConfig(object):
|
||||
class TLSConfig:
|
||||
"""
|
||||
TLS configuration.
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ from .._import_helper import HTTPAdapter as _HTTPAdapter
|
||||
|
||||
class BaseHTTPAdapter(_HTTPAdapter):
|
||||
def close(self):
|
||||
super(BaseHTTPAdapter, self).close()
|
||||
super().close()
|
||||
if hasattr(self, "pools"):
|
||||
self.pools.clear()
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@ from .npipesocket import NpipeSocket
|
||||
RecentlyUsedContainer = urllib3._collections.RecentlyUsedContainer
|
||||
|
||||
|
||||
class NpipeHTTPConnection(urllib3_connection.HTTPConnection, object):
|
||||
class NpipeHTTPConnection(urllib3_connection.HTTPConnection):
|
||||
def __init__(self, npipe_path, timeout=60):
|
||||
super(NpipeHTTPConnection, self).__init__("localhost", timeout=timeout)
|
||||
super().__init__("localhost", timeout=timeout)
|
||||
self.npipe_path = npipe_path
|
||||
self.timeout = timeout
|
||||
|
||||
@@ -37,9 +37,7 @@ class NpipeHTTPConnection(urllib3_connection.HTTPConnection, object):
|
||||
|
||||
class NpipeHTTPConnectionPool(urllib3.connectionpool.HTTPConnectionPool):
|
||||
def __init__(self, npipe_path, timeout=60, maxsize=10):
|
||||
super(NpipeHTTPConnectionPool, self).__init__(
|
||||
"localhost", timeout=timeout, maxsize=maxsize
|
||||
)
|
||||
super().__init__("localhost", timeout=timeout, maxsize=maxsize)
|
||||
self.npipe_path = npipe_path
|
||||
self.timeout = timeout
|
||||
|
||||
@@ -90,7 +88,7 @@ class NpipeHTTPAdapter(BaseHTTPAdapter):
|
||||
self.pools = RecentlyUsedContainer(
|
||||
pool_connections, dispose_func=lambda p: p.close()
|
||||
)
|
||||
super(NpipeHTTPAdapter, self).__init__()
|
||||
super().__init__()
|
||||
|
||||
def get_connection(self, url, proxies=None):
|
||||
with self.pools.lock:
|
||||
|
||||
@@ -45,7 +45,7 @@ def check_closed(f):
|
||||
return wrapped
|
||||
|
||||
|
||||
class NpipeSocket(object):
|
||||
class NpipeSocket:
|
||||
"""Partial implementation of the socket API over windows named pipes.
|
||||
This implementation is only designed to be used as a client socket,
|
||||
and server-specific methods (bind, listen, accept...) are not
|
||||
@@ -227,7 +227,7 @@ class NpipeFileIOBase(io.RawIOBase):
|
||||
self.sock = npipe_socket
|
||||
|
||||
def close(self):
|
||||
super(NpipeFileIOBase, self).close()
|
||||
super().close()
|
||||
self.sock = None
|
||||
|
||||
def fileno(self):
|
||||
|
||||
@@ -37,7 +37,7 @@ RecentlyUsedContainer = urllib3._collections.RecentlyUsedContainer
|
||||
|
||||
class SSHSocket(socket.socket):
|
||||
def __init__(self, host):
|
||||
super(SSHSocket, self).__init__(socket.AF_INET, socket.SOCK_STREAM)
|
||||
super().__init__(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.host = host
|
||||
self.port = None
|
||||
self.user = None
|
||||
@@ -117,9 +117,9 @@ class SSHSocket(socket.socket):
|
||||
self.proc.terminate()
|
||||
|
||||
|
||||
class SSHConnection(urllib3_connection.HTTPConnection, object):
|
||||
class SSHConnection(urllib3_connection.HTTPConnection):
|
||||
def __init__(self, ssh_transport=None, timeout=60, host=None):
|
||||
super(SSHConnection, self).__init__("localhost", timeout=timeout)
|
||||
super().__init__("localhost", timeout=timeout)
|
||||
self.ssh_transport = ssh_transport
|
||||
self.timeout = timeout
|
||||
self.ssh_host = host
|
||||
@@ -141,9 +141,7 @@ class SSHConnectionPool(urllib3.connectionpool.HTTPConnectionPool):
|
||||
scheme = "ssh"
|
||||
|
||||
def __init__(self, ssh_client=None, timeout=60, maxsize=10, host=None):
|
||||
super(SSHConnectionPool, self).__init__(
|
||||
"localhost", timeout=timeout, maxsize=maxsize
|
||||
)
|
||||
super().__init__("localhost", timeout=timeout, maxsize=maxsize)
|
||||
self.ssh_transport = None
|
||||
self.timeout = timeout
|
||||
if ssh_client:
|
||||
@@ -207,7 +205,7 @@ class SSHHTTPAdapter(BaseHTTPAdapter):
|
||||
self.pools = RecentlyUsedContainer(
|
||||
pool_connections, dispose_func=lambda p: p.close()
|
||||
)
|
||||
super(SSHHTTPAdapter, self).__init__()
|
||||
super().__init__()
|
||||
|
||||
def _create_paramiko_client(self, base_url):
|
||||
logging.getLogger("paramiko").setLevel(logging.WARNING)
|
||||
@@ -272,6 +270,6 @@ class SSHHTTPAdapter(BaseHTTPAdapter):
|
||||
return pool
|
||||
|
||||
def close(self):
|
||||
super(SSHHTTPAdapter, self).close()
|
||||
super().close()
|
||||
if self.ssh_client:
|
||||
self.ssh_client.close()
|
||||
|
||||
@@ -35,7 +35,7 @@ class SSLHTTPAdapter(BaseHTTPAdapter):
|
||||
def __init__(self, ssl_version=None, assert_hostname=None, **kwargs):
|
||||
self.ssl_version = ssl_version
|
||||
self.assert_hostname = assert_hostname
|
||||
super(SSLHTTPAdapter, self).__init__(**kwargs)
|
||||
super().__init__(**kwargs)
|
||||
|
||||
def init_poolmanager(self, connections, maxsize, block=False):
|
||||
kwargs = {
|
||||
@@ -58,7 +58,7 @@ class SSLHTTPAdapter(BaseHTTPAdapter):
|
||||
|
||||
But we still need to take care of when there is a proxy poolmanager
|
||||
"""
|
||||
conn = super(SSLHTTPAdapter, self).get_connection(*args, **kwargs)
|
||||
conn = super().get_connection(*args, **kwargs)
|
||||
if (
|
||||
self.assert_hostname is not None
|
||||
and conn.assert_hostname != self.assert_hostname
|
||||
|
||||
@@ -21,10 +21,10 @@ from .basehttpadapter import BaseHTTPAdapter
|
||||
RecentlyUsedContainer = urllib3._collections.RecentlyUsedContainer
|
||||
|
||||
|
||||
class UnixHTTPConnection(urllib3_connection.HTTPConnection, object):
|
||||
class UnixHTTPConnection(urllib3_connection.HTTPConnection):
|
||||
|
||||
def __init__(self, base_url, unix_socket, timeout=60):
|
||||
super(UnixHTTPConnection, self).__init__("localhost", timeout=timeout)
|
||||
super().__init__("localhost", timeout=timeout)
|
||||
self.base_url = base_url
|
||||
self.unix_socket = unix_socket
|
||||
self.timeout = timeout
|
||||
@@ -37,7 +37,7 @@ class UnixHTTPConnection(urllib3_connection.HTTPConnection, object):
|
||||
self.sock = sock
|
||||
|
||||
def putheader(self, header, *values):
|
||||
super(UnixHTTPConnection, self).putheader(header, *values)
|
||||
super().putheader(header, *values)
|
||||
if header == "Connection" and "Upgrade" in values:
|
||||
self.disable_buffering = True
|
||||
|
||||
@@ -45,14 +45,12 @@ class UnixHTTPConnection(urllib3_connection.HTTPConnection, object):
|
||||
# FIXME: We may need to disable buffering on Py3,
|
||||
# but there's no clear way to do it at the moment. See:
|
||||
# https://github.com/docker/docker-py/issues/1799
|
||||
return super(UnixHTTPConnection, self).response_class(sock, *args, **kwargs)
|
||||
return super().response_class(sock, *args, **kwargs)
|
||||
|
||||
|
||||
class UnixHTTPConnectionPool(urllib3.connectionpool.HTTPConnectionPool):
|
||||
def __init__(self, base_url, socket_path, timeout=60, maxsize=10):
|
||||
super(UnixHTTPConnectionPool, self).__init__(
|
||||
"localhost", timeout=timeout, maxsize=maxsize
|
||||
)
|
||||
super().__init__("localhost", timeout=timeout, maxsize=maxsize)
|
||||
self.base_url = base_url
|
||||
self.socket_path = socket_path
|
||||
self.timeout = timeout
|
||||
@@ -86,7 +84,7 @@ class UnixHTTPAdapter(BaseHTTPAdapter):
|
||||
self.pools = RecentlyUsedContainer(
|
||||
pool_connections, dispose_func=lambda p: p.close()
|
||||
)
|
||||
super(UnixHTTPAdapter, self).__init__()
|
||||
super().__init__()
|
||||
|
||||
def get_connection(self, url, proxies=None):
|
||||
with self.pools.lock:
|
||||
|
||||
@@ -17,7 +17,7 @@ from .._import_helper import urllib3
|
||||
from ..errors import DockerException
|
||||
|
||||
|
||||
class CancellableStream(object):
|
||||
class CancellableStream:
|
||||
"""
|
||||
Stream wrapper for real-time events, logs, etc. from the server.
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ def walk(root, patterns, default=True):
|
||||
|
||||
# Heavily based on
|
||||
# https://github.com/moby/moby/blob/master/pkg/fileutils/fileutils.go
|
||||
class PatternMatcher(object):
|
||||
class PatternMatcher:
|
||||
def __init__(self, patterns):
|
||||
self.patterns = list(filter(lambda p: p.dirs, [Pattern(p) for p in patterns]))
|
||||
self.patterns.append(Pattern("!.dockerignore"))
|
||||
@@ -216,7 +216,7 @@ class PatternMatcher(object):
|
||||
return rec_walk(root)
|
||||
|
||||
|
||||
class Pattern(object):
|
||||
class Pattern:
|
||||
def __init__(self, pattern_str):
|
||||
self.exclusion = False
|
||||
if pattern_str.startswith("!"):
|
||||
|
||||
Reference in New Issue
Block a user