smtp
[software/python-on-guile.git] / modules / language / python / exceptions.scm
1 (define-module (language python exceptions)
2 #:use-module (oop pf-objects)
3 #:use-module (oop goops)
4 #:export (StopIteration GeneratorExit RuntimeError TabError
5 Exception ValueError TypeError
6 IndexError KeyError AttributeError ArgumentError
7 SyntaxError SystemException
8 OSError ProcessLookupError PermissionError
9 None NotImplemented NotImplementedError
10 AssertionError ImportError
11 ModuleNotFoundError BlockingIOError
12 InterruptedError BaseException
13 ZeroDivisionError PendingDeprecationWarning
14 OverflowError RecursionError RuntimeWarning
15 Warning DeprecationWarning BytesWarning
16 ResourceWarning UserWarning UnicodeTranslateError
17 UnicodeDecodeError LookupError IndentationError
18 KeyboardInterrupt MemoryError NameError
19 EOFError UnicodeError UnicodeEncodeError
20 FileExistsError FileNotFoundError IsADirectoryError
21 EnvironmentError ConnectionError NotADirectoryError
22 ConnectionResetError ChildProcessError TimeOutError
23 BrokenPipeError ConnectionAbortedError SystemExit
24 ConnectionRefusedError ArithmeticError))
25
26 (define-syntax-rule (aif it p x y) (let ((it p)) (if it x y)))
27
28 (define-python-class Exception ()
29 (define __init__
30 (case-lambda
31 ((self)
32 (values))
33 ((self val . l)
34 (set self 'value val))))
35
36 (define __repr__
37 (lambda (self)
38 (aif it (rawref self 'value #f)
39 (format #f "~a:~a"
40 (rawref self '__name__) it)
41 (format #f "~a"
42 (rawref self '__name__))))))
43
44 (define-python-class SystemExit ()
45 (define __init__
46 (case-lambda
47 ((self)
48 (values))
49 ((self val . l)
50 (set self 'value val))))
51
52 (define __repr__
53 (lambda (self)
54 (aif it (rawref self 'value #f)
55 (format #f "~a:~a"
56 (rawref self '__name__) it)
57 (format #f "~a"
58 (rawref self '__name__))))))
59
60 (define-python-class Warning ()
61 (define __init__
62 (case-lambda
63 ((self)
64 (values))
65 ((self val . l)
66 (set self 'value val))))
67
68 (define __repr__
69 (lambda (self)
70 (aif it (rawref self 'value #f)
71 (format #f "~a:~a"
72 (rawref self '__name__) it)
73 (format #f "~a"
74 (rawref self '__name__))))))
75
76 (define-syntax define-er
77 (syntax-rules ()
78 ((_ nm k)
79 (define-python-class nm (Exception)))
80 ((_ nm w k)
81 (define-python-class nm w))))
82
83 (define-syntax define-er2
84 (syntax-rules ()
85 ((_ nm k)
86 (define-python-class nm (BaseException)))
87 ((_ nm w k)
88 (define-python-class nm w))))
89
90 (define StopIteration 'StopIteration)
91 (define GeneratorExit 'GeneratorExit)
92 (define-er EnvironmentError 'EnvironmentError)
93
94 (define-er EOFError 'EOFError)
95 (define-er MemoryError 'MemoryError)
96 (define-er NameError 'NameError)
97
98 (define-er ValueError 'ValueError)
99 (define-python-class UnicodeError (ValueError))
100 (define-python-class UnicodeDecodeError (UnicodeError))
101 (define-python-class UnicodeEncodeError (UnicodeError))
102 (define-python-class UnicodeTranslateError (UnicodeError))
103
104 (define-er LookupError 'LookupError)
105 (define-python-class IndexError (LookupError))
106 (define-python-class KeyError (LookupError))
107
108 (define-er ArithmeticError 'OverflowError)
109 (define-python-class OverflowError (ArithmeticError))
110 (define-python-class ZeroDivisionError (ArithmeticError))
111
112
113 (define-er KeyboardInterrupt 'KeyboardInterrupt)
114 (define-er BaseException 'BaseException)
115 (define-er SystemException 'SystemException)
116 (define-er RuntimeError 'RuntimeError)
117 (define-python-class NotImplementedError (RuntimeError))
118 (define-python-class RecursionError (RuntimeError))
119
120
121 (define-er ArgumentError 'IndexError)
122
123 (define-er OSError 'OSError)
124 (define-python-class BlockingIOError (OSError))
125 (define-python-class ChildProcessError (OSError))
126 (define-python-class ConnectionError (OSError))
127 (define-python-class BrokenPipeError (ConnectionError))
128 (define-python-class ConnectionAbortedError (ConnectionError))
129 (define-python-class ConnectionRefusedError (ConnectionError))
130 (define-python-class ConnectionResetError (ConnectionError))
131 (define-python-class FileExistsError (OSError))
132 (define-python-class FileNotFoundError (OSError))
133 (define-python-class InterruptedError (OSError))
134 (define-python-class IsADirectoryError (OSError))
135 (define-python-class NotADirectoryError (OSError))
136 (define-python-class PermissionError (OSError))
137 (define-python-class ProcessLookupError (OSError))
138 (define-python-class TimeOutError (OSError))
139 (define None 'None)
140
141
142 (define-er TypeError 'TypeError)
143 (define-er AttributeError 'AttributeError)
144 (define-er SyntaxError 'SyntaxError)
145 (define-python-class IndentationError (SyntaxError))
146 (define-python-class TabError (IndentationError))
147
148 (define-er RunTimeError 'RunTimeError)
149
150 (define AssertionError 'AssertionError)
151 (define-er ImportError 'ImportError)
152 (define-er ModuleNotFoundError (ImportError) 'ModuleNotFoundError)
153
154 (define NotImplemented (list 'NotImplemented))
155
156
157
158
159 (define-syntax define-wr
160 (syntax-rules ()
161 ((_ nm k)
162 (define-python-class nm (Warning)))
163 ((_ nm w k)
164 (define-python-class nm w))))
165
166 (define-wr BytesWarning 'BytesWarning)
167 (define-wr DepricationWarning 'DeprecationWarning)
168 (define-wr ResourceWarning 'ResourceWarning)
169 (define-wr UserWarning 'UserWarning)
170 (define-wr PendingDeprecationWarning 'PendingDeprecationWarning)
171 (define-wr RuntimeWarning 'RuntimeWarning)