Package install :: Package MoSTBioDat :: Package DataBase :: Package ForgetSQL2 :: Module doc_exception
[hide private]
[frames] | no frames]

Source Code for Module install.MoSTBioDat.DataBase.ForgetSQL2.doc_exception

  1  #!/usr/bin/env python 
  2   
  3  """Uses Exception docstrings in Exception printouts. 
  4   
  5  Copyright (c) 2002-2004 Stian Soiland 
  6   
  7  Permission is hereby granted, free of charge, to any person obtaining a 
  8  copy of this software and associated documentation files (the 
  9  "Software"), to deal in the Software without restriction, including 
 10  without limitation the rights to use, copy, modify, merge, publish, 
 11  distribute, sublicense, and/or sell copies of the Software, and to 
 12  permit persons to whom the Software is furnished to do so, subject to 
 13  the following conditions: 
 14   
 15  The above copyright notice and this permission notice shall be included 
 16  in all copies or substantial portions of the Software. 
 17   
 18  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
 19  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
 20  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
 21  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 
 22  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
 23  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
 24  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
 25   
 26  Author: Stian Soiland <stian@soiland.no> 
 27  License: MIT 
 28  URL: http://soiland.no/software 
 29  """ 
 30   
 31   
 32  # -*- coding: iso-8859-1 -*- 
 33   
34 -class DocstringException(Exception):
35 """Makes it easy to define more descriptive error messages. 36 37 >>> class RealityError(DocstringException): 38 ... '''Unreachable point''' 39 40 >>> raise RealityError 41 Traceback (most recent call last): 42 File "<stdin>", line 1, in ? 43 RealityError: Unreachable point 44 45 With argument: 46 47 >>> raise RealityError, "Outside handler" 48 Traceback (most recent call last): 49 File "<stdin>", line 1, in ? 50 RealityError: Unreachable point: Outside handler 51 52 Without docstring: 53 54 >>> class SomeError(RealityError): 55 ... pass 56 >>> raise SomeError 57 Traceback (most recent call last): 58 File "<stdin>", line 1, in ? 59 SomeError 60 61 Without docstring, with argument: 62 63 >>> raise SomeError, 129 64 Traceback (most recent call last): 65 File "<stdin>", line 1, in ? 66 SomeError: 129 67 """
68 - def __str__(self):
69 args = Exception.__str__(self) # Get our arguments 70 71 # We'll only include the docstring if it has been defined in 72 # our direct class. This avoids printing "General Error" when 73 # a class SpecificError(GeneralError) just forgot to specify a 74 # docstring. 75 doc = self.__class__.__doc__ 76 if args and doc: 77 return doc + ': ' + args 78 elif args: 79 # don't worry, our class name will be printed 80 return args 81 else: 82 return doc or ""
83
84 -class RealityError(DocstringException):
85 """This should never happen"""
86 ## example: 87 ## a = "Something" 88 ## if not a == "Something": 89 ## raise RealityError 90
91 -class UnreachableCodeError(RealityError):
92 """Unreachable code"""
93 ## example: 94 ## if 0: 95 ## raise RealityError, "Not 0" 96
97 -class ProgrammingError(DocstringException):
98 """Programming error"""
99 ## example: 100 ## def function(arg1=None, arg2=None): 101 ## if (arg1 and arg2) or not (arg1 or arg2): 102 ## raise ProgrammingError, "Must specify arg1 OR arg2" 103
104 -def _test():
105 import doctest,doc_exception 106 return doctest.testmod(doc_exception)
107 108 if __name__ == "__main__": 109 _test() 110