Show More
@@ -1,60 +1,60 b'' | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | """ |
|
3 | 3 | Utilities for warnings. Shoudn't we just use the built in warnings module. |
|
4 | 4 | """ |
|
5 | 5 | |
|
6 | 6 | # Copyright (c) IPython Development Team. |
|
7 | 7 | # Distributed under the terms of the Modified BSD License. |
|
8 | 8 | |
|
9 | 9 | from __future__ import print_function |
|
10 | 10 | |
|
11 | 11 | import sys |
|
12 | 12 | |
|
13 | 13 | from IPython.utils import io |
|
14 | 14 | |
|
15 | from warnings import warn | |
|
15 | import warnings | |
|
16 | 16 | |
|
17 | warn("The module IPython.utils.warn is deprecated, use the standard warnings module instead", DeprecationWarning) | |
|
17 | warnings.warn("The module IPython.utils.warn is deprecated, use the standard warnings module instead", DeprecationWarning) | |
|
18 | 18 | |
|
19 | 19 | def warn(msg,level=2,exit_val=1): |
|
20 | 20 | """Standard warning printer. Gives formatting consistency. |
|
21 | 21 | |
|
22 | 22 | Output is sent to io.stderr (sys.stderr by default). |
|
23 | 23 | |
|
24 | 24 | Options: |
|
25 | 25 | |
|
26 | 26 | -level(2): allows finer control: |
|
27 | 27 | 0 -> Do nothing, dummy function. |
|
28 | 28 | 1 -> Print message. |
|
29 | 29 | 2 -> Print 'WARNING:' + message. (Default level). |
|
30 | 30 | 3 -> Print 'ERROR:' + message. |
|
31 | 31 | 4 -> Print 'FATAL ERROR:' + message and trigger a sys.exit(exit_val). |
|
32 | 32 | |
|
33 | 33 | -exit_val (1): exit value returned by sys.exit() for a level 4 |
|
34 | 34 | warning. Ignored for all other levels.""" |
|
35 | 35 | |
|
36 | warn("The module IPython.utils.warn is deprecated, use the standard warnings module instead", DeprecationWarning) | |
|
36 | warnings.warn("The module IPython.utils.warn is deprecated, use the standard warnings module instead", DeprecationWarning) | |
|
37 | 37 | if level>0: |
|
38 | 38 | header = ['','','WARNING: ','ERROR: ','FATAL ERROR: '] |
|
39 | 39 | print(header[level], msg, sep='', file=io.stderr) |
|
40 | 40 | if level == 4: |
|
41 | 41 | print('Exiting.\n', file=io.stderr) |
|
42 | 42 | sys.exit(exit_val) |
|
43 | 43 | |
|
44 | 44 | |
|
45 | 45 | def info(msg): |
|
46 | 46 | """Equivalent to warn(msg,level=1).""" |
|
47 | 47 | |
|
48 | 48 | warn(msg,level=1) |
|
49 | 49 | |
|
50 | 50 | |
|
51 | 51 | def error(msg): |
|
52 | 52 | """Equivalent to warn(msg,level=3).""" |
|
53 | 53 | |
|
54 | 54 | warn(msg,level=3) |
|
55 | 55 | |
|
56 | 56 | |
|
57 | 57 | def fatal(msg,exit_val=1): |
|
58 | 58 | """Equivalent to warn(msg,exit_val=exit_val,level=4).""" |
|
59 | 59 | |
|
60 | 60 | warn(msg,exit_val=exit_val,level=4) |
General Comments 0
You need to be logged in to leave comments.
Login now