Skip to content

Commit a11e58f

Browse files
author
James William Pye
committed
Remove redundant code.
The driver's message printer needs to handle write() failures otherwise it stop a connection in its tracks if stderr is closed.
1 parent d94daa8 commit a11e58f

2 files changed

Lines changed: 10 additions & 20 deletions

File tree

postgresql/api.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
that makes up the basic interfaces used to work with a PostgreSQL.
1717
"""
1818
import os
19+
import sys
1920
import warnings
2021
import collections
2122
from abc import ABCMeta, abstractproperty, abstractmethod
@@ -354,8 +355,8 @@ def __str__(self):
354355

355356
code = "" if not self.code or self.code == "00000" else '(' + self.code + ')'
356357
return sev + code + ': ' + self.message + locstr + detailstr + \
357-
os.linesep + ' ' + \
358-
(os.linesep + ' ').join([': '.join(x[1:]) for x in ss]) + \
358+
os.linesep + \
359+
os.linesep.join([': '.join(x[1:]) for x in ss]) + \
359360
os.linesep
360361

361362
@property
@@ -1432,10 +1433,12 @@ def print_message(self, msg, file = None):
14321433
if file and not file.closed:
14331434
try:
14341435
file.write(str(msg))
1435-
except Exception as err:
1436-
sys.excepthook(*sys.exc_info())
1437-
else:
1438-
warnings.warn("sys.stderr unavailable for printing messages")
1436+
except Exception:
1437+
try:
1438+
sys.excepthook(*sys.exc_info())
1439+
except Exception:
1440+
# What more can be done?
1441+
pass
14391442

14401443
def handle_warnings_and_messages(self, source, this, obj):
14411444
"""

postgresql/driver/pq3.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3193,19 +3193,6 @@ def connect(self, **kw) -> Connection:
31933193
def ife_snapshot_text(self):
31943194
return 'postgresql.driver.pq3'
31953195

3196-
def throw_warnings(self, src, first, obj):
3197-
"use ife_sever() to stop this"
3198-
if isinstance(obj, pg_exc.Warning):
3199-
warnings.warn(obj)
3200-
3201-
def print_messages(self, src, first, obj):
3202-
"use ife_sever() to stop this"
3203-
if not isinstance(obj, pg_exc.Warning) and isinstance(obj, pg_api.Message):
3204-
sys.stderr.write(str(obj))
3205-
32063196
def __init__(self, typio = TypeIO):
32073197
self.typio = typio
3208-
self.ife_connect(
3209-
self.throw_warnings,
3210-
self.print_messages
3211-
)
3198+
super().__init__()

0 commit comments

Comments
 (0)