Browse Source

Added comment in datahandler class and derived class

m.orban 8 years ago
parent
commit
1f4a822945

+ 27
- 12
lodel/leapi/datahandlers/base_classes.py View File

@@ -77,6 +77,11 @@ class DataHandler(object):
77 77
     def is_internal(self):
78 78
         return self.internal is not False
79 79
 
80
+    ##brief check if a value can be nullable
81
+    #@param value *
82
+    #@throw DataNoneValid if value is None and nullable. LodelExceptions if not nullable 
83
+    #@return value (if not None)
84
+    # @return value
80 85
     def _check_data_value(self, value):
81 86
         if value is None:
82 87
             if not self.nullable:
@@ -84,12 +89,13 @@ class DataHandler(object):
84 89
             raise DataNoneValid("None with a nullable. GOTO CHECK")
85 90
         return value
86 91
 
87
-#
88
-#    ##@brief calls the data_field defined _check_data_value() method
89
-#    #@ingroup lodel2_dh_checks
90
-#    #@warning DO NOT REIMPLEMENT THIS METHOD IN A CUSTOM DATAHANDLER (see
91
-#    #@ref _construct_data() and @ref lodel2_dh_check_impl )
92
-#    #@return tuple (value, error|None)
92
+
93
+    ##@brief calls the data_field defined _check_data_value() method
94
+    #@ingroup lodel2_dh_checks
95
+    #@warning DO NOT REIMPLEMENT THIS METHOD IN A CUSTOM DATAHANDLER (see
96
+    #@ref _construct_data() and @ref lodel2_dh_check_impl)
97
+
98
+    #@return tuple (value, Exceptions)
93 99
     def check_data_value(self, value):
94 100
         try:
95 101
             value = self._check_data_value(value)
@@ -98,7 +104,7 @@ class DataHandler(object):
98 104
         except (LodelExceptions, FieldValidationError) as expt:
99 105
             return None, expt
100 106
         return value, None
101
-#
107
+
102 108
     ##@brief checks if this class can override the given data handler
103 109
     # @param data_handler DataHandler
104 110
     # @return bool
@@ -290,16 +296,17 @@ class Reference(DataHandler):
290 296
     def _set_back_reference(self, back_reference):
291 297
         self.__back_reference = back_reference
292 298
 
293
-    ##@brief Check value
299
+    ##@brief Check and cast value in appropriate type
294 300
     #@param value *
295
-    #@return tuple(value, exception)
296
-    #@todo implement the check when we have LeObject to check value
301
+    #@throw FieldValidationError if value is an appropriate type 
302
+    #@return value
303
+    #@todo implement the check when we have LeObject uid check value
297 304
     def _check_data_value(self, value):
298 305
         value= super()._check_data_value(value)
299 306
         elt = self.__allowed_classes[0]
300 307
         uid = elt.uid_fieldname()[0]# TODO multiple uid is broken
301 308
         if (expt is None and not (isinstance(value, LeObject)) or (value is uid)):
302
-            raise FieldValidationError("LeObject instance or id exxpected for a reference field")
309
+            raise FieldValidationError("LeObject instance or id expected for a reference field")
303 310
         return value
304 311
 
305 312
     def construct_data(self, emcomponent, fname, datas, cur_value):
@@ -345,6 +352,10 @@ class SingleRef(Reference):
345 352
     def __init__(self, allowed_classes = None, **kwargs):
346 353
         super().__init__(allowed_classes = allowed_classes)
347 354
  
355
+    ##@brief Check and cast value in appropriate type
356
+    #@param value *
357
+    #@throw FieldValidationError if value is unappropriate or can not be cast 
358
+    #@return value
348 359
     def _check_data_value(self, value):
349 360
         value = super()._check_data_value(value)
350 361
         if (expt is None and (len(val)>1)):
@@ -366,7 +377,11 @@ class MultipleRef(Reference):
366 377
         self.max_item = max_item
367 378
         super().__init__(**kwargs)
368 379
 
369
-       #@TODO  checkig one by one and put error in a list
380
+    ##@brief Check and cast value in appropriate type
381
+    #@param value *
382
+    #@throw FieldValidationError if value is unappropriate or can not be cast 
383
+    #@return value
384
+    #@TODO  checkig one by one and put error in a list
370 385
     def _check_data_value(self, value):
371 386
         value = super()._check_data_value(value)
372 387
         if not hasattr(value, '__iter__'):

+ 4
- 0
lodel/leapi/datahandlers/datas.py View File

@@ -46,6 +46,10 @@ max_length and regex'
46 46
         self.compiled_re = re.compile(regex)#trigger an error if invalid regex
47 47
         super(self.__class__, self).__init__(max_length=max_length, **kwargs)
48 48
 
49
+    ##@brief Check and cast value in appropriate type
50
+    #@param value *
51
+    #@throw FieldValidationError if value is unappropriate or can not be cast 
52
+    #@return value
49 53
     def _check_data_value(self, value):
50 54
         value = super()._check_data_value(value)
51 55
         if not self.compiled_re.match(value) or len(value) > self.max_length:

+ 16
- 9
lodel/leapi/datahandlers/references.py View File

@@ -17,9 +17,10 @@ class List(MultipleRef):
17 17
     def __init__(self, max_length = None, **kwargs):
18 18
         super().__init__(**kwargs)
19 19
 
20
-    ##@brief Check value
21
-    # @param value *
22
-    # @return tuple(value, exception)
20
+    ##@brief Check and cast value in appropriate type
21
+    #@param value *
22
+    #@throw FieldValidationError if value is unappropriate or can not be cast 
23
+    #@return value
23 24
     def _check_data_value(self, value):
24 25
         super()._check_data_value(value)
25 26
         if (expt is None and not (isinstance(val, list) or isinstance(val, str))):
@@ -35,9 +36,10 @@ class Set(MultipleRef):
35 36
     def __init__(self, **kwargs):
36 37
         super().__init__(**kwargs)
37 38
 
38
-    ##@brief Check value
39
-    # @param value *
40
-    # @return tuple(value, exception)
39
+    ##@brief Check and cast value in appropriate type
40
+    #@param value *
41
+    #@throw FieldValidationError if value is unappropriate or can not be cast 
42
+    #@return value
41 43
     def _check_data_value(self, value):
42 44
         super()._check_data_value(value)
43 45
         if (expt is None and not (isinstance(val, set) or isinstance(val, str))):
@@ -53,9 +55,10 @@ class Map(MultipleRef):
53 55
     def __init__(self, **kwargs):
54 56
         super().__init__(**kwargs)
55 57
 
56
-    ##@brief Check value
57
-    # @param value *
58
-    # @return tuple(value, exception)
58
+    ##@brief Check and cast value in appropriate type
59
+    #@param value *
60
+    #@throw FieldValidationError if value is unappropriate or can not be cast 
61
+    #@return value
59 62
     def _check_data_value(self, value):
60 63
         super()._check_data_value(value)
61 64
         if (expt is None and not isinstance(val, dict)):
@@ -75,6 +78,10 @@ class Hierarch(MultipleRef):
75 78
                             max_childs = max_childs,
76 79
                             **kwargs)
77 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
78 85
     def _check_data_value(self, value):
79 86
         super()._check_data_value(value)
80 87
         if (expt is None and not (isinstance(val, list) or isinstance(val, str))):

Loading…
Cancel
Save