2023-01-25 19:13:00 -05:00
|
|
|
"""
|
|
|
|
Constant module
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2023 Concordia CERC group
|
|
|
|
Project Coder Peter Yefi peteryefi@gmail.com
|
|
|
|
"""
|
2023-05-19 16:01:06 -04:00
|
|
|
import logging
|
2023-01-25 19:13:00 -05:00
|
|
|
|
|
|
|
|
2023-05-19 16:01:06 -04:00
|
|
|
def validate_import_export_type(cls_name: type, handler: str):
|
2023-01-25 19:13:00 -05:00
|
|
|
"""
|
|
|
|
Retrieves all the function names in a class which are property types (decoration)
|
|
|
|
and normal functions
|
|
|
|
:param cls_name: the class name
|
2023-05-19 16:01:06 -04:00
|
|
|
:param handler: import export handler
|
|
|
|
:return: None
|
2023-01-25 19:13:00 -05:00
|
|
|
"""
|
2023-08-08 12:39:37 -04:00
|
|
|
functions = [
|
|
|
|
function[1:] for function in dir(cls_name)
|
|
|
|
if (
|
|
|
|
isinstance(getattr(cls_name, function), property) or callable(getattr(cls_name, function))
|
|
|
|
) and function in cls_name.__dict__ and function[0] == '_' and function != '__init__']
|
2023-05-31 13:53:22 -04:00
|
|
|
|
2023-05-19 16:01:06 -04:00
|
|
|
if handler.lower() not in functions:
|
2023-05-31 13:51:35 -04:00
|
|
|
error_message = f'Wrong import type [{handler}]. Valid functions include {functions}'
|
|
|
|
logging.error(error_message)
|
|
|
|
raise ValueError(error_message)
|