Skip to content

Commit

Permalink
Replace ExceptionRaisedContext with ExceptionTrap.passes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Apr 2, 2024
1 parent 9e56f39 commit ea839cc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
10 changes: 6 additions & 4 deletions keyrings/alt/Google.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
pass

from jaraco.classes import properties
from jaraco.context import ExceptionTrap
from keyring import credentials, errors
from keyring.backend import KeyringBackend
from keyring.errors import ExceptionRaisedContext

from . import keyczar

Expand Down Expand Up @@ -74,11 +74,13 @@ def priority(cls):
raise RuntimeError("Requires keyczar")
return 3

# For Python 3.8 compatibility
passes = ExceptionTrap().passes

@passes
@classmethod
def _has_gdata(cls):
with ExceptionRaisedContext() as exc:
gdata.__name__
return not bool(exc)
gdata.__name__

def get_password(self, service, username):
"""Get password of the username for the service"""
Expand Down
12 changes: 8 additions & 4 deletions keyrings/alt/Windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import sys

from jaraco.classes import properties
from jaraco.context import ExceptionTrap
from keyring.backend import KeyringBackend
from keyring.errors import ExceptionRaisedContext, PasswordDeleteError
from keyring.errors import PasswordDeleteError

from . import file_base

Expand All @@ -19,15 +20,18 @@
pass


# For Python 3.8 compatibility
passes = ExceptionTrap().passes


@passes
def has_wincrypto():
"""
Does this environment have wincrypto?
Should return False even when Mercurial's Demand Import allowed import of
_win_crypto, so accesses an attribute of the module.
"""
with ExceptionRaisedContext() as exc:
_win_crypto.__name__
return not bool(exc)
_win_crypto.__name__


class EncryptedKeyring(file_base.Keyring):
Expand Down
12 changes: 8 additions & 4 deletions keyrings/alt/keyczar.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import abc
import os

from jaraco.context import ExceptionTrap

try:
from keyczar import keyczar
except ImportError:
pass

import keyring.backend
from keyring import errors


# For Python 3.8 compatibility
passes = ExceptionTrap().passes


@passes
def has_keyczar():
with errors.ExceptionRaisedContext() as exc:
keyczar.__name__
return not bool(exc)
keyczar.__name__


class BaseCrypter(keyring.backend.Crypter):
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ include_package_data = true
python_requires = >=3.8
install_requires =
jaraco.classes
jaraco.context

[options.extras_require]
testing =
Expand Down

0 comments on commit ea839cc

Please sign in to comment.