Package jsondata :: Module JSONDataExceptions
[hide private]
[frames] | no frames]

Source Code for Module jsondata.JSONDataExceptions

  1  # -*- coding:utf-8   -*- 
  2  """Common exceptions for the package 'jsondata'. 
  3  """ 
  4  __author__ = 'Arno-Can Uestuensoez' 
  5  __maintainer__ = 'Arno-Can Uestuensoez' 
  6  __license__ = "Artistic-License-2.0 + Forced-Fairplay-Constraints" 
  7  __copyright__ = "Copyright (C) 2015-2016 Arno-Can Uestuensoez @Ingenieurbuero Arno-Can Uestuensoez" 
  8  __version__ = '0.2.18' 
  9  __uuid__='63b597d6-4ada-4880-9f99-f5e0961351fb' 
 10   
 11  import sys 
 12  version = '{0}.{1}'.format(*sys.version_info[:2]) 
 13  if not version in ('2.6','2.7',): # pragma: no cover 
 14      raise Exception("Requires Python-2.6.* or higher") 
 15  # if version < '2.7': # pragma: no cover 
 16  #     raise Exception("Requires Python-2.7.* or higher") 
 17   
 18  # Sets display for inetractive JSON/JSONschema design. 
 19  _interactive = False 
 20   
21 -class JSONDataException(Exception):
22 """ base Exception.""" 23
24 - def __init__(self,*arg):
25 """To be replaced by derived Exceptions. 26 27 Fetch standard parameters and forward message to base class 'Exception'. 28 """ 29 self.fetch(*arg) 30 Exception.__init__(self,self.s)
31
32 - def fetch(self,*arg):
33 """Fetch arguments. 34 35 Args: 36 *args: The following order is expected: 37 38 0. Reason of exception. 39 40 1. Name of object that caused the exception. 41 42 2. Value of the object. 43 44 Returns: 45 None. 46 47 Raises: 48 None. 49 """ 50 self.s="" 51 for a in arg: 52 self.s+=":"+str(a) 53 self.s=self.s[1:]
54
55 - def __repr__(self):
56 """Cause: <reason>:<object>:<value>""" 57 return self.s
58
59 - def __str__(self):
60 """Cause with additional header text.""" 61 return "ERROR::"+self.s
62 63 # 64 # generic exceptions 65 # 66
67 -class JSONDataKeyError(JSONDataException,KeyError):
68 """ Error on key.""" 69
70 - def __init__(self,*arg):
71 JSONDataException.fetch(self,*arg) 72 KeyError.__init__(self,self.s)
73
74 - def __str__(self):
75 return "JSONDataKeyError:"+self.s
76
77 -class JSONDataNodeType(JSONDataException):
78 """ Error on NodeTypes."""
79 - def __str__(self):
80 return "JSONDataNodeType:"+self.s
81
82 -class JSONDataParameter(JSONDataException):
83 """ Erroneous parameters."""
84 - def __str__(self):
85 return "JSONDataParameter:"+self.s
86
87 -class JSONDataSourceFile(JSONDataException):
88 """ Error on read of a source file."""
89 - def __str__(self):
90 return "JSONDataSourceFile:"+self.s
91
92 -class JSONDataTargetFile(JSONDataException):
93 """ Error on writing a file."""
94 - def __str__(self):
95 return "JSONDataTargetFile:"+self.s
96
97 -class JSONDataValue(JSONDataException):
98 """ Error on a value."""
99 - def __str__(self):
100 return "JSONDataValue:"+self.s
101