diff --git a/Allura/allura/command/reclone_repo.py b/Allura/allura/command/reclone_repo.py index d03d69146..a25e8ca68 100644 --- a/Allura/allura/command/reclone_repo.py +++ b/Allura/allura/command/reclone_repo.py @@ -40,14 +40,7 @@ def command(self): def _setup(self): '''Perform basic setup, suppressing superfluous warnings.''' - with warnings.catch_warnings(): - try: - from sqlalchemy import exc - except ImportError: - pass - else: - warnings.simplefilter("ignore", category=exc.SAWarning) - self.basic_setup() + self.basic_setup() def _load_objects(self): '''Load objects to be operated on.''' diff --git a/Allura/allura/command/script.py b/Allura/allura/command/script.py index a13e121ff..a004d41fa 100644 --- a/Allura/allura/command/script.py +++ b/Allura/allura/command/script.py @@ -44,40 +44,33 @@ class ScriptCommand(base.Command): help='Drop to a debugger on error') def command(self): - with warnings.catch_warnings(): - try: - from sqlalchemy import exc - except ImportError: - pass - else: - warnings.simplefilter("ignore", category=exc.SAWarning) - self.basic_setup() - request = webob.Request.blank('--script--', environ={ - 'paste.registry': self.registry}) - tg.request_local.context.request = request - if self.options.pdb: - base.log.info('Installing exception hook') - sys.excepthook = utils.postmortem_hook - filename = self.args[1] - with open(filename) as fp: - ns = dict(__name__='__main__') - sys.argv = self.args[1:] - code = compile(fp.read(), filename, 'exec') + self.basic_setup() + request = webob.Request.blank('--script--', environ={ + 'paste.registry': self.registry}) + tg.request_local.context.request = request + if self.options.pdb: + base.log.info('Installing exception hook') + sys.excepthook = utils.postmortem_hook + filename = self.args[1] + with open(filename) as fp: + ns = dict(__name__='__main__') + sys.argv = self.args[1:] + code = compile(fp.read(), filename, 'exec') - if self.options.profile: - profile_output_file = self.options.profile_output or '%s.profile' % os.path.basename(filename) - if not os.access(os.path.dirname(profile_output_file), os.W_OK): - raise OSError(f'no write permission to dir for {profile_output_file}. ' - f'Specify a different path with --profile-output') - # https://stackoverflow.com/a/48622889 - pr = cProfile.Profile() - pr.enable() + if self.options.profile: + profile_output_file = self.options.profile_output or '%s.profile' % os.path.basename(filename) + if not os.access(os.path.dirname(profile_output_file), os.W_OK): + raise OSError(f'no write permission to dir for {profile_output_file}. ' + f'Specify a different path with --profile-output') + # https://stackoverflow.com/a/48622889 + pr = cProfile.Profile() + pr.enable() - exec(code, ns) # noqa: S102 + exec(code, ns) # noqa: S102 - if self.options.profile: - pr.disable() - pr.dump_stats(profile_output_file) + if self.options.profile: + pr.disable() + pr.dump_stats(profile_output_file) class SetToolAccessCommand(base.Command): diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py index 23565d98c..bcfa181e3 100644 --- a/Allura/allura/controllers/auth.py +++ b/Allura/allura/controllers/auth.py @@ -34,9 +34,7 @@ from tg import request, response from webob import exc as wexc from paste.deploy.converters import asbool -with warnings.catch_warnings(): # ignore py2 CryptographyDeprecationWarning - warnings.filterwarnings('ignore') - from cryptography.hazmat.primitives.twofactor import InvalidToken +from cryptography.hazmat.primitives.twofactor import InvalidToken from beaker.session import _session_id import allura.tasks.repo_tasks diff --git a/Allura/allura/lib/multifactor.py b/Allura/allura/lib/multifactor.py index 82b924bdc..c80465501 100644 --- a/Allura/allura/lib/multifactor.py +++ b/Allura/allura/lib/multifactor.py @@ -31,12 +31,10 @@ from tg import config from tg import app_globals as g from paste.deploy.converters import asint -with warnings.catch_warnings(): # ignore py2 CryptographyDeprecationWarning - warnings.filterwarnings('ignore') - from cryptography.hazmat.backends import default_backend - from cryptography.hazmat.primitives.twofactor import InvalidToken - from cryptography.hazmat.primitives.twofactor.totp import TOTP - from cryptography.hazmat.primitives.hashes import SHA1 +from cryptography.hazmat.backends import default_backend +from cryptography.hazmat.primitives.twofactor import InvalidToken +from cryptography.hazmat.primitives.twofactor.totp import TOTP +from cryptography.hazmat.primitives.hashes import SHA1 import qrcode from ming.odm import session