-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathwarnings.py
36 lines (25 loc) · 982 Bytes
/
warnings.py
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
# This file is part of rinohtype, the Python document preparation system.
#
# Copyright (c) Brecht Machiels.
#
# Use of this source code is subject to the terms of the GNU Affero General
# Public License v3. See the LICENSE file or http://www.gnu.org/licenses/.
import sys
import warnings
from warnings import formatwarning as standard_formatwarning
from warnings import showwarning as standard_showwarning
class RinohWarning(UserWarning):
@property
def message(self):
return self.args[0]
def warn(message):
warnings.warn(message, category=RinohWarning, stacklevel=2)
def showwarning(warning, category, filename, lineno, file=None, line=None):
if category == RinohWarning:
if file is None:
file = sys.stderr
file.write('\r{}\n'.format(warning.message))
else:
return standard_showwarning(warning, category, filename, lineno, file,
line)
warnings.showwarning = showwarning