Browse Source

Code cleaning on references module

Roland Haroutiounian 7 years ago
parent
commit
dc3a8f4e22
1 changed files with 39 additions and 34 deletions
  1. 39
    34
      lodel/leapi/datahandlers/references.py

+ 39
- 34
lodel/leapi/datahandlers/references.py View File

@@ -3,35 +3,37 @@
3 3
 from lodel.context import LodelContext
4 4
 LodelContext.expose_modules(globals(), {
5 5
     'lodel.leapi.datahandlers.base_classes': ['Reference', 'MultipleRef',
6
-        'SingleRef'],
6
+                                              'SingleRef'],
7 7
     'lodel.logger': 'logger',
8 8
     'lodel.exceptions': ['LodelException', 'LodelExceptions',
9
-        'LodelFatalError', 'DataNoneValid', 'FieldValidationError']})
9
+                         'LodelFatalError', 'DataNoneValid',
10
+                         'FieldValidationError']})
11
+
10 12
 
11 13
 class Link(SingleRef):
12 14
     pass
13 15
 
14 16
 
15
-##@brief Child class of MultipleRef where references are represented in the form of a python list
17
+## @brief Child class of MultipleRef where references are represented in the form of a python list
16 18
 class List(MultipleRef):
17 19
 
18
-    ##@brief instanciates a list reference
20
+    ## @brief instanciates a list reference
19 21
     # @param max_length int
20 22
     # @param kwargs
21 23
     #   - allowed_classes list | None : list of allowed em classes if None no restriction
22 24
     #   - internal bool
23 25
 
24
-    def __init__(self, max_length = None, **kwargs):
26
+    def __init__(self, max_length=None, **kwargs):
25 27
         super().__init__(**kwargs)
26 28
 
27 29
     @classmethod
28 30
     def empty(cls):
29 31
         return list()
30 32
 
31
-    ##@brief Check and cast value in appropriate type
32
-    #@param value *
33
-    #@throw FieldValidationError if value is unappropriate or can not be cast 
34
-    #@return value
33
+    ## @brief Check and cast value in appropriate type
34
+    # @param value *
35
+    # @throw FieldValidationError if value is unappropriate or can not be cast
36
+    # @return value
35 37
     def _check_data_value(self, value):
36 38
         value = super()._check_data_value(value)
37 39
         try:
@@ -39,12 +41,12 @@ class List(MultipleRef):
39 41
         except Exception as e:
40 42
             raise FieldValidationError("Given iterable is not castable in \
41 43
 a list : %s" % e)
42
-        return value
43 44
 
44
-##@brief Child class of MultipleRef where references are represented in the form of a python set
45
+
46
+## @brief Child class of MultipleRef where references are represented in the form of a python set
45 47
 class Set(MultipleRef):
46 48
 
47
-    ##@brief instanciates a set reference
49
+    ## @brief instanciates a set reference
48 50
     # @param kwargs : named arguments
49 51
     #   - allowed_classes list | None : list of allowed em classes if None no restriction
50 52
     #   - internal bool : if False, the field is not internal
@@ -55,10 +57,10 @@ class Set(MultipleRef):
55 57
     def empty(cls):
56 58
         return set()
57 59
 
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
60
+    ## @brief Check and cast value in appropriate type
61
+    # @param value *
62
+    # @throw FieldValidationError if value is unappropriate or can not be cast
63
+    # @return value
62 64
     def _check_data_value(self, value):
63 65
         value = super()._check_data_value(value)
64 66
         try:
@@ -66,11 +68,12 @@ class Set(MultipleRef):
66 68
         except Exception as e:
67 69
             raise FieldValidationError("Given iterable is not castable in \
68 70
 a set : %s" % e)
69
-    
70
-##@brief Child class of MultipleRef where references are represented in the form of a python dict
71
+
72
+
73
+## @brief Child class of MultipleRef where references are represented in the form of a python dict
71 74
 class Map(MultipleRef):
72 75
 
73
-    ##@brief instanciates a dict reference
76
+    ## @brief instanciates a dict reference
74 77
     # @param kwargs : named arguments
75 78
     #   - allowed_classes list | None : list of allowed em classes if None no restriction
76 79
     #   - internal bool : if False, the field is not internal
@@ -81,38 +84,40 @@ class Map(MultipleRef):
81 84
     def empty(cls):
82 85
         return dict()
83 86
 
84
-    ##@brief Check and cast value in appropriate type
85
-    #@param value *
86
-    #@throw FieldValidationError if value is unappropriate or can not be cast 
87
-    #@return value
87
+    ## @brief Check and cast value in appropriate type
88
+    # @param value *
89
+    # @throw FieldValidationError if value is unappropriate or can not be cast
90
+    # @return value
88 91
     def _check_data_value(self, value):
89 92
         value = super()._check_data_value(value)
90 93
         if not isinstance(value, dict):
91 94
             raise FieldValidationError("Values for dict fields should be dict")
92 95
         return value
93 96
 
94
-##@brief This Reference class is designed to handler hierarchy with some constraint
97
+
98
+## @brief This Reference class is designed to handler hierarchy with some constraint
95 99
 class Hierarch(MultipleRef):
96 100
     
97 101
     directly_editable = False
98
-    ##@brief Instanciate a data handler handling hierarchical relation with constraints
102
+
103
+    ## @brief Instanciate a data handler handling hierarchical relation with constraints
99 104
     # @param back_reference tuple : Here it is mandatory to have a back ref (like a parent field)
100 105
     # @param max_depth int | None :  limit of depth
101 106
     # @param max_childs int | Nine : maximum number of childs by nodes
102
-    def __init__(self, back_reference, max_depth = None, max_childs = None, **kwargs):
103
-        super().__init__(   back_reference = back_reference,
104
-                            max_depth = max_depth,
105
-                            max_childs = max_childs,
106
-                            **kwargs)
107
+    def __init__(self, back_reference, max_depth=None, max_childs=None, **kwargs):
108
+        super().__init__(back_reference=back_reference,
109
+                         max_depth=max_depth,
110
+                         max_childs=max_childs,
111
+                         **kwargs)
107 112
 
108 113
     @classmethod
109 114
     def empty(cls):
110 115
         return tuple()
111 116
 
112
-    ##@brief Check and cast value in appropriate type
113
-    #@param value *
114
-    #@throw FieldValidationError if value is unappropriate or can not be cast 
115
-    #@return value
117
+    ## @brief Check and cast value in appropriate type
118
+    # @param value *
119
+    # @throw FieldValidationError if value is unappropriate or can not be cast
120
+    # @return value
116 121
     def _check_data_value(self, value):
117 122
         value = super()._check_data_value(value)
118 123
         if  not (isinstance(value, list) or isinstance(value, str)):

Loading…
Cancel
Save