diff --git a/CHANGES.rst b/CHANGES.rst index db20805..829f6f5 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,9 @@ +v3.5.2 +====== + +#39: Replace use of deprecated ``base64.encode/decodestring`` +with ``encode/decodebytes``. + v3.5.1 ====== diff --git a/keyrings/alt/Windows.py b/keyrings/alt/Windows.py index a9bb45b..dd77220 100644 --- a/keyrings/alt/Windows.py +++ b/keyrings/alt/Windows.py @@ -91,7 +91,7 @@ def get_password(self, service, username): password_saved = winreg.QueryValueEx(hkey, username)[0] password_base64 = password_saved.encode('ascii') # decode with base64 - password_encrypted = base64.decodestring(password_base64) + password_encrypted = base64.decodebytes(password_base64) # decrypted the password password = _win_crypto.decrypt(password_encrypted).decode('utf-8') except EnvironmentError: @@ -103,7 +103,7 @@ def set_password(self, service, username, password): # encrypt the password password_encrypted = _win_crypto.encrypt(password.encode('utf-8')) # encode with base64 - password_base64 = base64.encodestring(password_encrypted) + password_base64 = base64.encodebytes(password_encrypted) # encode again to unicode password_saved = password_base64.decode('ascii') diff --git a/keyrings/alt/file_base.py b/keyrings/alt/file_base.py index 0cb2c14..e7552a0 100644 --- a/keyrings/alt/file_base.py +++ b/keyrings/alt/file_base.py @@ -2,24 +2,14 @@ import os import abc -import base64 import configparser +from base64 import encodebytes, decodebytes from keyring.errors import PasswordDeleteError from keyring.backend import KeyringBackend from keyring.util import platform_, properties from .escape import escape as escape_for_ini -try: - encodebytes = base64.encodebytes -except AttributeError: # pragma: no cover - encodebytes = base64.encodestring - -try: - decodebytes = base64.decodebytes -except AttributeError: # pragma: no cover - decodebytes = base64.decodestring - class FileBacked(object): @abc.abstractproperty diff --git a/keyrings/alt/pyfs.py b/keyrings/alt/pyfs.py index 16c06f5..1610634 100644 --- a/keyrings/alt/pyfs.py +++ b/keyrings/alt/pyfs.py @@ -171,7 +171,7 @@ def get_password(self, service, username): try: password_base64 = self.config.get(service, username).encode() # decode with base64 - password_encrypted = base64.decodestring(password_base64) + password_encrypted = base64.decodebytes(password_base64) # decrypted the password password = self.decrypt(password_encrypted).decode('utf-8') except (configparser.NoOptionError, configparser.NoSectionError): @@ -188,7 +188,7 @@ def set_password(self, service, username, password): password_encrypted = self.encrypt(password.encode('utf-8')) # encode with base64 - password_base64 = base64.encodestring(password_encrypted).decode() + password_base64 = base64.encodebytes(password_encrypted).decode() # write the modification if not self.config.has_section(service): self.config.add_section(service)