Package gensaschema :: Module _exceptions
[frames] | no frames]

Source Code for Module gensaschema._exceptions

 1  # -*- coding: ascii -*- 
 2  r""" 
 3  :Copyright: 
 4   
 5   Copyright 2014 - 2016 
 6   Andr\xe9 Malo or his licensors, as applicable 
 7   
 8  :License: 
 9   
10   Licensed under the Apache License, Version 2.0 (the "License"); 
11   you may not use this file except in compliance with the License. 
12   You may obtain a copy of the License at 
13   
14       http://www.apache.org/licenses/LICENSE-2.0 
15   
16   Unless required by applicable law or agreed to in writing, software 
17   distributed under the License is distributed on an "AS IS" BASIS, 
18   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
19   See the License for the specific language governing permissions and 
20   limitations under the License. 
21   
22  ======================== 
23   GenSASchema Exceptions 
24  ======================== 
25   
26  The module provides all exceptions and warnings used throughout the 
27  `gensaschema` package. 
28  """ 
29  if __doc__:  # pragma: no branch 
30      # pylint: disable = redefined-builtin 
31      __doc__ = __doc__.encode('ascii').decode('unicode_escape') 
32  __author__ = r"Andr\xe9 Malo".encode('ascii').decode('unicode_escape') 
33  __docformat__ = "restructuredtext en" 
34   
35  import warnings as _warnings 
36 37 38 -class Error(Exception):
39 """ Base exception for this package """
40
41 42 -class Warning(Warning): # noqa pylint: disable = redefined-builtin, undefined-variable
43 """ 44 Base warning for this package 45 46 >>> with _warnings.catch_warnings(record=True) as record: 47 ... Warning.emit('my message') 48 ... assert len(record) == 1 49 ... str(record[0].message) 50 'my message' 51 52 >>> _warnings.simplefilter('error') 53 >>> Warning.emit('lalala') 54 Traceback (most recent call last): 55 ... 56 Warning: lalala 57 """ 58 59 @classmethod
60 - def emit(cls, message, stacklevel=1): # pragma: no cover
61 """ 62 Emit a warning of this very category 63 64 This method is pure convenience. It saves you the unfriendly 65 ``warnings.warn`` syntax (and the ``warnings`` import). 66 67 :Parameters: 68 `message` : any 69 The warning message 70 71 `stacklevel` : ``int`` 72 Number of stackframes to go up in order to place the warning 73 source. This is useful for generic warning-emitting helper 74 functions. The stacklevel of *this* helper function is already 75 taken into account. 76 """ 77 # Note that this method cannot be code-covered, probably because of 78 # the stack magic. 79 _warnings.warn(message, cls, max(1, stacklevel) + 1) 80