summaryrefslogtreecommitdiff
path: root/modules/language/python/exceptions.scm
blob: fd1f0e13811bc19324b749f2fd221fcd94bc43bc (about) (plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
(define-module (language python exceptions)
  #:use-module (oop pf-objects)
  #:use-module (oop goops)
  #:export (StopIteration GeneratorExit RuntimeError TabError
                          Exception ValueError TypeError
                          IndexError KeyError AttributeError ArgumentError
                          SyntaxError SystemException
                          OSError ProcessLookupError PermissionError
                          None NotImplemented NotImplementedError
			  AssertionError ImportError
                          ModuleNotFoundError BlockingIOError
                          InterruptedError BaseException
			  ZeroDivisionError PendingDeprecationWarning
			  OverflowError RecursionError RuntimeWarning
			  Warning DeprecationWarning BytesWarning
                          ResourceWarning UserWarning UnicodeTranslateError
                          UnicodeDecodeError LookupError IndentationError
                          KeyboardInterrupt MemoryError NameError
                          EOFError UnicodeError UnicodeEncodeError
                          FileExistsError FileNotFoundError IsADirectoryError
			  EnvironmentError ConnectionError NotADirectoryError
                          ConnectionResetError ChildProcessError TimeOutError
                          BrokenPipeError ConnectionAbortedError SystemExit
                          ConnectionRefusedError ArithmeticError
                          FutureWarning))

(define-syntax-rule (aif it p x y) (let ((it p)) (if it x y)))

(define-python-class Exception ()
  (define __init__
    (case-lambda
      ((self)
       (values))
      ((self val . l)
       (set self 'value val))))
                 
  (define __repr__
    (lambda (self)
      (aif it (rawref self 'value #f)
           (format #f "~a:~a"
                   (rawref self '__name__) it)
           (format #f "~a"
                   (rawref self '__name__))))))

(define-python-class SystemExit ()
  (define __init__
    (case-lambda
      ((self)
       (values))
      ((self val . l)
       (set self 'value val))))
                 
  (define __repr__
    (lambda (self)
      (aif it (rawref self 'value #f)
           (format #f "~a:~a"
                   (rawref self '__name__) it)
           (format #f "~a"
                   (rawref self '__name__))))))

(define-python-class Warning ()
  (define __init__
    (case-lambda
      ((self)
       (values))
      ((self val . l)
       (set self 'value val))))
                 
  (define __repr__
    (lambda (self)
      (aif it (rawref self 'value #f)
           (format #f "~a:~a"
                   (rawref self '__name__) it)
           (format #f "~a"
                   (rawref self '__name__))))))

(define-syntax define-er
  (syntax-rules ()
    ((_ nm k)
     (define-python-class nm (Exception)))
    ((_ nm w k)
     (define-python-class nm w))))

(define-syntax define-er2
  (syntax-rules ()
    ((_ nm k)
     (define-python-class nm (BaseException)))
    ((_ nm w k)
     (define-python-class nm w))))

(define StopIteration           'StopIteration)
(define GeneratorExit           'GeneratorExit)
(define-er EnvironmentError     'EnvironmentError)

(define-er EOFError             'EOFError)
(define-er MemoryError          'MemoryError)
(define-er NameError            'NameError)

(define-er ValueError           'ValueError)
(define-python-class UnicodeError (ValueError))
(define-python-class UnicodeDecodeError (UnicodeError))
(define-python-class UnicodeEncodeError (UnicodeError))
(define-python-class UnicodeTranslateError (UnicodeError))

(define-er LookupError          'LookupError)
  (define-python-class IndexError (LookupError))
  (define-python-class KeyError   (LookupError))

(define-er ArithmeticError        'OverflowError)
  (define-python-class OverflowError     (ArithmeticError))
  (define-python-class ZeroDivisionError (ArithmeticError))


(define-er KeyboardInterrupt    'KeyboardInterrupt)
(define-er BaseException        'BaseException)
(define-er SystemException      'SystemException)
(define-er RuntimeError         'RuntimeError)
  (define-python-class NotImplementedError (RuntimeError))
  (define-python-class RecursionError      (RuntimeError)) 


(define-er ArgumentError        'IndexError)

(define-er OSError              'OSError)
  (define-python-class BlockingIOError    (OSError))
  (define-python-class ChildProcessError  (OSError))
  (define-python-class ConnectionError    (OSError))
    (define-python-class BrokenPipeError        (ConnectionError))
    (define-python-class ConnectionAbortedError (ConnectionError))
    (define-python-class ConnectionRefusedError (ConnectionError))
    (define-python-class ConnectionResetError   (ConnectionError))
  (define-python-class FileExistsError    (OSError))
  (define-python-class FileNotFoundError  (OSError))
  (define-python-class InterruptedError   (OSError))
  (define-python-class IsADirectoryError  (OSError))
  (define-python-class NotADirectoryError (OSError))
  (define-python-class PermissionError    (OSError))
  (define-python-class ProcessLookupError (OSError))
  (define-python-class TimeOutError       (OSError))
(define None                    'None)


(define-er TypeError            'TypeError)
(define-er AttributeError       'AttributeError)
(define-er SyntaxError          'SyntaxError)
 (define-python-class IndentationError (SyntaxError))
   (define-python-class TabError (IndentationError))

(define-er RunTimeError         'RunTimeError)

(define AssertionError          'AssertionError)
(define-er ImportError          'ImportError)      
(define-er ModuleNotFoundError  (ImportError) 'ModuleNotFoundError)

(define NotImplemented (list 'NotImplemented))


            

(define-syntax define-wr
  (syntax-rules ()
    ((_ nm k)
     (define-python-class nm (Warning)))
    ((_ nm w k)
     (define-python-class nm w))))

(define-wr BytesWarning              'BytesWarning)
(define-wr DepricationWarning        'DeprecationWarning)
(define-wr ResourceWarning           'ResourceWarning)
(define-wr UserWarning               'UserWarning)
(define-wr PendingDeprecationWarning 'PendingDeprecationWarning)
(define-wr RuntimeWarning            'RuntimeWarning)
(define-wr FutureWarning             'FutureWarning)