##// END OF EJS Templates
Deprecated the module IPython.utils.warn
Pierre Gerold -
Show More
@@ -1,57 +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 warning import warn
16
17 warn("The module IPython.utils.warn is deprecated, use the standard warnings module instead", DeprecationWarning)
15 18
16 19 def warn(msg,level=2,exit_val=1):
17 20 """Standard warning printer. Gives formatting consistency.
18 21
19 22 Output is sent to io.stderr (sys.stderr by default).
20 23
21 24 Options:
22 25
23 26 -level(2): allows finer control:
24 27 0 -> Do nothing, dummy function.
25 28 1 -> Print message.
26 29 2 -> Print 'WARNING:' + message. (Default level).
27 30 3 -> Print 'ERROR:' + message.
28 31 4 -> Print 'FATAL ERROR:' + message and trigger a sys.exit(exit_val).
29 32
30 33 -exit_val (1): exit value returned by sys.exit() for a level 4
31 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 37 if level>0:
34 38 header = ['','','WARNING: ','ERROR: ','FATAL ERROR: ']
35 39 print(header[level], msg, sep='', file=io.stderr)
36 40 if level == 4:
37 41 print('Exiting.\n', file=io.stderr)
38 42 sys.exit(exit_val)
39 43
40 44
41 45 def info(msg):
42 46 """Equivalent to warn(msg,level=1)."""
43 47
44 48 warn(msg,level=1)
45 49
46 50
47 51 def error(msg):
48 52 """Equivalent to warn(msg,level=3)."""
49 53
50 54 warn(msg,level=3)
51 55
52 56
53 57 def fatal(msg,exit_val=1):
54 58 """Equivalent to warn(msg,exit_val=exit_val,level=4)."""
55 59
56 60 warn(msg,exit_val=exit_val,level=4)
57
General Comments 0
You need to be logged in to leave comments. Login now