Browse Source

Moved new class exceptions in exceptions.py

m.orban 8 years ago
parent
commit
67bd4087a9

+ 12
- 0
lodel/exceptions.py View File

@@ -30,3 +30,15 @@ class LodelExceptions(LodelException):
30 30
 #@note Designed to be raised in dramatic case
31 31
 class LodelFatalError(Exception):
32 32
     pass
33
+
34
+##@brief Designed to be a catched exception.
35
+#
36
+#@note Designed to be raised in DataHandler
37
+class DataNoneValid(Exception):
38
+    pass
39
+    
40
+##@brief Designed to be a catched exception.
41
+#
42
+#@note Designed to be raised in DataHandler
43
+class FieldValidationError(Exception):
44
+    pass

+ 1
- 6
lodel/leapi/datahandlers/base_classes.py View File

@@ -11,11 +11,6 @@ import warnings
11 11
 from lodel.exceptions import *
12 12
 from lodel import logger
13 13
 
14
-class DataNoneValid(Exception):
15
-    pass
16
-
17
-class FieldValidationError(Exception):
18
-    pass
19 14
 
20 15
 ##@brief Base class for all data handlers
21 16
 #@ingroup lodel2_datahandlers
@@ -378,7 +373,7 @@ class MultipleRef(Reference):
378 373
     #@param value *
379 374
     #@throw FieldValidationError if value is unappropriate or can not be cast 
380 375
     #@return value
381
-    #@TODO  checkig one by one and put error in a list
376
+    #@TODO  Writing test error for errors when stored multiple references in one field
382 377
     def _check_data_value(self, value):
383 378
         value = super()._check_data_value(value)
384 379
         if not hasattr(value, '__iter__'):

+ 1
- 1
lodel/leapi/datahandlers/datas.py View File

@@ -2,7 +2,7 @@
2 2
 import warnings
3 3
 import inspect
4 4
 from lodel.leapi.datahandlers.datas_base import *
5
-from lodel.leapi.datahandlers.base_classes import FieldValidationError
5
+from lodel.exceptions import *
6 6
 import re
7 7
 
8 8
 ##@brief Data field designed to handle formated strings

+ 24
- 1
lodel/leapi/datahandlers/datas_base.py View File

@@ -4,7 +4,9 @@ import datetime
4 4
 import time
5 5
 import os
6 6
 
7
-from lodel.leapi.datahandlers.base_classes import DataField, FieldValidationError
7
+from lodel.leapi.datahandlers.base_classes import DataField
8
+from lodel.exceptions import *
9
+
8 10
 
9 11
 ##@brief Data field designed to handle boolean values
10 12
 class Boolean(DataField):
@@ -18,6 +20,10 @@ class Boolean(DataField):
18 20
         #    kwargs['check_data_value'] = self._check_data_value
19 21
         super().__init__(ftype='bool', **kwargs)
20 22
 
23
+    ##@brief Check and cast value in appropriate type
24
+    #@param value *
25
+    #@throw FieldValidationError if value is unappropriate or can not be cast 
26
+    #@return value
21 27
     def _check_data_value(self, value):
22 28
         value = super()._check_data_value(value)   
23 29
         if not isinstance(value, bool):
@@ -34,6 +40,10 @@ class Integer(DataField):
34 40
     def __init__(self, **kwargs):
35 41
         super().__init__( **kwargs)
36 42
 
43
+    ##@brief Check and cast value in appropriate type
44
+    #@param value *
45
+    #@throw FieldValidationError if value is unappropriate or can not be cast 
46
+    #@return value
37 47
     def _check_data_value(self, value, strict = False):
38 48
         value = super()._check_data_value(value)
39 49
         if (strict and isinstance(value, int)):
@@ -68,6 +78,10 @@ class Varchar(DataField):
68 78
             return False
69 79
         return True
70 80
     
81
+    ##@brief Check and cast value in appropriate type
82
+    #@param value *
83
+    #@throw FieldValidationError if value is unappropriate or can not be cast 
84
+    #@return value
71 85
     def _check_data_value(self, value):
72 86
         value = super()._check_data_value(value)   
73 87
         if not isinstance(value, str):
@@ -75,6 +89,7 @@ class Varchar(DataField):
75 89
         if len(value) > self.max_length:
76 90
              raise FieldValidationError("The value '%s' is longer than the maximum length of this field (%s)" % (value, self.max_length))
77 91
         return value
92
+
78 93
 ##@brief Data field designed to handle date & time 
79 94
 class DateTime(DataField):
80 95
 
@@ -91,6 +106,10 @@ class DateTime(DataField):
91 106
         self.datetime_format = '%Y-%m-%d' if 'format' not in kwargs else kwargs['format']
92 107
         super().__init__(**kwargs)
93 108
 
109
+    ##@brief Check and cast value in appropriate type
110
+    #@param value *
111
+    #@throw FieldValidationError if value is unappropriate or can not be cast 
112
+    #@return value
94 113
     def _check_data_value(self, value):
95 114
         value = super()._check_data_value(value)
96 115
         if isinstance(value,str):
@@ -116,6 +135,10 @@ class Text(DataField):
116 135
     def __init__(self, **kwargs):
117 136
         super(self.__class__, self).__init__(ftype='text', **kwargs)
118 137
     
138
+    ##@brief Check and cast value in appropriate type
139
+    #@param value *
140
+    #@throw FieldValidationError if value is unappropriate or can not be cast 
141
+    #@return value
119 142
     def _check_data_value(self, value):
120 143
         value = super()._check_data_value(value)   
121 144
         if not isinstance(value, str):

+ 2
- 2
lodel/leapi/datahandlers/references.py View File

@@ -1,6 +1,6 @@
1 1
 # -*- coding: utf-8 -*-
2
-from lodel.leapi.datahandlers.base_classes import Reference, MultipleRef, SingleRef, FieldValidationError, DataNoneValid
3
-
2
+from lodel.leapi.datahandlers.base_classes import Reference, MultipleRef, SingleRef
3
+from lodel.exceptions import *
4 4
 from lodel import logger
5 5
 
6 6
 class Link(SingleRef):

Loading…
Cancel
Save