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