@@ -97,6 +97,24 @@ def find_class_in_module(module_name, class_name):
9797 return None
9898
9999
100+ def search_class_in_module_from_partial_name (module_name : str , class_partial_name : str ) -> Optional [List [type ]]:
101+ """
102+ Search a class in a module using a partial name.
103+ :param module_name: The name of the module to search in.
104+ :param class_partial_name: The partial name of the class to search for.
105+ :return: A list of classes that match the partial name.
106+
107+ """
108+ try :
109+ module = import_module (module_name )
110+ classes = get_module_classes_from_name (module_name )
111+ matching_classes = [cls for cls_name , cls in classes if class_partial_name .lower () in cls_name .lower ()]
112+ return matching_classes
113+ except ImportError as e :
114+ logging .error (f"Module '{ module_name } ' not found: { e } " )
115+ return None
116+
117+
100118def get_class_methods (cls : Union [type , Any ]) -> List [str ]:
101119 """
102120 Returns the list of the methods names for a specific class.
@@ -196,44 +214,32 @@ def get_energyml_class_in_related_dev_pkg(cls: type):
196214 return res
197215
198216
199- def get_class_from_qualified_type (qualified_type : str ) -> Optional [type ]:
200- return get_class_from_content_type (qualified_type )
201-
202-
203- def get_class_from_content_type (content_type : str ) -> Optional [type ]:
217+ def get_module_name_and_type_from_content_or_qualified_type (cqt : str ) -> Tuple [str , str ]:
204218 """
205- Return a :class:`type` object matching with the content-type :param:`content_type`.
206- :param content_type:
207- :return:
219+ Return a tuple (module_name, type) from a content-type or qualified-type string.
208220 """
209221 ct = None
210222 try :
211- ct = parse_content_type (content_type )
223+ ct = parse_content_type (cqt )
212224 except AttributeError :
213225 pass
214226 if ct is None :
215227 try :
216- ct = parse_qualified_type (content_type )
228+ ct = parse_qualified_type (cqt )
217229 except AttributeError :
218230 pass
219231
220232 domain = ct .group ("domain" )
221233 if domain is None :
222234 # logging.debug(f"\tdomain {domain} xmlDomain {ct.group('xmlDomain')} ")
223235 domain = "opc"
236+
224237 if domain == "opc" :
225238 xml_domain = ct .group ("xmlDomain" )
226239 if "." in xml_domain :
227240 xml_domain = xml_domain [xml_domain .rindex ("." ) + 1 :]
228- # Don't know what to do with http://schemas.f2i-consulting.com/package/2014/metadata/extended-core-properties
229- # if "extended" in xml_domain:
230- # xml_domain = xml_domain.replace("extended", "")
231- # if xml_domain.startswith("-"):
232- # xml_domain = xml_domain[1:]
233- #
234241 opc_type = pascal_case (xml_domain ).replace ("-" , "" )
235- # logging.debug("\tenergyml.opc.opc." + opc_type)
236- return get_class_from_name ("energyml.opc.opc." + opc_type )
242+ return ("energyml.opc.opc" , opc_type )
237243 else :
238244 domain = ct .group ("domain" )
239245 obj_type = ct .group ("type" )
@@ -246,10 +252,21 @@ def get_class_from_content_type(content_type: str) -> Optional[type]:
246252 if domain .lower () == "resqml" and version_num .startswith ("2_0" ):
247253 version_num = "2_0_1"
248254
249- # logging.debug(get_module_name(domain, version_num)
250- # + "."
251- # + obj_type)
252- return get_class_from_name (get_module_name (domain , version_num ) + "." + obj_type )
255+ return (get_module_name (domain , version_num ), obj_type )
256+
257+
258+ def get_class_from_qualified_type (qualified_type : str ) -> Optional [type ]:
259+ return get_class_from_content_type (qualified_type )
260+
261+
262+ def get_class_from_content_type (content_type : str ) -> Optional [type ]:
263+ """
264+ Return a :class:`type` object matching with the content-type :param:`content_type`.
265+ :param content_type:
266+ :return:
267+ """
268+ module_name , object_type = get_module_name_and_type_from_content_or_qualified_type (content_type )
269+ return get_class_from_name (module_name + "." + object_type )
253270
254271
255272def get_module_name (domain : str , domain_version : str ):
@@ -1078,7 +1095,7 @@ def get_obj_pkg_pkgv_type_uuid_version(
10781095
10791096 if ct is not None :
10801097 ct_match = parse_content_type (ct )
1081- logging .debug ("ct : " , ct_match )
1098+ logging .debug ("ct : %S " , ct_match )
10821099 if ct_match is not None :
10831100 pkg = ct_match .group ("domain" )
10841101 pkg_v = ct_match .group ("domainVersion" )
@@ -1087,7 +1104,7 @@ def get_obj_pkg_pkgv_type_uuid_version(
10871104 try :
10881105 qt = get_object_attribute_no_verif (obj , "qualified_type" )
10891106 qt_match = parse_qualified_type (qt )
1090- logging .debug ("qt : " , qt , obj .__dict__ , qt_match )
1107+ logging .debug ("qt : %s %s " , qt , obj .__dict__ , qt_match )
10911108 if qt_match is not None :
10921109 pkg = qt_match .group ("domain" )
10931110 pkg_v = qt_match .group ("domainVersion" )
@@ -1392,11 +1409,14 @@ def random_value_from_class(cls: type):
13921409 if not is_primitive (cls ):
13931410 # import_related_module(cls.__module__)
13941411 energyml_module_context = get_related_energyml_modules_name (cls )
1395- return _random_value_from_class (
1396- cls = cls ,
1397- energyml_module_context = energyml_module_context ,
1398- attribute_name = None ,
1399- )
1412+ if cls is not None :
1413+ return _random_value_from_class (
1414+ cls = cls ,
1415+ energyml_module_context = energyml_module_context ,
1416+ attribute_name = None ,
1417+ )
1418+ else :
1419+ return None
14001420
14011421
14021422def _random_value_from_class (
0 commit comments