-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathsys.py
More file actions
99 lines (85 loc) · 2.09 KB
/
sys.py
File metadata and controls
99 lines (85 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
##
# .sys
##
"""
py-postgresql system functions and data.
Data
----
``libpath``
The local file system paths that contain query libraries.
Overridable Functions
---------------------
excformat
Information that makes up an exception's displayed "body".
Effectively, the implementation of `postgresql.exception.Error.__str__`
msghook
Display a message.
"""
import sys
import os
import traceback
from .python.element import format_element
from .python.string import indent
libpath = []
def default_errformat(val):
"""
Built-in error formatter. Do not change.
"""
it = val._e_metas()
if val.creator is not None:
# Protect against element traceback failures.
try:
after = os.linesep + format_element(val.creator)
except Exception:
after = 'Element Traceback of %r caused exception:%s' %(
type(val.creator).__name__,
os.linesep
)
after += indent(traceback.format_exc())
after = os.linesep + indent(after).rstrip()
else:
after = ''
return next(it)[1] \
+ os.linesep + ' ' \
+ (os.linesep + ' ').join(
k + ': ' + v for k, v in it
) + after
def default_msghook(msg, format_message = format_element):
"""
Built-in message hook. DON'T TOUCH!
"""
if sys.stderr and not sys.stderr.closed:
try:
sys.stderr.write(format_message(msg) + os.linesep)
except Exception:
try:
sys.excepthook(*sys.exc_info())
except Exception:
# gasp.
pass
def errformat(*args, **kw):
"""
Raised Database Error formatter pointing to default_excformat.
Override if you like. All postgresql.exceptions.Error's are formatted using
this function.
"""
return default_errformat(*args, **kw)
def msghook(*args, **kw):
"""
Message hook pointing to default_msghook.
Override if you like. All untrapped messages raised by
driver connections come here to be printed to stderr.
"""
return default_msghook(*args, **kw)
def reset_errformat(with_func = errformat):
"""
Restore the original excformat function.
"""
global errformat
errformat = with_func
def reset_msghook(with_func = msghook):
"""
Restore the original msghook function.
"""
global msghook
msghook = with_func