17
17
import yaml
18
18
19
19
from ioc .component import Definition , Reference , WeakReference , ContainerBuilder
20
- import ioc .helper
21
20
import ioc .exceptions
22
- from . import misc
23
-
24
- from .misc import OrderedDictYAMLLoader
21
+ import ioc .misc
25
22
26
23
class Loader (object ):
27
- def fix_config (self , config : dict [str , Any ]) -> 'ioc.helper .Dict' :
24
+ def fix_config (self , config : dict [str , Any ]) -> 'ioc.misc .Dict' :
28
25
for key , value in config .items ():
29
26
if isinstance (value , dict ):
30
27
config [key ] = self .fix_config (value )
31
28
32
- return ioc .helper .Dict (config )
29
+ return ioc .misc .Dict (config )
33
30
34
31
class YamlLoader (Loader ):
35
32
def support (self , file : str ) -> bool :
@@ -42,7 +39,7 @@ def load(self, file: str, container_builder: ContainerBuilder) -> None:
42
39
content = f .read ()
43
40
44
41
try :
45
- data = yaml .load (content , OrderedDictYAMLLoader )
42
+ data = yaml .load (content , ioc . misc . OrderedDictYAMLLoader )
46
43
except yaml .scanner .ScannerError as e :
47
44
raise ioc .exceptions .LoadingError ("file %s, \n error: %s" % (file , e ))
48
45
@@ -109,23 +106,23 @@ def load(self, file: str, container_builder: ContainerBuilder) -> None:
109
106
container_builder .add (id , definition )
110
107
111
108
def set_reference (self , value : Any ) -> Any :
112
- if misc .is_scalar (value ) and value [0 :1 ] == '@' :
109
+ if ioc . misc .is_string (value ) and value [0 :1 ] == '@' :
113
110
if '#' in value :
114
111
id , method = value .split ("#" )
115
112
return Reference (id [1 :], method )
116
113
117
114
return Reference (value [1 :])
118
115
119
- if misc .is_scalar (value ) and value [0 :2 ] == '#@' :
116
+ if ioc . misc .is_string (value ) and value [0 :2 ] == '#@' :
120
117
return WeakReference (value [2 :])
121
118
122
- if misc .is_iterable (value ):
119
+ if ioc . misc .is_iterable (value ):
123
120
return self .set_references (value )
124
121
125
122
return value
126
123
127
124
def set_references (self , arguments : Union [list [Any ], dict [str , Any ]]) -> Union [list [Any ], dict [str , Any ]]:
128
- for pos in misc .get_keys (arguments ):
125
+ for pos in ioc . misc .get_keys (arguments ):
129
126
arguments [pos ] = self .set_reference (arguments [pos ])
130
127
131
128
return arguments
0 commit comments