Skip to content

Commit

Permalink
In Windows backend, remove support for old PyWin32 errors. Users need…
Browse files Browse the repository at this point in the history
… to install a modern pywin32. Ref #140.
  • Loading branch information
jaraco committed Nov 28, 2021
1 parent a938a52 commit 0426944
Showing 1 changed file with 0 additions and 27 deletions.
27 changes: 0 additions & 27 deletions keyring/backends/Windows.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import functools
import logging

from ..util import properties
Expand Down Expand Up @@ -111,7 +110,6 @@ def _get_password(self, target):
Type=win32cred.CRED_TYPE_GENERIC, TargetName=target
)
except pywintypes.error as e:
e = OldPywinError.wrap(e)
if e.winerror == 1168 and e.funcname == 'CredRead': # not found
return None
raise
Expand Down Expand Up @@ -156,7 +154,6 @@ def _delete_password(self, target):
try:
win32cred.CredDelete(Type=win32cred.CRED_TYPE_GENERIC, TargetName=target)
except pywintypes.error as e:
e = OldPywinError.wrap(e)
if e.winerror == 1168 and e.funcname == 'CredDelete': # not found
return
raise
Expand All @@ -172,27 +169,3 @@ def get_credential(self, service, username):
if not res:
return None
return SimpleCredential(res['UserName'], res.value)


class OldPywinError:
"""
A compatibility wrapper for old PyWin32 errors, such as reported in
https://bitbucket.org/kang/python-keyring-lib/issue/140/
"""

def __init__(self, orig):
self.orig = orig

@property
def funcname(self):
return self.orig[1]

@property
def winerror(self):
return self.orig[0]

@classmethod
def wrap(cls, orig_err):
attr_check = functools.partial(hasattr, orig_err)
is_old = not all(map(attr_check, ['funcname', 'winerror']))
return cls(orig_err) if is_old else orig_err

0 comments on commit 0426944

Please sign in to comment.