-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexception.py
184 lines (102 loc) · 3.88 KB
/
exception.py
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
174
175
176
177
178
179
180
181
182
183
184
# -*- coding: utf-8 -*-
# This file is part of the pymfony package.
#
# (c) Alexandre Quercia <[email protected]>
#
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.
from __future__ import absolute_import;
from pymfony.component.system import Object;
from pymfony.component.system.oop import interface;
from pymfony.component.system.exception import RuntimeException;
"""
"""
@interface
class ExceptionInterface(Object):
"""Exception interface for all exceptions thrown by the component.
@author: Fabien Potencier <[email protected]>
@api
"""
class RuntimeException(RuntimeException, ExceptionInterface):
"""Exception class thrown when an error occurs during parsing.
@author: Romain Neutron <[email protected]>
@api
"""
class ParseException(RuntimeException):
"""Exception class thrown when an error occurs during parsing.
@author: Fabien Potencier <[email protected]>
@api
"""
def __init__(self, message, parsedLine = -1, snippet = None, parsedFile = None, previous = None):
"""Constructor.
@param: string message The error message
@param integer parsedLine The line where the error occurred
@param integer snippet The snippet of code near the problem
@param string parsedFile The file name where the error occurred
@param Exception previous The previous exception
"""
if previous:
assert isinstance(previous, Exception);
self.__parsedFile = None;
self.__parsedLine = None;
self.__snippet = None;
self.__rawMessage = None;
self.__parsedFile = parsedFile;
self.__parsedLine = parsedLine;
self.__snippet = snippet;
self.__rawMessage = message;
self.__updateRepr();
RuntimeException.__init__(self, self._message, 0, previous);
def getSnippet(self):
"""Gets the snippet of code near the error.
@return: string The snippet of code
"""
return self.__snippet;
def setSnippet(self, snippet):
"""Sets the snippet of code near the error.
@param: string snippet The code snippet
"""
self.__snippet = snippet;
self.__updateRepr();
def getParsedFile(self):
"""Gets the filename where the error occurred.
This method returns None if a string is parsed.:
@return: string The filename
"""
return self.__parsedFile;
def setParsedFile(self, parsedFile):
"""Sets the filename where the error occurred.
@param: string parsedFile The filename
"""
self.__parsedFile = parsedFile;
self.__updateRepr();
def getParsedLine(self):
"""Gets the line where the error occurred.
@return: integer The file line
"""
return self.__parsedLine;
def setParsedLine(self, parsedLine):
"""Sets the line where the error occurred.
@param: integer parsedLine The file line
"""
self.__parsedLine = parsedLine;
self.__updateRepr();
def __updateRepr(self):
self._message = self.__rawMessage;
dot = False;
if self._message.endswith('.'):
self._message = self._message[:-1];
dot = True;
if (None is not self.__parsedFile) :
self._message += ' in {0}'.format(repr(self.__parsedFile));
if (self.__parsedLine >= 0) :
self._message += ' at line {0}'.format(self.__parsedLine);
if (self.__snippet) :
self._message += ' (near "{0}")'.format(self.__snippet);
if (dot) :
self._message += '.';
class DumpException(RuntimeException):
"""Exception class raise when an error occurs during dumping.
@author: Fabien Potencier <[email protected]>
@api
"""