From c214689d0bf67bbe64b657b5b8054acdab64a7a0 Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Thu, 14 Apr 2022 12:26:09 +1000 Subject: [PATCH] Remove inspect method for Python 3.11 --- CHANGELOG.md | 1 + setup.py | 3 ++- winrm/transport.py | 49 ++++++++-------------------------------------- 3 files changed, 11 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1488e94..d3e17a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Version 0.4.3 - Fix invalid regex escape sequences. - Decoding CLIXML failures for `run_ps` will create a `UserWarning` rather than printing the warning. +- Remove usage of deprecated Python API to support Python 3.11 ### Version 0.4.2 - Dropped Python 3.5 from support matrix as it is EOL. diff --git a/setup.py b/setup.py index 752bb38..5b6c1a0 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ license='MIT license', packages=find_packages(), package_data={'winrm.tests': ['*.ps1']}, - install_requires=['xmltodict', 'requests>=2.9.1', 'requests_ntlm>=0.3.0', 'six'], + install_requires=['xmltodict', 'requests>=2.9.1', 'requests_ntlm>=1.1.0', 'six'], extras_require={ 'credssp': ['requests-credssp>=1.0.0'], 'kerberos:sys_platform=="win32"': ['winkerberos>=0.5.0'], @@ -44,6 +44,7 @@ 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: Implementation :: PyPy', 'Topic :: Software Development :: Libraries :: Python Modules', 'Topic :: System :: Clustering', diff --git a/winrm/transport.py b/winrm/transport.py index dbfb4cd..5d65188 100644 --- a/winrm/transport.py +++ b/winrm/transport.py @@ -1,7 +1,6 @@ from __future__ import unicode_literals import sys import os -import inspect import requests import requests.auth import warnings @@ -228,12 +227,10 @@ def build_session(self): if self.auth_method == 'kerberos': if not HAVE_KERBEROS: - raise WinRMError("requested auth method is kerberos, but requests_kerberos is not installed") + raise WinRMError("requested auth method is kerberos, but pykerberos is not installed") - man_args = dict( + session.auth = HTTPKerberosAuth( mutual_authentication=REQUIRED, - ) - opt_args = dict( delegate=self.kerberos_delegation, force_preemptive=True, principal=self.username, @@ -242,8 +239,6 @@ def build_session(self): service=self.service, send_cbt=self.send_cbt ) - kerb_args = self._get_args(man_args, opt_args, HTTPKerberosAuth.__init__) - session.auth = HTTPKerberosAuth(**kerb_args) encryption_available = hasattr(session.auth, 'winrm_encryption_available') and session.auth.winrm_encryption_available elif self.auth_method in ['certificate', 'ssl']: if self.auth_method == 'ssl' and not self.cert_pem and not self.cert_key_pem: @@ -257,15 +252,12 @@ def build_session(self): elif self.auth_method == 'ntlm': if not HAVE_NTLM: raise WinRMError("requested auth method is ntlm, but requests_ntlm is not installed") - man_args = dict( + + session.auth = HttpNtlmAuth( username=self.username, - password=self.password + password=self.password, + send_cbt=self.send_cbt, ) - opt_args = dict( - send_cbt=self.send_cbt - ) - ntlm_args = self._get_args(man_args, opt_args, HttpNtlmAuth.__init__) - session.auth = HttpNtlmAuth(**ntlm_args) # check if requests_ntlm has the session_security attribute available for encryption encryption_available = hasattr(session.auth, 'session_security') # TODO: ssl is not exactly right here- should really be client_cert @@ -275,17 +267,13 @@ def build_session(self): if not HAVE_CREDSSP: raise WinRMError("requests auth method is credssp, but requests-credssp is not installed") - man_args = dict( + session.auth = HttpCredSSPAuth( username=self.username, - password=self.password - ) - opt_args = dict( + password=self.password, disable_tlsv1_2=self.credssp_disable_tlsv1_2, auth_mechanism=self.credssp_auth_mechanism, minimum_version=self.credssp_minimum_version ) - credssp_args = self._get_args(man_args, opt_args, HttpCredSSPAuth.__init__) - session.auth = HttpCredSSPAuth(**credssp_args) encryption_available = True else: raise WinRMError("unsupported auth method: %s" % self.auth_method) @@ -355,24 +343,3 @@ def _get_message_response_text(self, response): else: response_text = response.content return response_text - - def _get_args(self, mandatory_args, optional_args, function): - argspec = set(inspect.getargspec(function).args) - function_args = dict() - for name, value in mandatory_args.items(): - if name in argspec: - function_args[name] = value - else: - raise Exception("Function %s does not contain mandatory arg " - "%s, check installed version with pip list" - % (str(function), name)) - - for name, value in optional_args.items(): - if name in argspec: - function_args[name] = value - else: - warnings.warn("Function %s does not contain optional arg %s, " - "check installed version with pip list" - % (str(function), name)) - - return function_args