Reverted "Fixed #27818 -- Replaced try/except/pass with contextlib.suppress()."

This reverts commit 550cb3a365
because try/except performs better.
This commit is contained in:
Tim Graham 2017-09-07 08:16:21 -04:00 committed by GitHub
parent 8b2515a450
commit 6e4c6281db
66 changed files with 351 additions and 207 deletions

View file

@ -1,7 +1,6 @@
import os
import signal
import subprocess
from contextlib import suppress
from django.core.files.temp import NamedTemporaryFile
from django.db.backends.base.client import BaseDatabaseClient
@ -41,9 +40,7 @@ class DatabaseClient(BaseDatabaseClient):
if passwd:
# Create temporary .pgpass file.
temp_pgpass = NamedTemporaryFile(mode='w+')
# If the current locale can't encode the data, let the user
# input the password manually.
with suppress(UnicodeEncodeError):
try:
print(
_escape_pgpass(host) or '*',
str(port) or '*',
@ -55,6 +52,10 @@ class DatabaseClient(BaseDatabaseClient):
flush=True,
)
os.environ['PGPASSFILE'] = temp_pgpass.name
except UnicodeEncodeError:
# If the current locale can't encode the data, let the
# user input the password manually.
pass
# Allow SIGINT to pass to psql to abort queries.
signal.signal(signal.SIGINT, signal.SIG_IGN)
subprocess.check_call(args)