Skip to content

Commit

Permalink
Address DeprecationWarning for configparser.readfp() (#7393)
Browse files Browse the repository at this point in the history
* Replace RawConfigParser.readfp(StringIO(str)) with RawConfigParser.read_string()

DeprecationWarning: This method will be removed in Python 3.12. Use 'parser.read_file()' instead.

https://docs.python.org/3/library/configparser.html#configparser.ConfigParser.read_string

* remove usage of six for configparser.RawConfigParser
  • Loading branch information
jonemo committed Nov 3, 2022
1 parent 7cfb49c commit 313d875
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion awscli/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import zipfile
import signal
import contextlib
from configparser import RawConfigParser

from botocore.compat import six
#import botocore.compat
Expand All @@ -36,7 +37,6 @@
BytesIO = six.BytesIO
urlopen = six.moves.urllib.request.urlopen
binary_type = six.binary_type
RawConfigParser = six.moves.configparser.RawConfigParser


# Most, but not all, python installations will have zlib. This is required to
Expand Down
2 changes: 1 addition & 1 deletion awscli/customizations/codeartifact/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def get_commands(cls, endpoint, auth_token, **kwargs):
sys.stdout.write(os.linesep)
raise e
else:
pypi_rc.readfp(StringIO(default_pypi_rc))
pypi_rc.read_string(default_pypi_rc)

pypi_rc_stream = StringIO()
pypi_rc.write(pypi_rc_stream)
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/codeartifact/test_codeartifact_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def _get_twine_commands(self):
pypi_rc.set('codeartifact', 'username', 'aws')
pypi_rc.set('codeartifact', 'password', self.auth_token)
else:
pypi_rc.readfp(StringIO(default_pypi_rc))
pypi_rc.read_string(default_pypi_rc)

pypi_rc_stream = StringIO()
pypi_rc.write(pypi_rc_stream)
Expand Down Expand Up @@ -302,7 +302,7 @@ def _assert_pypi_rc_has_expected_content(
self, pypi_rc_str, server, repo_url=None, username=None, password=None
):
pypi_rc = RawConfigParser()
pypi_rc.readfp(StringIO(pypi_rc_str))
pypi_rc.read_string(pypi_rc_str)

self.assertIn('distutils', pypi_rc.sections())
self.assertIn('index-servers', pypi_rc.options('distutils'))
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/customizations/codeartifact/test_adapter_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dateutil.relativedelta import relativedelta

from awscli.testutils import unittest, mock, FileCreator
from awscli.compat import urlparse, RawConfigParser, StringIO
from awscli.compat import urlparse, RawConfigParser
from awscli.customizations.codeartifact.login import (
BaseLogin, NuGetLogin, DotNetLogin, NpmLogin, PipLogin, TwineLogin,
get_relative_expiration_time
Expand Down Expand Up @@ -590,7 +590,7 @@ def _assert_pypi_rc_has_expected_content(
self, pypi_rc_str, server, repo_url=None, username=None, password=None
):
pypi_rc = RawConfigParser()
pypi_rc.readfp(StringIO(pypi_rc_str))
pypi_rc.read_string(pypi_rc_str)

self.assertIn('distutils', pypi_rc.sections())
self.assertIn('index-servers', pypi_rc.options('distutils'))
Expand Down

0 comments on commit 313d875

Please sign in to comment.