@@ 166-199 (lines=34) @@ | ||
163 | ) |
|
164 | ||
165 | ||
166 | class RequiredArgument(GvmError): |
|
167 | """Raised if a required argument/parameter is missing |
|
168 | ||
169 | Derives from :py:class:`GvmError` |
|
170 | ||
171 | Arguments: |
|
172 | message: Error message to be displayed. Takes precedence over argument |
|
173 | and function. |
|
174 | argument: Optional name of the required argument. |
|
175 | function: Optional name of the called function. |
|
176 | """ |
|
177 | ||
178 | def __init__( |
|
179 | self, |
|
180 | message: Optional[str] = None, |
|
181 | *, |
|
182 | argument: Optional[str] = None, |
|
183 | function: Optional[str] = None, |
|
184 | ): |
|
185 | super().__init__(message, argument, function) |
|
186 | self.argument = argument |
|
187 | self.function = function |
|
188 | ||
189 | def __str__(self): |
|
190 | if self.message: |
|
191 | return self.message |
|
192 | ||
193 | if not self.function: |
|
194 | return "Required argument {}".format(self.argument) |
|
195 | ||
196 | if not self.argument: |
|
197 | return "Required argument missing for {}".format(self.function) |
|
198 | ||
199 | return "{} requires a {} argument".format(self.function, self.argument) |
|
200 | ||
@@ 97-130 (lines=34) @@ | ||
94 | ) |
|
95 | ||
96 | ||
97 | class InvalidArgument(GvmError): |
|
98 | """Raised if an invalid argument/parameter is passed |
|
99 | ||
100 | Derives from :py:class:`GvmError` |
|
101 | ||
102 | Arguments: |
|
103 | message: Error message to be displayed. Takes precedence over argument |
|
104 | and function |
|
105 | argument: Optional name of the invalid argument |
|
106 | function: Optional name of the called function |
|
107 | """ |
|
108 | ||
109 | def __init__( |
|
110 | self, |
|
111 | message: Optional[str] = None, |
|
112 | *, |
|
113 | argument: Optional[str] = None, |
|
114 | function: Optional[str] = None, |
|
115 | ): |
|
116 | super().__init__(message, argument, function) |
|
117 | self.argument = argument |
|
118 | self.function = function |
|
119 | ||
120 | def __str__(self): |
|
121 | if self.message: |
|
122 | return self.message |
|
123 | ||
124 | if not self.function: |
|
125 | return "Invalid argument {}".format(self.argument) |
|
126 | ||
127 | if not self.argument: |
|
128 | return "Invalid argument for {}".format(self.function) |
|
129 | ||
130 | return "Invalid argument {} for {}".format(self.argument, self.function) |
|
131 | ||
132 | ||
133 | class InvalidArgumentType(GvmError): |