Skip to content

Commit

Permalink
Merge pull request #40 from jaraco/bugfix/39-python39
Browse files Browse the repository at this point in the history
Use encode/decodebytes. Fixes #39.
  • Loading branch information
jaraco authored Sep 25, 2020
2 parents 7833153 + 8019adb commit c7c2680
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v3.5.2
======

#39: Replace use of deprecated ``base64.encode/decodestring``
with ``encode/decodebytes``.

v3.5.1
======

Expand Down
4 changes: 2 additions & 2 deletions keyrings/alt/Windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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')

Expand Down
12 changes: 1 addition & 11 deletions keyrings/alt/file_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions keyrings/alt/pyfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand Down

0 comments on commit c7c2680

Please sign in to comment.