holado 0.13.22__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- holado/__init__.py +358 -0
- holado/common/__init__.py +25 -0
- holado/common/context/__init__.py +25 -0
- holado/common/context/context.py +248 -0
- holado/common/context/service_manager.py +262 -0
- holado/common/context/session_context.py +516 -0
- holado/common/handlers/__init__.py +19 -0
- holado/common/handlers/enums.py +41 -0
- holado/common/handlers/object.py +175 -0
- holado/common/handlers/undefined.py +55 -0
- holado/common/tools/__init__.py +19 -0
- holado/common/tools/gc_manager.py +155 -0
- holado/holado_config.py +45 -0
- holado-0.13.22.dist-info/METADATA +194 -0
- holado-0.13.22.dist-info/RECORD +698 -0
- holado-0.13.22.dist-info/WHEEL +4 -0
- holado-0.13.22.dist-info/licenses/LICENSE +21 -0
- holado_ais/__init__.py +33 -0
- holado_ais/ais/MaritimeIdentificationDigits.csv +295 -0
- holado_ais/ais/ais_manager.py +151 -0
- holado_ais/ais/ais_messages.py +356 -0
- holado_ais/ais/ais_payload.py +35 -0
- holado_ais/ais/enums.py +37 -0
- holado_ais/ais/patch_pyais.py +1174 -0
- holado_ais/tests/behave/steps/__init__.py +17 -0
- holado_ais/tests/behave/steps/ais/__init__.py +0 -0
- holado_ais/tests/behave/steps/ais/ais_manager_steps.py +50 -0
- holado_ais/tests/behave/steps/ais/ais_messages_steps.py +237 -0
- holado_binary/__init__.py +17 -0
- holado_binary/ipc/binary.py +125 -0
- holado_binary/ipc/bit_series.py +307 -0
- holado_binary/tests/behave/steps/__init__.py +17 -0
- holado_binary/tests/behave/steps/ipc/binary_steps.py +57 -0
- holado_binary/tests/behave/steps/ipc/bit_series_steps.py +132 -0
- holado_context/__init__.py +16 -0
- holado_context/tests/behave/steps/__init__.py +16 -0
- holado_context/tests/behave/steps/private/__init__.py +16 -0
- holado_context/tests/behave/steps/private/common/context_steps.py +68 -0
- holado_core/__init__.py +32 -0
- holado_core/common/__init__.py +0 -0
- holado_core/common/actors/actions.py +97 -0
- holado_core/common/actors/actor.py +226 -0
- holado_core/common/actors/element_actor.py +32 -0
- holado_core/common/actors/find_actor.py +106 -0
- holado_core/common/actors/tree_actor.py +32 -0
- holado_core/common/actors/verify_actions.py +69 -0
- holado_core/common/block/base.py +122 -0
- holado_core/common/block/block_manager.py +173 -0
- holado_core/common/block/block_method.py +46 -0
- holado_core/common/block/block_steps.py +37 -0
- holado_core/common/block/function.py +42 -0
- holado_core/common/block/scope_function.py +28 -0
- holado_core/common/block/scope_manager.py +238 -0
- holado_core/common/block/scope_steps.py +141 -0
- holado_core/common/criterias/and_criteria.py +61 -0
- holado_core/common/criterias/criteria.py +78 -0
- holado_core/common/criterias/or_criteria.py +64 -0
- holado_core/common/criterias/tools/criteria_context.py +20 -0
- holado_core/common/criterias/tools/criteria_parameters.py +18 -0
- holado_core/common/drivers/driver.py +153 -0
- holado_core/common/drivers/element_driver.py +30 -0
- holado_core/common/drivers/element_internal_api.py +239 -0
- holado_core/common/drivers/internal_api.py +40 -0
- holado_core/common/drivers/tree_driver.py +30 -0
- holado_core/common/drivers/tree_internal_api.py +176 -0
- holado_core/common/exceptions/__init__.py +0 -0
- holado_core/common/exceptions/element_exception.py +28 -0
- holado_core/common/exceptions/exceptions.py +24 -0
- holado_core/common/exceptions/functional_exception.py +21 -0
- holado_core/common/exceptions/holado_exception.py +25 -0
- holado_core/common/exceptions/technical_exception.py +27 -0
- holado_core/common/exceptions/timeout_exception.py +20 -0
- holado_core/common/exceptions/verify_exception.py +20 -0
- holado_core/common/finders/after_in_tree_finder.py +87 -0
- holado_core/common/finders/element_finder.py +60 -0
- holado_core/common/finders/else_finder.py +105 -0
- holado_core/common/finders/finder.py +478 -0
- holado_core/common/finders/or_finder.py +98 -0
- holado_core/common/finders/then_finder.py +157 -0
- holado_core/common/finders/tools/enums.py +30 -0
- holado_core/common/finders/tools/find_builder.py +118 -0
- holado_core/common/finders/tools/find_context.py +405 -0
- holado_core/common/finders/tools/find_info.py +27 -0
- holado_core/common/finders/tools/find_parameters.py +240 -0
- holado_core/common/finders/tools/find_updater.py +95 -0
- holado_core/common/finders/tools/finder_info.py +26 -0
- holado_core/common/finders/tree_finder.py +146 -0
- holado_core/common/handlers/__init__.py +0 -0
- holado_core/common/handlers/abstracts/base_redo.py +702 -0
- holado_core/common/handlers/abstracts/get_or_create.py +120 -0
- holado_core/common/handlers/element_holder.py +122 -0
- holado_core/common/handlers/enums.py +23 -0
- holado_core/common/handlers/exceptions/redo_exceptions.py +28 -0
- holado_core/common/handlers/features/resource_by_name.py +187 -0
- holado_core/common/handlers/features/resource_by_type.py +174 -0
- holado_core/common/handlers/redo.py +119 -0
- holado_core/common/handlers/wait.py +127 -0
- holado_core/common/inspectors/element_inspector.py +57 -0
- holado_core/common/inspectors/inspector.py +221 -0
- holado_core/common/inspectors/tools/inspect_builder.py +169 -0
- holado_core/common/inspectors/tools/inspect_context.py +69 -0
- holado_core/common/inspectors/tools/inspect_parameters.py +181 -0
- holado_core/common/inspectors/tree_inspector.py +73 -0
- holado_core/common/resource/persisted_data_manager.py +113 -0
- holado_core/common/resource/persisted_method_to_call_manager.py +263 -0
- holado_core/common/resource/resource_manager.py +126 -0
- holado_core/common/resource/table_data_manager.py +110 -0
- holado_core/common/tables/__init__.py +1 -0
- holado_core/common/tables/comparators/__init__.py +0 -0
- holado_core/common/tables/comparators/boolean_table_cell_comparator.py +25 -0
- holado_core/common/tables/comparators/bytes_table_cell_comparator.py +25 -0
- holado_core/common/tables/comparators/datetime_table_cell_comparator.py +24 -0
- holado_core/common/tables/comparators/float_table_cell_comparator.py +31 -0
- holado_core/common/tables/comparators/integer_table_cell_comparator.py +25 -0
- holado_core/common/tables/comparators/internal_table_cell_comparator.py +30 -0
- holado_core/common/tables/comparators/string_table_cell_comparator.py +24 -0
- holado_core/common/tables/comparators/string_table_comparator.py +29 -0
- holado_core/common/tables/comparators/string_table_row_comparator.py +29 -0
- holado_core/common/tables/comparators/table_cell_comparator.py +40 -0
- holado_core/common/tables/comparators/table_comparator.py +209 -0
- holado_core/common/tables/comparators/table_comparator_manager.py +60 -0
- holado_core/common/tables/comparators/table_row_comparator.py +116 -0
- holado_core/common/tables/comparators/table_with_header_comparator.py +68 -0
- holado_core/common/tables/converters/__init__.py +0 -0
- holado_core/common/tables/converters/table_converter.py +233 -0
- holado_core/common/tables/enums.py +23 -0
- holado_core/common/tables/table.py +261 -0
- holado_core/common/tables/table_cell.py +126 -0
- holado_core/common/tables/table_manager.py +365 -0
- holado_core/common/tables/table_row.py +169 -0
- holado_core/common/tables/table_with_header.py +242 -0
- holado_core/common/tools/__init__.py +0 -0
- holado_core/common/tools/comparators/comparator.py +151 -0
- holado_core/common/tools/comparators/object_comparator.py +21 -0
- holado_core/common/tools/converters/converter.py +118 -0
- holado_core/common/tools/path_manager.py +238 -0
- holado_core/common/tools/string_tools.py +144 -0
- holado_core/common/tools/tools.py +197 -0
- holado_core/tests/behave/steps/__init__.py +20 -0
- holado_core/tests/behave/steps/common/__init__.py +0 -0
- holado_core/tests/behave/steps/common/common_steps.py +137 -0
- holado_core/tests/behave/steps/common/config_steps.py +42 -0
- holado_core/tests/behave/steps/common/resource_steps.py +62 -0
- holado_core/tests/behave/steps/common/tables_steps.py +560 -0
- holado_core/tools/__init__.py +0 -0
- holado_core/tools/abstracts/__init__.py +0 -0
- holado_core/tools/abstracts/blocking_command_service.py +64 -0
- holado_core/tools/abstracts/service.py +48 -0
- holado_crypto/__init__.py +31 -0
- holado_crypto/crypto/crypto.py +108 -0
- holado_crypto/crypto/key.py +92 -0
- holado_crypto/crypto/tcpbin.py +105 -0
- holado_crypto/crypto/transport/__init__.py +0 -0
- holado_crypto/crypto/transport/crc.py +40 -0
- holado_crypto/tests/behave/steps/__init__.py +18 -0
- holado_crypto/tests/behave/steps/crypto_steps.py +112 -0
- holado_crypto/tests/behave/steps/key_steps.py +82 -0
- holado_crypto/tests/behave/steps/tcpbin_steps.py +79 -0
- holado_data/__init__.py +31 -0
- holado_data/data/generator/base.py +93 -0
- holado_data/data/generator/generator_manager.py +27 -0
- holado_data/data/generator/python_generator.py +30 -0
- holado_data/tests/behave/steps/__init__.py +17 -0
- holado_data/tests/behave/steps/data/generator_steps.py +91 -0
- holado_data/tests/behave/steps/tools/utils_steps.py +59 -0
- holado_db/__init__.py +32 -0
- holado_db/tests/behave/steps/__init__.py +18 -0
- holado_db/tests/behave/steps/tools/db/db_client_steps.py +134 -0
- holado_db/tests/behave/steps/tools/db/postgresql_client_steps.py +59 -0
- holado_db/tests/behave/steps/tools/db/sqlite_client_steps.py +57 -0
- holado_db/tools/db/clients/base/db_audit.py +94 -0
- holado_db/tools/db/clients/base/db_client.py +344 -0
- holado_db/tools/db/clients/postgresql/postgresql_audit.py +75 -0
- holado_db/tools/db/clients/postgresql/postgresql_client.py +84 -0
- holado_db/tools/db/clients/sqlite/sqlite_audit.py +70 -0
- holado_db/tools/db/clients/sqlite/sqlite_client.py +60 -0
- holado_db/tools/db/db_manager.py +109 -0
- holado_db/tools/db/query/base/query_builder.py +138 -0
- holado_db/tools/db/query/pypika/pypika_query_builder.py +244 -0
- holado_db/tools/db/query/query_manager.py +77 -0
- holado_django/__init__.py +31 -0
- holado_django/server/HOWTO.txt +27 -0
- holado_django/server/django_projects/rest_api/db.sqlite3 +0 -0
- holado_django/server/django_projects/rest_api/manage.py +22 -0
- holado_django/server/django_projects/rest_api/rest_api/__init__.py +0 -0
- holado_django/server/django_projects/rest_api/rest_api/application/__init__.py +0 -0
- holado_django/server/django_projects/rest_api/rest_api/application/admin.py +3 -0
- holado_django/server/django_projects/rest_api/rest_api/application/apps.py +9 -0
- holado_django/server/django_projects/rest_api/rest_api/application/migrations/__init__.py +0 -0
- holado_django/server/django_projects/rest_api/rest_api/application/models.py +3 -0
- holado_django/server/django_projects/rest_api/rest_api/application/tests.py +3 -0
- holado_django/server/django_projects/rest_api/rest_api/application/views.py +6 -0
- holado_django/server/django_projects/rest_api/rest_api/asgi.py +16 -0
- holado_django/server/django_projects/rest_api/rest_api/settings.py +130 -0
- holado_django/server/django_projects/rest_api/rest_api/urls.py +35 -0
- holado_django/server/django_projects/rest_api/rest_api/wsgi.py +16 -0
- holado_django/server/django_server.py +110 -0
- holado_django/server/grpc_django_server.py +57 -0
- holado_django/server/patch_djangogrpcframework.py +46 -0
- holado_django/tests/behave/steps/__init__.py +16 -0
- holado_django/tests/behave/steps/django_server_steps.py +83 -0
- holado_docker/__init__.py +25 -0
- holado_docker/sdk/docker/container_logs.py +447 -0
- holado_docker/sdk/docker/docker_client.py +537 -0
- holado_docker/sdk/docker/docker_service.py +71 -0
- holado_docker/tests/behave/steps/__init__.py +16 -0
- holado_docker/tests/behave/steps/sdk/docker/container_logs_steps.py +47 -0
- holado_examples/projects/server_rest/server_rest_example/initialize_holado.py +72 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/db.sqlite3 +0 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/manage.py +22 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/__init__.py +0 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/application/__init__.py +0 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/application/admin.py +3 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/application/apps.py +7 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/application/migrations/__init__.py +0 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/application/models.py +3 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/application/serializers.py +15 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/application/tests.py +3 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/application/views.py +24 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/asgi.py +16 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/settings.py +130 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/urls.py +31 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/wsgi.py +16 -0
- holado_examples/projects/server_rest/server_rest_example/rest_server.py +37 -0
- holado_examples/scripts/script_custom_initialization.py +16 -0
- holado_examples/scripts/script_minimal_initialization.py +23 -0
- holado_examples/tests/behave/testing_solution/__main__.py +13 -0
- holado_examples/tests/behave/testing_solution/behave_environment.py +35 -0
- holado_examples/tests/behave/testing_solution/environment.py +36 -0
- holado_examples/tests/behave/testing_solution/features/Configuration/Actions/configure_system.feature +10 -0
- holado_examples/tests/behave/testing_solution/features/NonReg/example.feature +26 -0
- holado_examples/tests/behave/testing_solution/initialize_holado.py +62 -0
- holado_examples/tests/behave/testing_solution/logging.conf +102 -0
- holado_examples/tests/behave/testing_solution/requirements.txt +5 -0
- holado_examples/tests/behave/testing_solution/run_test.sh +7 -0
- holado_examples/tests/behave/testing_solution/run_test_nonreg.sh +6 -0
- holado_examples/tests/behave/testing_solution/src/common/tools/path_manager.py +40 -0
- holado_examples/tests/behave/testing_solution/src/config/config_manager.py +30 -0
- holado_examples/tests/behave/testing_solution/src/context/session_context.py +45 -0
- holado_examples/tests/behave/testing_solution/steps/config_steps.py +21 -0
- holado_examples/tests/behave/testing_solution/steps/public_steps.py +10 -0
- holado_grpc/TODO +8 -0
- holado_grpc/__init__.py +40 -0
- holado_grpc/api/rpc/TODO.txt +4 -0
- holado_grpc/api/rpc/grpc_client.py +210 -0
- holado_grpc/api/rpc/grpc_manager.py +81 -0
- holado_grpc/ipc/rpc/__init__.py +0 -0
- holado_grpc/ipc/rpc/grpc_compiler.py +45 -0
- holado_grpc/ipc/rpc/grpc_services.py +165 -0
- holado_grpc/tests/behave/steps/__init__.py +16 -0
- holado_grpc/tests/behave/steps/api/grpc_client_steps.py +173 -0
- holado_grpc/tests/behave/steps/private/__init__.py +16 -0
- holado_grpc/tests/behave/steps/private/api/grpc_steps.py +77 -0
- holado_helper/__init__.py +35 -0
- holado_helper/debug/README.txt +32 -0
- holado_helper/debug/memory/memory_profiler.py +106 -0
- holado_helper/docker/init_user.sh +24 -0
- holado_helper/docker/logging.conf +44 -0
- holado_helper/docker/run_holado_test_nonreg_in_docker.sh +120 -0
- holado_helper/docker/run_terminal_in_docker.sh +101 -0
- holado_helper/holado_module_template/__init__.py +38 -0
- holado_helper/holado_module_template/tests/behave/steps/__init__.py +16 -0
- holado_helper/holado_module_template/tests/behave/steps/private/__init__.py +16 -0
- holado_helper/initialize_holado.py +72 -0
- holado_helper/script/action.py +130 -0
- holado_helper/script/action_script.py +477 -0
- holado_helper/script/any_action_script.py +126 -0
- holado_helper/script/behave_action_script.py +99 -0
- holado_helper/script/csv_action_script.py +142 -0
- holado_helper/script/initialize_script.py +95 -0
- holado_helper/script/input_output_script.py +136 -0
- holado_helper/script/job.py +75 -0
- holado_helper/script/json_action_script.py +104 -0
- holado_helper/script/script.py +110 -0
- holado_json/__init__.py +16 -0
- holado_json/filesystem/json_file.py +94 -0
- holado_json/filesystem/stream_json_file.py +117 -0
- holado_json/ipc/json.py +146 -0
- holado_json/ipc/json_converter.py +69 -0
- holado_json/ipc/json_types.py +183 -0
- holado_json/tests/behave/steps/__init__.py +16 -0
- holado_json/tests/behave/steps/ipc/__init__.py +0 -0
- holado_json/tests/behave/steps/ipc/json_steps.py +131 -0
- holado_keycloak/__init__.py +16 -0
- holado_keycloak/tests/behave/steps/__init__.py +16 -0
- holado_keycloak/tests/behave/steps/tools/keycloak_client_steps.py +73 -0
- holado_keycloak/tools/keycloak/__init__.py +0 -0
- holado_keycloak/tools/keycloak/keycloak_client.py +90 -0
- holado_logging/__init__.py +38 -0
- holado_logging/common/logging/holado_logger.py +71 -0
- holado_logging/common/logging/log_config.py +163 -0
- holado_logging/common/logging/log_manager.py +335 -0
- holado_multitask/__init__.py +33 -0
- holado_multitask/multiprocessing/context/process_context.py +35 -0
- holado_multitask/multiprocessing/function_process.py +102 -0
- holado_multitask/multiprocessing/periodic_function_process.py +137 -0
- holado_multitask/multiprocessing/process.py +213 -0
- holado_multitask/multiprocessing/processesmanager.py +137 -0
- holado_multitask/multitasking/multitask_manager.py +464 -0
- holado_multitask/multithreading/__init__.py +0 -0
- holado_multitask/multithreading/context/thread_context.py +86 -0
- holado_multitask/multithreading/functionthreaded.py +129 -0
- holado_multitask/multithreading/loopfunctionthreaded.py +45 -0
- holado_multitask/multithreading/loopthread.py +110 -0
- holado_multitask/multithreading/periodicfunctionthreaded.py +135 -0
- holado_multitask/multithreading/reflection/inspect.py +47 -0
- holado_multitask/multithreading/reflection/sys.py +29 -0
- holado_multitask/multithreading/reflection/traceback.py +35 -0
- holado_multitask/multithreading/thread.py +203 -0
- holado_multitask/multithreading/threadsmanager.py +167 -0
- holado_multitask/multithreading/timer.py +51 -0
- holado_multitask/tests/behave/steps/__init__.py +17 -0
- holado_multitask/tests/behave/steps/multiprocessing_steps.py +138 -0
- holado_multitask/tests/behave/steps/multithreading_steps.py +129 -0
- holado_protobuf/__init__.py +61 -0
- holado_protobuf/ipc/protobuf/__init__.py +0 -0
- holado_protobuf/ipc/protobuf/abstracts/type.py +45 -0
- holado_protobuf/ipc/protobuf/protobuf_compiler.py +118 -0
- holado_protobuf/ipc/protobuf/protobuf_converter.py +153 -0
- holado_protobuf/ipc/protobuf/protobuf_messages.py +968 -0
- holado_protobuf/ipc/protobuf/protobuf_modifier.py +65 -0
- holado_protobuf/ipc/protobuf/types/__init__.py +0 -0
- holado_protobuf/ipc/protobuf/types/google/__init__.py +0 -0
- holado_protobuf/ipc/protobuf/types/google/protobuf.py +124 -0
- holado_protobuf/tests/behave/steps/__init__.py +16 -0
- holado_protobuf/tests/behave/steps/ipc/protobuf_steps.py +297 -0
- holado_python/__init__.py +36 -0
- holado_python/common/enums.py +34 -0
- holado_python/common/iterables.py +38 -0
- holado_python/common/tools/comparators/boolean_comparator.py +37 -0
- holado_python/common/tools/comparators/bytes_comparator.py +48 -0
- holado_python/common/tools/comparators/datetime_comparator.py +74 -0
- holado_python/common/tools/comparators/float_comparator.py +97 -0
- holado_python/common/tools/comparators/integer_comparator.py +37 -0
- holado_python/common/tools/comparators/string_comparator.py +99 -0
- holado_python/common/tools/comparators/type_comparator.py +31 -0
- holado_python/common/tools/datetime.py +341 -0
- holado_python/standard_library/csv.py +207 -0
- holado_python/standard_library/hashlib.py +110 -0
- holado_python/standard_library/multiprocessing.py +62 -0
- holado_python/standard_library/queue.py +79 -0
- holado_python/standard_library/socket/blocking_socket.py +219 -0
- holado_python/standard_library/socket/echo_server.py +29 -0
- holado_python/standard_library/socket/message_socket.py +152 -0
- holado_python/standard_library/socket/non_blocking_socket.py +172 -0
- holado_python/standard_library/socket/socket.py +411 -0
- holado_python/standard_library/ssl/resources/certificates/NOTES.txt +5 -0
- holado_python/standard_library/ssl/resources/certificates/localhost.crt +19 -0
- holado_python/standard_library/ssl/resources/certificates/localhost.key +28 -0
- holado_python/standard_library/ssl/ssl.py +131 -0
- holado_python/standard_library/typing.py +192 -0
- holado_python/tests/behave/steps/__init__.py +27 -0
- holado_python/tests/behave/steps/builtins/str_steps.py +45 -0
- holado_python/tests/behave/steps/convert_steps.py +59 -0
- holado_python/tests/behave/steps/iterable_steps.py +87 -0
- holado_python/tests/behave/steps/standard_library/csv_steps.py +134 -0
- holado_python/tests/behave/steps/standard_library/datetime_steps.py +163 -0
- holado_python/tests/behave/steps/standard_library/hashlib_steps.py +57 -0
- holado_python/tests/behave/steps/standard_library/multiprocessing_steps.py +56 -0
- holado_python/tests/behave/steps/standard_library/queue_steps.py +358 -0
- holado_python/tests/behave/steps/standard_library/socket_steps.py +384 -0
- holado_python/tests/behave/steps/standard_library/ssl_steps.py +71 -0
- holado_rabbitmq/__init__.py +28 -0
- holado_rabbitmq/tests/behave/steps/__init__.py +17 -0
- holado_rabbitmq/tests/behave/steps/tools/rabbitmq_client_steps.py +565 -0
- holado_rabbitmq/tests/behave/steps/tools/rabbitmq_server_steps.py +64 -0
- holado_rabbitmq/tools/rabbitmq/rabbitmq_blocking_client.py +333 -0
- holado_rabbitmq/tools/rabbitmq/rabbitmq_client.py +678 -0
- holado_rabbitmq/tools/rabbitmq/rabbitmq_manager.py +146 -0
- holado_rabbitmq/tools/rabbitmq/rabbitmq_select_client.py +428 -0
- holado_rabbitmq/tools/rabbitmq/rabbitmq_server.py +24 -0
- holado_redis/__init__.py +17 -0
- holado_redis/tests/behave/steps/__init__.py +16 -0
- holado_redis/tests/behave/steps/tools/redis_client_steps.py +101 -0
- holado_redis/tools/redis/TODO.txt +7 -0
- holado_redis/tools/redis/redis_client.py +190 -0
- holado_redis/tools/redis/redis_manager.py +38 -0
- holado_report/__init__.py +36 -0
- holado_report/campaign/campaign_manager.py +348 -0
- holado_report/report/analyze/execution_historic_manager.py +96 -0
- holado_report/report/analyze/scenario_duration_manager.py +245 -0
- holado_report/report/builders/detailed_scenario_report_builder.py +172 -0
- holado_report/report/builders/execution_historic_report_builder.py +132 -0
- holado_report/report/builders/failure_report_builder.py +150 -0
- holado_report/report/builders/report_builder.py +64 -0
- holado_report/report/builders/short_scenario_report_builder.py +94 -0
- holado_report/report/builders/summary_by_category_report_builder.py +103 -0
- holado_report/report/builders/summary_report_builder.py +110 -0
- holado_report/report/builders/summary_scenario_by_category_report_builder.py +109 -0
- holado_report/report/builders/summary_scenario_report_builder.py +81 -0
- holado_report/report/execution_historic.py +144 -0
- holado_report/report/report_manager.py +424 -0
- holado_report/report/reports/base_report.py +163 -0
- holado_report/report/reports/feature_report.py +106 -0
- holado_report/report/reports/scenario_report.py +64 -0
- holado_rest/__init__.py +32 -0
- holado_rest/api/rest/TODO.txt +2 -0
- holado_rest/api/rest/rest_client.py +200 -0
- holado_rest/api/rest/rest_manager.py +72 -0
- holado_rest/tests/behave/steps/__init__.py +16 -0
- holado_rest/tests/behave/steps/api/__init__.py +0 -0
- holado_rest/tests/behave/steps/api/rest_client_steps.py +181 -0
- holado_rest/tests/behave/steps/private/__init__.py +16 -0
- holado_rest/tests/behave/steps/private/api/__init__.py +0 -0
- holado_rest/tests/behave/steps/private/api/rest_steps.py +75 -0
- holado_s3/__init__.py +17 -0
- holado_s3/tests/behave/steps/__init__.py +17 -0
- holado_s3/tests/behave/steps/private/__init__.py +16 -0
- holado_s3/tests/behave/steps/private/tools/s3_steps.py +89 -0
- holado_s3/tests/behave/steps/tools/s3_client_steps.py +403 -0
- holado_s3/tests/behave/steps/tools/s3_server_steps.py +57 -0
- holado_s3/tools/s3/__init__.py +0 -0
- holado_s3/tools/s3/boto3_s3_client.py +59 -0
- holado_s3/tools/s3/minio_client.py +75 -0
- holado_s3/tools/s3/moto_server.py +52 -0
- holado_scripting/__init__.py +54 -0
- holado_scripting/common/tools/dynamic_text_manager.py +73 -0
- holado_scripting/common/tools/evaluate_parameters.py +228 -0
- holado_scripting/common/tools/expression_evaluator.py +389 -0
- holado_scripting/common/tools/variable_manager.py +354 -0
- holado_scripting/tests/behave/steps/__init__.py +22 -0
- holado_scripting/tests/behave/steps/common/tools/variable_convert_steps.py +159 -0
- holado_scripting/tests/behave/steps/common/tools/variable_new_steps.py +130 -0
- holado_scripting/tests/behave/steps/common/tools/variable_steps.py +108 -0
- holado_scripting/tests/behave/steps/common/tools/variable_verify_steps.py +160 -0
- holado_scripting/tests/behave/steps/scenario/function_steps.py +77 -0
- holado_scripting/tests/behave/steps/scenario/if_steps.py +87 -0
- holado_scripting/tests/behave/steps/scenario/loop_steps.py +119 -0
- holado_scripting/text/base/base_function.py +25 -0
- holado_scripting/text/base/base_verify_function.py +25 -0
- holado_scripting/text/base/text_inspecter.py +204 -0
- holado_scripting/text/interpreter/exceptions/interpreter_exception.py +25 -0
- holado_scripting/text/interpreter/functions/function_apply_function.py +60 -0
- holado_scripting/text/interpreter/functions/function_cast.py +60 -0
- holado_scripting/text/interpreter/functions/function_convert.py +57 -0
- holado_scripting/text/interpreter/functions/function_dynamic_value.py +40 -0
- holado_scripting/text/interpreter/functions/function_escape_all_bytes.py +35 -0
- holado_scripting/text/interpreter/functions/function_exists_variable.py +39 -0
- holado_scripting/text/interpreter/functions/function_hex_to_bytes.py +49 -0
- holado_scripting/text/interpreter/functions/function_hex_to_int.py +53 -0
- holado_scripting/text/interpreter/functions/function_to_base_64.py +41 -0
- holado_scripting/text/interpreter/functions/function_to_bytes.py +50 -0
- holado_scripting/text/interpreter/functions/function_to_hex.py +42 -0
- holado_scripting/text/interpreter/functions/function_to_string.py +50 -0
- holado_scripting/text/interpreter/text_interpreter.py +219 -0
- holado_scripting/text/verifier/exceptions/verifier_exception.py +21 -0
- holado_scripting/text/verifier/functions/verify_function_extract_in.py +35 -0
- holado_scripting/text/verifier/functions/verify_function_match_pattern.py +63 -0
- holado_scripting/text/verifier/text_verifier.py +103 -0
- holado_sftp/__init__.py +16 -0
- holado_sftp/tests/behave/steps/__init__.py +17 -0
- holado_sftp/tests/behave/steps/private/__init__.py +16 -0
- holado_sftp/tests/behave/steps/private/tools/sftp_steps.py +78 -0
- holado_sftp/tests/behave/steps/tools/sftp_client_steps.py +94 -0
- holado_sftp/tests/behave/steps/tools/sftp_server_steps.py +82 -0
- holado_sftp/tools/sftp/__init__.py +0 -0
- holado_sftp/tools/sftp/sftp_client.py +103 -0
- holado_sftp/tools/sftp/sftp_server.py +39 -0
- holado_swagger/__init__.py +31 -0
- holado_swagger/swagger_hub/mockserver/mockserver_client.py +82 -0
- holado_swagger/swagger_hub/mockserver/mockserver_manager.py +33 -0
- holado_swagger/tests/behave/steps/__init__.py +16 -0
- holado_swagger/tests/behave/steps/swagger_hub/mockserver_steps.py +74 -0
- holado_system/system/command/command.py +247 -0
- holado_system/system/command/command_result.py +128 -0
- holado_system/system/command/curl_command.py +101 -0
- holado_system/system/command/exceptions.py +59 -0
- holado_system/system/filesystem/file.py +150 -0
- holado_system/system/global_system.py +187 -0
- holado_system/tests/behave/steps/__init__.py +18 -0
- holado_system/tests/behave/steps/system/commands_steps.py +92 -0
- holado_system/tests/behave/steps/system/file_steps.py +231 -0
- holado_system/tests/behave/steps/system/system_steps.py +84 -0
- holado_test/__init__.py +30 -0
- holado_test/behave/__init__.py +0 -0
- holado_test/behave/behave.py +400 -0
- holado_test/behave/behave_environment.py +169 -0
- holado_test/behave/behave_function.py +33 -0
- holado_test/behave/behave_manager.py +558 -0
- holado_test/behave/independant_runner.py +66 -0
- holado_test/behave/scenario/__init__.py +0 -0
- holado_test/behave/scenario/behave_step_tools.py +157 -0
- holado_test/common/context/feature_context.py +81 -0
- holado_test/common/context/scenario_context.py +169 -0
- holado_test/common/context/step_context.py +66 -0
- holado_test/common/exceptions/undefined_step_exception.py +21 -0
- holado_test/scenario/step_tools.py +547 -0
- holado_test/scenario/tester_tools.py +57 -0
- holado_test/test_config.py +26 -0
- holado_test/tests/behave/steps/__init__.py +18 -0
- holado_test/tests/behave/steps/scenario/exception_steps.py +87 -0
- holado_test/tests/behave/steps/scenario/scenario_steps.py +100 -0
- holado_test/tests/behave/steps/scenario/tester_steps.py +65 -0
- holado_test/tools/test_server/client/rest/test_server_client.py +150 -0
- holado_test/tools/test_server/server/Dockerfile +60 -0
- holado_test/tools/test_server/server/core/server_context.py +42 -0
- holado_test/tools/test_server/server/core/server_manager.py +41 -0
- holado_test/tools/test_server/server/requirements.txt +2 -0
- holado_test/tools/test_server/server/rest/README +2 -0
- holado_test/tools/test_server/server/rest/api/__init__.py +24 -0
- holado_test/tools/test_server/server/rest/api/campaign/__init__.py +32 -0
- holado_test/tools/test_server/server/rest/api/campaign/scenario.py +40 -0
- holado_test/tools/test_server/server/rest/initialize_holado.py +72 -0
- holado_test/tools/test_server/server/rest/logging.conf +51 -0
- holado_test/tools/test_server/server/rest/openapi.yaml +57 -0
- holado_test/tools/test_server/server/rest/run.py +41 -0
- holado_test/tools/test_server/server/run.sh +6 -0
- holado_test/tools/test_server/server/run_test_server_in_docker.sh +104 -0
- holado_tools/__init__.py +38 -0
- holado_tools/scripts/execute_persisted_post_processes/execute_persisted_post_processes.py +36 -0
- holado_tools/scripts/execute_persisted_post_processes/execute_persisted_post_processes.sh +6 -0
- holado_tools/scripts/execute_persisted_post_processes/initialize_holado.py +62 -0
- holado_tools/tests/behave/steps/__init__.py +16 -0
- holado_tools/tests/behave/steps/tools/host_controller/client_steps.py +97 -0
- holado_tools/tools/host_controller/client/rest/host_controller_client.py +275 -0
- holado_tools/tools/host_controller/server/Dockerfile +60 -0
- holado_tools/tools/host_controller/server/requirements.txt +2 -0
- holado_tools/tools/host_controller/server/rest/README +2 -0
- holado_tools/tools/host_controller/server/rest/api/__init__.py +24 -0
- holado_tools/tools/host_controller/server/rest/api/config.py +88 -0
- holado_tools/tools/host_controller/server/rest/api/docker/__init__.py +66 -0
- holado_tools/tools/host_controller/server/rest/api/docker/container.py +144 -0
- holado_tools/tools/host_controller/server/rest/api/docker/logs.py +66 -0
- holado_tools/tools/host_controller/server/rest/api/os.py +58 -0
- holado_tools/tools/host_controller/server/rest/initialize_holado.py +72 -0
- holado_tools/tools/host_controller/server/rest/openapi.yaml +561 -0
- holado_tools/tools/host_controller/server/rest/run.py +31 -0
- holado_tools/tools/host_controller/server/run_host_controller_in_docker.sh +107 -0
- holado_tools/tools/host_viewer/client/rest/host_viewer_client.py +190 -0
- holado_tools/tools/host_viewer/server/Dockerfile +60 -0
- holado_tools/tools/host_viewer/server/requirements.txt +2 -0
- holado_tools/tools/host_viewer/server/rest/README +2 -0
- holado_tools/tools/host_viewer/server/rest/api/__init__.py +24 -0
- holado_tools/tools/host_viewer/server/rest/api/docker/__init__.py +65 -0
- holado_tools/tools/host_viewer/server/rest/api/docker/container.py +87 -0
- holado_tools/tools/host_viewer/server/rest/api/os.py +58 -0
- holado_tools/tools/host_viewer/server/rest/initialize_holado.py +72 -0
- holado_tools/tools/host_viewer/server/rest/openapi.yaml +301 -0
- holado_tools/tools/host_viewer/server/rest/run.py +31 -0
- holado_tools/tools/host_viewer/server/run_host_viewer_in_docker.sh +107 -0
- holado_value/__init__.py +24 -0
- holado_value/common/tables/comparators/table_2_value_table_cell_comparator.py +196 -0
- holado_value/common/tables/comparators/table_2_value_table_comparator.py +27 -0
- holado_value/common/tables/comparators/table_2_value_table_row_comparator.py +27 -0
- holado_value/common/tables/comparators/table_2_value_table_with_header_comparator.py +27 -0
- holado_value/common/tables/converters/value_table_converter.py +267 -0
- holado_value/common/tables/value_table.py +29 -0
- holado_value/common/tables/value_table_cell.py +76 -0
- holado_value/common/tables/value_table_manager.py +48 -0
- holado_value/common/tables/value_table_row.py +43 -0
- holado_value/common/tables/value_table_with_header.py +28 -0
- holado_value/common/tools/unique_value_manager.py +109 -0
- holado_value/common/tools/value.py +191 -0
- holado_value/common/tools/value_types.py +41 -0
- holado_value/tests/behave/steps/__init__.py +16 -0
- holado_value/tests/behave/steps/private/__init__.py +16 -0
- holado_ws/__init__.py +16 -0
- holado_ws/api/ws/TODO.txt +2 -0
- holado_ws/tests/behave/steps/__init__.py +16 -0
- holado_ws/tests/behave/steps/api/web_service_steps.py +189 -0
- holado_xml/__init__.py +38 -0
- holado_xml/tests/behave/steps/__init__.py +16 -0
- holado_xml/tests/behave/steps/private/__init__.py +16 -0
- holado_xml/xml/stream_xml_file.py +181 -0
- holado_xml/xml/xml_file.py +97 -0
- holado_xml/xml/xml_manager.py +35 -0
- holado_yaml/__init__.py +31 -0
- holado_yaml/tests/behave/steps/__init__.py +16 -0
- holado_yaml/tests/behave/steps/yaml_steps.py +161 -0
- holado_yaml/yaml/enums.py +28 -0
- holado_yaml/yaml/pyyaml/pyyaml_client.py +72 -0
- holado_yaml/yaml/ruamel/ruamel_yaml_client.py +80 -0
- holado_yaml/yaml/yaml_client.py +203 -0
- holado_yaml/yaml/yaml_manager.py +94 -0
- test_holado/Dockerfile_test_holado +82 -0
- test_holado/__init__.py +4 -0
- test_holado/__main__.py +25 -0
- test_holado/build_docker_image_to_test_holado_in_docker.sh +7 -0
- test_holado/environment.py +60 -0
- test_holado/features/Configuration/Actions/execute_persisted_post_processes.feature +13 -0
- test_holado/features/NonReg/api/REST.feature +26 -0
- test_holado/features/NonReg/api/gRPC.feature +116 -0
- test_holado/features/NonReg/common/multiprocessing/simple.feature +60 -0
- test_holado/features/NonReg/common/system/commands.feature +43 -0
- test_holado/features/NonReg/common/system/system.feature +20 -0
- test_holado/features/NonReg/common/tables/table.feature +245 -0
- test_holado/features/NonReg/common/tables/value_table_conversion.feature +29 -0
- test_holado/features/NonReg/common/tools/DateTime.feature +88 -0
- test_holado/features/NonReg/common/tools/UniqueValueManager.feature +43 -0
- test_holado/features/NonReg/holado_ais/ais_message-bitarray_to_nmea.feature +135 -0
- test_holado/features/NonReg/holado_ais/ais_message-nmea_raw_to_dict.feature +93 -0
- test_holado/features/NonReg/holado_ais/message_types/type-10.feature +38 -0
- test_holado/features/NonReg/holado_ais/message_types/type-12.feature +37 -0
- test_holado/features/NonReg/holado_ais/message_types/type-14.feature +36 -0
- test_holado/features/NonReg/holado_ais/message_types/type-15.feature +36 -0
- test_holado/features/NonReg/holado_ais/message_types/type-16.feature +38 -0
- test_holado/features/NonReg/holado_ais/message_types/type-17.feature +46 -0
- test_holado/features/NonReg/holado_ais/message_types/type-18.feature +37 -0
- test_holado/features/NonReg/holado_ais/message_types/type-19.feature +38 -0
- test_holado/features/NonReg/holado_ais/message_types/type-1_2_3.feature +42 -0
- test_holado/features/NonReg/holado_ais/message_types/type-20.feature +38 -0
- test_holado/features/NonReg/holado_ais/message_types/type-21.feature +37 -0
- test_holado/features/NonReg/holado_ais/message_types/type-22.feature +84 -0
- test_holado/features/NonReg/holado_ais/message_types/type-23.feature +49 -0
- test_holado/features/NonReg/holado_ais/message_types/type-24.feature +72 -0
- test_holado/features/NonReg/holado_ais/message_types/type-25.feature +143 -0
- test_holado/features/NonReg/holado_ais/message_types/type-26.feature +144 -0
- test_holado/features/NonReg/holado_ais/message_types/type-27.feature +36 -0
- test_holado/features/NonReg/holado_ais/message_types/type-4_11.feature +39 -0
- test_holado/features/NonReg/holado_ais/message_types/type-5.feature +33 -0
- test_holado/features/NonReg/holado_ais/message_types/type-6.feature +37 -0
- test_holado/features/NonReg/holado_ais/message_types/type-7_13.feature +43 -0
- test_holado/features/NonReg/holado_ais/message_types/type-8.feature +37 -0
- test_holado/features/NonReg/holado_ais/message_types/type-9.feature +37 -0
- test_holado/features/NonReg/holado_binary/bit_series.error.feature +33 -0
- test_holado/features/NonReg/holado_binary/bit_series.feature +144 -0
- test_holado/features/NonReg/holado_protobuf/protobuf.feature +291 -0
- test_holado/features/NonReg/holado_python/convert.feature +20 -0
- test_holado/features/NonReg/holado_python/iterable.feature +61 -0
- test_holado/features/NonReg/holado_python/standard_library/socket/local_echo_server/socket_reset.feature +191 -0
- test_holado/features/NonReg/holado_python/standard_library/socket/local_echo_server/socket_with_tls_and_verify.feature +279 -0
- test_holado/features/NonReg/holado_python/standard_library/socket/local_echo_server/socket_with_tls_without_verify.feature +299 -0
- test_holado/features/NonReg/holado_python/standard_library/socket/local_echo_server/socket_without_tls.feature +163 -0
- test_holado/features/NonReg/holado_python/standard_library/socket/tcpbin.com/socket_with_mtls.feature +214 -0
- test_holado/features/NonReg/holado_python/standard_library/socket/tcpbin.com/socket_with_tls.feature +184 -0
- test_holado/features/NonReg/holado_python/standard_library/socket/tcpbin.com/socket_without_tls.feature +169 -0
- test_holado/features/NonReg/holado_scripting/common/tools/dynamic_text_manager.feature +18 -0
- test_holado/features/NonReg/holado_scripting/common/tools/expression_evaluator.feature +185 -0
- test_holado/features/NonReg/holado_scripting/common/tools/variable_manager.feature +71 -0
- test_holado/features/NonReg/holado_scripting/text/interpreter/interpreter.error.feature +21 -0
- test_holado/features/NonReg/holado_scripting/text/interpreter/interpreter.feature +120 -0
- test_holado/features/NonReg/holado_yaml/yaml.feature +514 -0
- test_holado/features/NonReg/ipc/json.feature +20 -0
- test_holado/features/NonReg/scenario/scenario.feature +183 -0
- test_holado/features/NonReg/test_steps/behave.feature +275 -0
- test_holado/features/NonReg/test_steps/common.feature +100 -0
- test_holado/features/NonReg/tools/RabbitMQ.feature +445 -0
- test_holado/features/NonReg/tools/RabbitMQ_steps.feature +276 -0
- test_holado/features/NonReg/tools/S3/boto3_client.feature +73 -0
- test_holado/features/NonReg/tools/S3/minio_client.feature +75 -0
- test_holado/features/NonReg/tools/db_sqlite3.feature +41 -0
- test_holado/features/NonReg/tools/sFTP.feature +25 -0
- test_holado/features/Test/logger.feature +28 -0
- test_holado/features/Test/test_host_controller.feature +13 -0
- test_holado/features/Test/test_parameter.feature +15 -0
- test_holado/features/__init__.py +0 -0
- test_holado/initialize_holado.py +62 -0
- test_holado/logging.conf +53 -0
- test_holado/resources/proto/definitions/protobuf/custom_types/field_types.proto +24 -0
- test_holado/resources/proto/definitions/protobuf/protobuf.dev/tutorial/addressbook.proto +56 -0
- test_holado/resources/proto/generated/protobuf/custom_types/field_types_pb2.py +34 -0
- test_holado/resources/proto/generated/protobuf/protobuf/dev/tutorial/addressbook_pb2.py +34 -0
- test_holado/resources/scripts/list_tags.sh +2 -0
- test_holado/resources/scripts/update_resources_proto_generated.py +70 -0
- test_holado/steps/__init__.py +0 -0
- test_holado/steps/private_steps.py +20 -0
- test_holado/steps/public_steps.py +23 -0
- test_holado/test_holado_session_context.py +43 -0
- test_holado/tools/connexion/api_rest/openapi.yaml +16 -0
- test_holado/tools/connexion/api_rest/run.py +19 -0
- test_holado/tools/django/README.txt +3 -0
- test_holado/tools/django/api_grpc/api_grpc/__init__.py +0 -0
- test_holado/tools/django/api_grpc/api_grpc/api1/__init__.py +0 -0
- test_holado/tools/django/api_grpc/api_grpc/api1/admin.py +3 -0
- test_holado/tools/django/api_grpc/api_grpc/api1/apps.py +6 -0
- test_holado/tools/django/api_grpc/api_grpc/api1/migrations/__init__.py +0 -0
- test_holado/tools/django/api_grpc/api_grpc/api1/models.py +3 -0
- test_holado/tools/django/api_grpc/api_grpc/api1/proto/__init__.py +0 -0
- test_holado/tools/django/api_grpc/api_grpc/api1/proto/account.proto +27 -0
- test_holado/tools/django/api_grpc/api_grpc/api1/proto/account_pb2.py +33 -0
- test_holado/tools/django/api_grpc/api_grpc/api1/proto/account_pb2_grpc.py +199 -0
- test_holado/tools/django/api_grpc/api_grpc/api1/serializers.py +12 -0
- test_holado/tools/django/api_grpc/api_grpc/api1/services.py +11 -0
- test_holado/tools/django/api_grpc/api_grpc/api1/tests.py +3 -0
- test_holado/tools/django/api_grpc/api_grpc/api1/views.py +3 -0
- test_holado/tools/django/api_grpc/api_grpc/asgi.py +16 -0
- test_holado/tools/django/api_grpc/api_grpc/settings.py +126 -0
- test_holado/tools/django/api_grpc/api_grpc/urls.py +27 -0
- test_holado/tools/django/api_grpc/api_grpc/wsgi.py +16 -0
- test_holado/tools/django/api_grpc/db.sqlite3 +0 -0
- test_holado/tools/django/api_grpc/manage.py +29 -0
- test_holado/tools/django/api_grpc/manual_test_commands.txt +25 -0
- test_holado/tools/django/api_grpc/patch_djangogrpcframework.py +42 -0
- test_holado/tools/django/api_rest/api_rest/__init__.py +0 -0
- test_holado/tools/django/api_rest/api_rest/api1/__init__.py +0 -0
- test_holado/tools/django/api_rest/api_rest/api1/admin.py +3 -0
- test_holado/tools/django/api_rest/api_rest/api1/apps.py +6 -0
- test_holado/tools/django/api_rest/api_rest/api1/migrations/__init__.py +0 -0
- test_holado/tools/django/api_rest/api_rest/api1/models.py +3 -0
- test_holado/tools/django/api_rest/api_rest/api1/serializers.py +15 -0
- test_holado/tools/django/api_rest/api_rest/api1/tests.py +3 -0
- test_holado/tools/django/api_rest/api_rest/api1/views.py +24 -0
- test_holado/tools/django/api_rest/api_rest/asgi.py +16 -0
- test_holado/tools/django/api_rest/api_rest/settings.py +133 -0
- test_holado/tools/django/api_rest/api_rest/urls.py +32 -0
- test_holado/tools/django/api_rest/api_rest/wsgi.py +16 -0
- test_holado/tools/django/api_rest/db.sqlite3 +0 -0
- test_holado/tools/django/api_rest/manage.py +22 -0
|
@@ -0,0 +1,968 @@
|
|
|
1
|
+
|
|
2
|
+
#################################################
|
|
3
|
+
# HolAdo (Holistic Automation do)
|
|
4
|
+
#
|
|
5
|
+
# (C) Copyright 2021-2025 by Eric Klumpp
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
8
|
+
#
|
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
10
|
+
|
|
11
|
+
# The Software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the Software.
|
|
12
|
+
#################################################
|
|
13
|
+
|
|
14
|
+
import logging
|
|
15
|
+
import os
|
|
16
|
+
from holado_core.common.exceptions.functional_exception import FunctionalException
|
|
17
|
+
from holado_core.common.exceptions.technical_exception import TechnicalException
|
|
18
|
+
import sys
|
|
19
|
+
import importlib
|
|
20
|
+
import re
|
|
21
|
+
from holado_core.common.tools.tools import Tools
|
|
22
|
+
from holado_core.common.tools.converters.converter import Converter
|
|
23
|
+
from holado_value.common.tables.value_table_manager import ValueTableManager
|
|
24
|
+
from holado_value.common.tools.value_types import ValueTypes
|
|
25
|
+
import inspect
|
|
26
|
+
from typing import NamedTuple
|
|
27
|
+
from holado_core.common.exceptions.holado_exception import HAException
|
|
28
|
+
from holado_python.standard_library.typing import Typing
|
|
29
|
+
from holado.common.handlers.undefined import undefined_argument, undefined_value
|
|
30
|
+
|
|
31
|
+
logger = logging.getLogger(__name__)
|
|
32
|
+
|
|
33
|
+
try:
|
|
34
|
+
import google.protobuf.message
|
|
35
|
+
import google.protobuf.descriptor
|
|
36
|
+
from google.protobuf.descriptor import FieldDescriptor
|
|
37
|
+
# import google.protobuf.pyext
|
|
38
|
+
from google.protobuf.internal import api_implementation
|
|
39
|
+
from holado_protobuf.ipc.protobuf.protobuf_converter import SortOrder
|
|
40
|
+
|
|
41
|
+
# logger.info(f"Protobuf internal API implementation is of type '{api_implementation.Type()}'")
|
|
42
|
+
if api_implementation.Type() == 'cpp':
|
|
43
|
+
# from google.protobuf.pyext.cpp_message import GeneratedProtocolMessageType
|
|
44
|
+
from google.protobuf.pyext._message import ScalarMapContainer as ScalarMap # @UnresolvedImport @UnusedImport
|
|
45
|
+
from google.protobuf.pyext._message import MessageMapContainer as MessageMap # @UnresolvedImport @UnusedImport
|
|
46
|
+
# from google.protobuf.pyext._message import RepeatedScalarContainer as RepeatedScalarFieldContainer
|
|
47
|
+
# from google.protobuf.pyext._message import RepeatedCompositeContainer as RepeatedCompositeFieldContainer
|
|
48
|
+
else:
|
|
49
|
+
# from google.protobuf.internal.python_message import GeneratedProtocolMessageType
|
|
50
|
+
from google.protobuf.internal.containers import ScalarMap # @UnusedImport @Reimport
|
|
51
|
+
from google.protobuf.internal.containers import MessageMap # @UnusedImport @Reimport
|
|
52
|
+
from google.protobuf.internal.containers import RepeatedScalarFieldContainer, RepeatedCompositeFieldContainer # @UnusedImport
|
|
53
|
+
|
|
54
|
+
with_protobuf = True
|
|
55
|
+
except Exception as exc:
|
|
56
|
+
if Tools.do_log(logger, logging.DEBUG):
|
|
57
|
+
logger.debug(f"ProtobufMessages is not available. Initialization failed on error: {exc}")
|
|
58
|
+
with_protobuf = False
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class ProtobufMessages(object):
|
|
64
|
+
|
|
65
|
+
@classmethod
|
|
66
|
+
def is_available(cls):
|
|
67
|
+
return with_protobuf
|
|
68
|
+
|
|
69
|
+
if with_protobuf:
|
|
70
|
+
|
|
71
|
+
@classmethod
|
|
72
|
+
def is_descriptor_enum(cls, obj):
|
|
73
|
+
return isinstance(obj, google.protobuf.descriptor.EnumDescriptor)
|
|
74
|
+
|
|
75
|
+
@classmethod
|
|
76
|
+
def is_descriptor_message(cls, obj):
|
|
77
|
+
return isinstance(obj, google.protobuf.descriptor.Descriptor)
|
|
78
|
+
|
|
79
|
+
@classmethod
|
|
80
|
+
def is_object_message(cls, obj):
|
|
81
|
+
return isinstance(obj, google.protobuf.message.Message)
|
|
82
|
+
|
|
83
|
+
@classmethod
|
|
84
|
+
def is_object_enum(cls, obj):
|
|
85
|
+
class_name = type(obj).__name__.lower()
|
|
86
|
+
return "enum" in class_name
|
|
87
|
+
|
|
88
|
+
@classmethod
|
|
89
|
+
def is_object_repeated(cls, obj):
|
|
90
|
+
class_name = type(obj).__name__.lower()
|
|
91
|
+
return "repeated" in class_name
|
|
92
|
+
|
|
93
|
+
@classmethod
|
|
94
|
+
def is_object_map(cls, obj):
|
|
95
|
+
class_name = type(obj).__name__.lower()
|
|
96
|
+
return "map" in class_name and hasattr(obj, 'items') and callable(obj.items)
|
|
97
|
+
# return isinstance(obj, ScalarMap) or isinstance(obj, MessageMap)
|
|
98
|
+
|
|
99
|
+
def is_message_field_set(self, obj, field_name):
|
|
100
|
+
return self.__is_message_field_set(obj, field_name)
|
|
101
|
+
|
|
102
|
+
def __init__(self):
|
|
103
|
+
self.__message_types_by_fullname = {}
|
|
104
|
+
self.__enum_types_by_fullname = {}
|
|
105
|
+
self.__enum_data_by_fullname = {}
|
|
106
|
+
self.__regex_attribute_fullname = re.compile(r'^(.*?)(?:\[(.+)\])?$')
|
|
107
|
+
|
|
108
|
+
self.__registered_types = []
|
|
109
|
+
|
|
110
|
+
def initialize(self):
|
|
111
|
+
self._register_types()
|
|
112
|
+
|
|
113
|
+
def import_all_compiled_proto(self, compiled_proto_path, package_name=None, raise_if_not_exist=True):
|
|
114
|
+
"""Register a folder path containing compiled proto files. Usually it corresponds to the parameter '--python_out' passed to proto compiler."""
|
|
115
|
+
if Tools.do_log(logger, logging.DEBUG):
|
|
116
|
+
logger.debug(f"[ProtobufMessages] Importing all compiled proto in '{compiled_proto_path}'...")
|
|
117
|
+
|
|
118
|
+
if package_name is None:
|
|
119
|
+
package_name = ""
|
|
120
|
+
|
|
121
|
+
if os.path.exists(compiled_proto_path):
|
|
122
|
+
if os.path.isfile(compiled_proto_path):
|
|
123
|
+
proto_path = os.path.dirname(compiled_proto_path)
|
|
124
|
+
sys.path.append(proto_path)
|
|
125
|
+
self.__import_compiled_proto(compiled_proto_path, package_name)
|
|
126
|
+
elif os.path.isdir(compiled_proto_path):
|
|
127
|
+
sys.path.append(compiled_proto_path)
|
|
128
|
+
self.__import_all_compiled_proto(compiled_proto_path, package_name)
|
|
129
|
+
else:
|
|
130
|
+
raise TechnicalException(f"Unmanaged path '{compiled_proto_path}'")
|
|
131
|
+
else:
|
|
132
|
+
msg = f"Path '{compiled_proto_path}' doesn't exist"
|
|
133
|
+
if raise_if_not_exist:
|
|
134
|
+
raise TechnicalException(msg)
|
|
135
|
+
else:
|
|
136
|
+
logger.warning(msg)
|
|
137
|
+
|
|
138
|
+
def __import_all_compiled_proto(self, compiled_proto_path, package_name):
|
|
139
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
140
|
+
logger.trace(f"[ProtobufMessages] Importing all compiled proto in '{compiled_proto_path}' (package: '{package_name}')...")
|
|
141
|
+
if os.path.isdir(compiled_proto_path):
|
|
142
|
+
lp = os.listdir(compiled_proto_path)
|
|
143
|
+
for cp in lp:
|
|
144
|
+
if not cp.startswith((".", "_")):
|
|
145
|
+
cur_proto_path = os.path.join(compiled_proto_path, cp)
|
|
146
|
+
|
|
147
|
+
if os.path.isfile(cur_proto_path):
|
|
148
|
+
self.__import_compiled_proto(cur_proto_path, package_name)
|
|
149
|
+
elif os.path.isdir(cur_proto_path):
|
|
150
|
+
cur_package_name = f"{package_name}.{cp}" if package_name is not None and len(package_name) > 0 else cp
|
|
151
|
+
self.__import_all_compiled_proto(cur_proto_path, cur_package_name)
|
|
152
|
+
else:
|
|
153
|
+
raise TechnicalException(f"Unmanaged path '{cur_proto_path}'")
|
|
154
|
+
else:
|
|
155
|
+
raise TechnicalException(f"Unmanaged path '{compiled_proto_path}'")
|
|
156
|
+
|
|
157
|
+
def __import_compiled_proto(self, compiled_proto_file_path, package_name):
|
|
158
|
+
if not os.path.isfile(compiled_proto_file_path):
|
|
159
|
+
raise TechnicalException(f"Compiled proto path '{compiled_proto_file_path}' is not a file")
|
|
160
|
+
if not compiled_proto_file_path.endswith("_pb2.py"):
|
|
161
|
+
return
|
|
162
|
+
|
|
163
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
164
|
+
|
|
165
|
+
logger.trace(f"[ProtobufMessages] Importing compiled proto file '{compiled_proto_file_path}' (package: '{package_name}')...")
|
|
166
|
+
|
|
167
|
+
filename = os.path.splitext(os.path.basename(compiled_proto_file_path))[0]
|
|
168
|
+
module_name = f"{package_name}.{filename}" if package_name is not None and len(package_name) > 0 else filename
|
|
169
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
170
|
+
logger.trace(f"[ProtobufMessages] Importing module '{module_name}'")
|
|
171
|
+
module = importlib.import_module(module_name)
|
|
172
|
+
|
|
173
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
174
|
+
|
|
175
|
+
logger.trace(f"[ProtobufMessages] DESCRIPTOR of module '{module_name}': {self.__represent_descriptor(module.DESCRIPTOR)}")
|
|
176
|
+
module_package = module.DESCRIPTOR.package if hasattr(module.DESCRIPTOR, 'package') else package_name
|
|
177
|
+
self.__import_compiled_proto_object(module, module_package)
|
|
178
|
+
|
|
179
|
+
def __import_compiled_proto_object(self, module_or_object, module_or_object_fullname):
|
|
180
|
+
# Import message types
|
|
181
|
+
if hasattr(module_or_object.DESCRIPTOR, 'message_types_by_name'):
|
|
182
|
+
for mt_name in module_or_object.DESCRIPTOR.message_types_by_name:
|
|
183
|
+
self.__import_compiled_proto_message(module_or_object, module_or_object_fullname, mt_name)
|
|
184
|
+
|
|
185
|
+
# Import enum types
|
|
186
|
+
if hasattr(module_or_object.DESCRIPTOR, 'enum_types_by_name'):
|
|
187
|
+
for et_name in module_or_object.DESCRIPTOR.enum_types_by_name:
|
|
188
|
+
self.__import_compiled_proto_enum(module_or_object, module_or_object_fullname, et_name)
|
|
189
|
+
|
|
190
|
+
# Import nested types
|
|
191
|
+
if hasattr(module_or_object.DESCRIPTOR, 'nested_types_by_name'):
|
|
192
|
+
for nt_name in module_or_object.DESCRIPTOR.nested_types_by_name:
|
|
193
|
+
nt = module_or_object.DESCRIPTOR.nested_types_by_name[nt_name]
|
|
194
|
+
if self.is_descriptor_message(nt):
|
|
195
|
+
self.__import_compiled_proto_message(module_or_object, module_or_object_fullname, nt_name)
|
|
196
|
+
elif self.is_descriptor_enum(nt):
|
|
197
|
+
self.__import_compiled_proto_enum(module_or_object, module_or_object_fullname, nt_name)
|
|
198
|
+
else:
|
|
199
|
+
raise TechnicalException(f"Unmanaged nested type '{nt_name}' having descriptor: {self.__represent_descriptor(nt)}")
|
|
200
|
+
|
|
201
|
+
def __import_compiled_proto_message(self, module_or_object, module_or_object_fullname, message_type_name):
|
|
202
|
+
if hasattr(module_or_object, message_type_name):
|
|
203
|
+
mt = getattr(module_or_object, message_type_name)
|
|
204
|
+
mt_fullname = f"{module_or_object_fullname}.{message_type_name}" if module_or_object_fullname is not None and len(module_or_object_fullname) > 0 else message_type_name
|
|
205
|
+
self.__message_types_by_fullname[mt_fullname] = mt
|
|
206
|
+
if Tools.do_log(logger, logging.DEBUG):
|
|
207
|
+
logger.debug(f"[ProtobufMessages] New managed message type '{mt_fullname}' (type: '{mt.__qualname__}')")
|
|
208
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
209
|
+
logger.trace(f"[ProtobufMessages] Message type '{mt_fullname}': {Tools.represent_object(mt)}")
|
|
210
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
211
|
+
logger.trace(f"[ProtobufMessages] DESCRIPTOR of message type '{mt_fullname}': {self.__represent_descriptor(mt.DESCRIPTOR)}")
|
|
212
|
+
|
|
213
|
+
# Import nested types
|
|
214
|
+
self.__import_compiled_proto_object(mt, mt_fullname)
|
|
215
|
+
else:
|
|
216
|
+
raise TechnicalException(f"Not found message type '{message_type_name}' in '{module_or_object_fullname}': {Tools.represent_object(module_or_object)}")
|
|
217
|
+
|
|
218
|
+
def __import_compiled_proto_enum(self, module_or_object, module_or_object_fullname, enum_type_name):
|
|
219
|
+
if hasattr(module_or_object, enum_type_name):
|
|
220
|
+
et = getattr(module_or_object, enum_type_name)
|
|
221
|
+
et_fullname = f"{module_or_object_fullname}.{enum_type_name}" if module_or_object_fullname is not None and len(module_or_object_fullname) > 0 else enum_type_name
|
|
222
|
+
self.__enum_types_by_fullname[et_fullname] = et
|
|
223
|
+
if Tools.do_log(logger, logging.DEBUG):
|
|
224
|
+
logger.debug(f"[ProtobufMessages] New managed enum type '{et_fullname}' (type: '{Typing.get_object_class_fullname(et)}')")
|
|
225
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
226
|
+
logger.trace(f"[ProtobufMessages] Enum type '{et_fullname}': {Tools.represent_object(et)}")
|
|
227
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
228
|
+
logger.trace(f"[ProtobufMessages] DESCRIPTOR of enum type '{et_fullname}': {self.__represent_descriptor(et.DESCRIPTOR)}")
|
|
229
|
+
else:
|
|
230
|
+
raise TechnicalException(f"Not found enum type '{enum_type_name}' in '{module_or_object_fullname}': {Tools.represent_object(module_or_object)}")
|
|
231
|
+
|
|
232
|
+
def has_object_type(self, type_fullname):
|
|
233
|
+
"""Return if type fullname is known."""
|
|
234
|
+
return self.has_message_type(type_fullname) or self.has_enum_type(type_fullname)
|
|
235
|
+
|
|
236
|
+
def has_message_type(self, message_type_fullname):
|
|
237
|
+
"""Return if message type fullname is known."""
|
|
238
|
+
return message_type_fullname in self.__message_types_by_fullname
|
|
239
|
+
|
|
240
|
+
def has_enum_type(self, enum_type_fullname):
|
|
241
|
+
"""Return if enum type fullname is known."""
|
|
242
|
+
return enum_type_fullname in self.__enum_types_by_fullname
|
|
243
|
+
|
|
244
|
+
def get_object_type(self, type_fullname):
|
|
245
|
+
"""Return type object for given type fullname."""
|
|
246
|
+
if self.has_message_type(type_fullname):
|
|
247
|
+
return self.get_message_type(type_fullname)
|
|
248
|
+
else:
|
|
249
|
+
raise FunctionalException(f"Unknown type fullname '{type_fullname}'")
|
|
250
|
+
|
|
251
|
+
def get_message_type(self, message_type_fullname):
|
|
252
|
+
"""Return type object for given message type fullname."""
|
|
253
|
+
if self.has_message_type(message_type_fullname):
|
|
254
|
+
return self.__message_types_by_fullname[message_type_fullname]
|
|
255
|
+
else:
|
|
256
|
+
raise FunctionalException(f"Unknown message type fullname '{message_type_fullname}'")
|
|
257
|
+
|
|
258
|
+
def get_enum_type(self, enum_type_fullname):
|
|
259
|
+
"""Return type object for given message type fullname."""
|
|
260
|
+
if self.has_enum_type(enum_type_fullname):
|
|
261
|
+
return self.__enum_types_by_fullname[enum_type_fullname]
|
|
262
|
+
else:
|
|
263
|
+
raise FunctionalException(f"Unknown enum type fullname '{enum_type_fullname}' (known enums: {list(self.__enum_types_by_fullname.keys())})")
|
|
264
|
+
|
|
265
|
+
def get_enum_name(self, enum_value, enum_type_fullname):
|
|
266
|
+
enum_type = self.get_enum_type(enum_type_fullname)
|
|
267
|
+
return self.__get_enum_name(enum_value, enum_type=enum_type)
|
|
268
|
+
|
|
269
|
+
def get_enum_value(self, fullname=None, enum_type_fullname=None, enum_name=None):
|
|
270
|
+
if fullname is not None:
|
|
271
|
+
enum_type_fullname, enum_name = fullname.rsplit('.', 1)
|
|
272
|
+
enum_type = self.get_enum_type(enum_type_fullname)
|
|
273
|
+
return self.__get_enum_value(enum_name, enum_type=enum_type)
|
|
274
|
+
|
|
275
|
+
def new_object(self, type_fullname):
|
|
276
|
+
"""Return a new object of given type fullname."""
|
|
277
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
278
|
+
logger.trace(f"Creating new object of type '{type_fullname}'...")
|
|
279
|
+
if self.has_object_type(type_fullname):
|
|
280
|
+
if self.has_message_type(type_fullname):
|
|
281
|
+
mt = self.get_message_type(type_fullname)
|
|
282
|
+
res = mt()
|
|
283
|
+
else:
|
|
284
|
+
raise TechnicalException(f"Unmanaged object creation for type fullname '{type_fullname}' (all managed types are logged at start with level DEBUG)")
|
|
285
|
+
else:
|
|
286
|
+
raise TechnicalException(f"Unknown type fullname '{type_fullname}' (all known types are logged at start with level DEBUG)")
|
|
287
|
+
|
|
288
|
+
if Tools.do_log(logger, logging.DEBUG):
|
|
289
|
+
logger.debug(f"New object of type '{type_fullname}' => {res}")
|
|
290
|
+
return res
|
|
291
|
+
|
|
292
|
+
def new_message(self, message_type_fullname, fields_table=None, fields_dict=None, serialized_string=None):
|
|
293
|
+
"""Return a new message of given message type fullname.
|
|
294
|
+
The content of the message can be filled from serialized string, or from field values in a Name/Value table.
|
|
295
|
+
"""
|
|
296
|
+
res = self.new_object(message_type_fullname)
|
|
297
|
+
|
|
298
|
+
if serialized_string is not None:
|
|
299
|
+
res.ParseFromString(serialized_string)
|
|
300
|
+
elif fields_table is not None:
|
|
301
|
+
if ValueTableManager.verify_table_is_name_value_table(fields_table, raise_exception=False):
|
|
302
|
+
self.__set_object_fields_with_name_value_table(res, fields_table)
|
|
303
|
+
else:
|
|
304
|
+
raise TechnicalException(f"When defining parameter fields_table, it must be a Name/Value table: [{Typing.get_object_class_fullname(fields_table)}]\n{fields_table.represent(4)}")
|
|
305
|
+
elif fields_dict is not None:
|
|
306
|
+
self.__set_object_fields_with_dict(res, fields_dict)
|
|
307
|
+
|
|
308
|
+
if Tools.do_log(logger, logging.DEBUG):
|
|
309
|
+
# logger.debug(f"New message of type '{message_type_fullname}' => {res}")
|
|
310
|
+
logger.debug(f"New message of type '{message_type_fullname}' => {Tools.represent_object(res)}")
|
|
311
|
+
return res
|
|
312
|
+
|
|
313
|
+
def get_object_field_names(self, obj, recursive=False, uncollapse_repeated=False, add_repeated_index=False, with_unset=True, sort_order=SortOrder.Definition):
|
|
314
|
+
res = self.__get_object_field_names(obj, recursive=recursive, uncollapse_repeated=uncollapse_repeated, add_repeated_index=add_repeated_index, with_unset=with_unset, is_message_field=False, sort_order=sort_order)
|
|
315
|
+
# logger.trace(f"Object of type '{self.get_object_type_fullname(obj)}' has field names: {res}")
|
|
316
|
+
return res
|
|
317
|
+
|
|
318
|
+
def get_message_field_names(self, obj, recursive=False, uncollapse_repeated=False, add_repeated_index=False, with_unset=True):
|
|
319
|
+
res = self.__get_message_field_names(obj, recursive=recursive, uncollapse_repeated=uncollapse_repeated, add_repeated_index=add_repeated_index, with_unset=with_unset)
|
|
320
|
+
# logger.trace(f"Message of type '{self.get_object_type_fullname(obj)}' has field names: {res}")
|
|
321
|
+
return res
|
|
322
|
+
|
|
323
|
+
def get_object_field_values(self, obj, attribute_expression):
|
|
324
|
+
"""
|
|
325
|
+
Return a list of values for attribute names matching given expression.
|
|
326
|
+
Attribute name expression can contain "." for sub-fields, and "[]" to access all elements of the repeated field.
|
|
327
|
+
The list contains only one value unless a repeated field is included in attribute expression with suffix '[]'.
|
|
328
|
+
"""
|
|
329
|
+
attr_names = attribute_expression.split('.')
|
|
330
|
+
res_list = [(obj, "")]
|
|
331
|
+
for attr_name in attr_names:
|
|
332
|
+
old_list = res_list
|
|
333
|
+
if attr_name.endswith("[]"):
|
|
334
|
+
if len(old_list) > 1:
|
|
335
|
+
raise TechnicalException("Uncollapse two different repeated fields in the same message is not managed.")
|
|
336
|
+
cur_res = old_list[0][0]
|
|
337
|
+
cur_fullname = old_list[0][1]
|
|
338
|
+
real_attr_name = attr_name[:-2]
|
|
339
|
+
|
|
340
|
+
cur_attr_fullname = cur_fullname + '.' + real_attr_name if len(cur_fullname) > 0 else real_attr_name
|
|
341
|
+
if not hasattr(cur_res, real_attr_name):
|
|
342
|
+
raise TechnicalException(f"Attribute '{cur_attr_fullname}' doesn't exist in object [{cur_res}]")
|
|
343
|
+
|
|
344
|
+
res_list = []
|
|
345
|
+
for index, attr_obj in enumerate(getattr(cur_res, real_attr_name)):
|
|
346
|
+
new_attr_fullname = f"{cur_attr_fullname}[{index}]"
|
|
347
|
+
res_list.append((attr_obj, new_attr_fullname))
|
|
348
|
+
else:
|
|
349
|
+
res_list = []
|
|
350
|
+
for obj, obj_attr_fullname in old_list:
|
|
351
|
+
new_attr_fullname = f"{obj_attr_fullname}.{attr_name}"
|
|
352
|
+
if self.__has_object_field(obj, field_name=attr_name):
|
|
353
|
+
attr_obj = self.__get_object_field(obj, field_name=attr_name)
|
|
354
|
+
res_list.append((attr_obj, new_attr_fullname))
|
|
355
|
+
else:
|
|
356
|
+
raise TechnicalException(f"Attribute '{new_attr_fullname}' doesn't exist in object [{obj}]")
|
|
357
|
+
|
|
358
|
+
return [obj for obj, _ in res_list]
|
|
359
|
+
|
|
360
|
+
def has_object_field(self, obj, attribute_expression, create_field=False):
|
|
361
|
+
leaf_obj, _, attr_last_name = self.__get_leaf_object_and_attribute_names(obj, attribute_expression, create_field=create_field)
|
|
362
|
+
return self.__has_object_field(leaf_obj, field_fullname=attr_last_name)
|
|
363
|
+
|
|
364
|
+
def get_object_field_value(self, obj, attribute_expression, create_field=False):
|
|
365
|
+
"""
|
|
366
|
+
Return the value for attribute name matching given expression.
|
|
367
|
+
Attribute name expression can contain "." for sub-fields.
|
|
368
|
+
"""
|
|
369
|
+
attr_names = attribute_expression.split('.')
|
|
370
|
+
res = obj
|
|
371
|
+
attr_fullname = ""
|
|
372
|
+
for attr_name in attr_names:
|
|
373
|
+
if self.__has_object_field(res, field_fullname=attr_name):
|
|
374
|
+
res = self.__get_object_field(res, field_fullname=attr_name, create_field=create_field)
|
|
375
|
+
attr_fullname = attr_fullname + '.' + attr_name if len(attr_fullname) > 0 else attr_name
|
|
376
|
+
else:
|
|
377
|
+
attr_name, _ = self.__split_attribute_fullname(attr_name)
|
|
378
|
+
if len(attr_fullname) > 0:
|
|
379
|
+
attr_fullname = attr_fullname + '.' + attr_name
|
|
380
|
+
raise FunctionalException(f"Field '{attr_fullname}' doesn't exist in message type '{self.get_object_type_fullname(obj)}' (in sub-message type '{self.get_object_type_fullname(res)}', existing fields: {self.__get_object_descriptor_field_names(res, False)})")
|
|
381
|
+
else:
|
|
382
|
+
raise FunctionalException(f"Field '{attr_name}' doesn't exist in message type '{self.get_object_type_fullname(obj)}' (existing fields: {self.__get_object_descriptor_field_names(obj, False)})")
|
|
383
|
+
|
|
384
|
+
return res
|
|
385
|
+
|
|
386
|
+
def set_object_field_value(self, obj, attribute_expression, value):
|
|
387
|
+
if Tools.do_log(logger, logging.DEBUG):
|
|
388
|
+
logger.debug(f"Setting protobuf object ({id(obj)}) field '{attribute_expression}' with value [{value}] (type: {Typing.get_object_class_fullname(value)})")
|
|
389
|
+
leaf_obj, leaf_attribute_expression, attr_last_name = self.__get_leaf_object_and_attribute_names(obj, attribute_expression, create_field=True)
|
|
390
|
+
|
|
391
|
+
# Set value
|
|
392
|
+
if self.__has_object_field(leaf_obj, field_fullname=attr_last_name):
|
|
393
|
+
self.__set_object_field(leaf_obj, field_fullname=attr_last_name, value=value, create_field=True)
|
|
394
|
+
else:
|
|
395
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
396
|
+
logger.trace(f"Field '{attr_last_name}' doesn't exist in type '{self.get_object_type_fullname(leaf_obj)}'")
|
|
397
|
+
attr_name, _ = self.__split_attribute_fullname(attr_last_name)
|
|
398
|
+
if leaf_attribute_expression is not None:
|
|
399
|
+
attr_fullname = leaf_attribute_expression + '.' + attr_name
|
|
400
|
+
raise FunctionalException(f"Field '{attr_fullname}' doesn't exist in object type '{self.get_object_type_fullname(obj)}' (in sub-message type '{self.get_object_type_fullname(leaf_obj)}', existing fields: {self.__get_object_descriptor_field_names(leaf_obj, False)})")
|
|
401
|
+
else:
|
|
402
|
+
raise FunctionalException(f"Field '{attr_name}' doesn't exist in object type '{self.get_object_type_fullname(obj)}' (existing fields: {self.__get_object_descriptor_field_names(obj, False)})")
|
|
403
|
+
|
|
404
|
+
def __get_leaf_object_and_attribute_names(self, obj, attribute_expression, create_field=False):
|
|
405
|
+
try:
|
|
406
|
+
leaf_attribute_expression, attr_last_name = attribute_expression.rsplit('.', 1)
|
|
407
|
+
except ValueError:
|
|
408
|
+
leaf_obj = obj
|
|
409
|
+
leaf_attribute_expression = None
|
|
410
|
+
attr_last_name = attribute_expression
|
|
411
|
+
else:
|
|
412
|
+
# Get "leaf" object (in object tree) containing the leaf attribute to set
|
|
413
|
+
leaf_obj = self.get_object_field_value(obj, leaf_attribute_expression, create_field=create_field)
|
|
414
|
+
return leaf_obj, leaf_attribute_expression, attr_last_name
|
|
415
|
+
|
|
416
|
+
def __get_object_field_names(self, obj, recursive=False, uncollapse_repeated=False, add_repeated_index=True, with_unset=True, prefix="", is_message_field=False, sort_order=SortOrder.Definition):
|
|
417
|
+
res = []
|
|
418
|
+
if uncollapse_repeated and ProtobufMessages.is_object_repeated(obj):
|
|
419
|
+
if add_repeated_index:
|
|
420
|
+
for index, value in enumerate(obj):
|
|
421
|
+
new_prefix = f"{prefix}[{index}]"
|
|
422
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
423
|
+
logger.trace(f"Adding field names of repeated with prefix '{new_prefix}' (type: {Typing.get_object_class_fullname(value)})")
|
|
424
|
+
res.extend(self.__get_object_field_names(value, recursive=recursive, uncollapse_repeated=uncollapse_repeated, add_repeated_index=add_repeated_index, with_unset=with_unset, prefix=new_prefix, is_message_field=is_message_field, sort_order=sort_order))
|
|
425
|
+
else:
|
|
426
|
+
new_prefix = f"{prefix}[]"
|
|
427
|
+
value = obj[0]
|
|
428
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
429
|
+
logger.trace(f"Adding field names of repeated with prefix '{new_prefix}' (type: {Typing.get_object_class_fullname(value)})")
|
|
430
|
+
res.extend(self.__get_object_field_names(value, recursive=recursive, uncollapse_repeated=uncollapse_repeated, add_repeated_index=add_repeated_index, with_unset=with_unset, prefix=new_prefix, is_message_field=is_message_field, sort_order=sort_order))
|
|
431
|
+
elif (recursive or not is_message_field) and ProtobufMessages.is_object_map(obj):
|
|
432
|
+
sorted_dict = dict(sorted(obj.items()))
|
|
433
|
+
for key, value in sorted_dict.items():
|
|
434
|
+
key_prefix = f"{prefix}[{key}]" if len(prefix) > 0 else key
|
|
435
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
436
|
+
logger.trace(f"Adding field names of object of prefix '{key_prefix}' (type: {Typing.get_object_class_fullname(value)})")
|
|
437
|
+
res.extend(self.__get_object_field_names(value, recursive=recursive, uncollapse_repeated=uncollapse_repeated, add_repeated_index=add_repeated_index, with_unset=with_unset, prefix=key_prefix, is_message_field=is_message_field))
|
|
438
|
+
elif (recursive or not is_message_field) and ProtobufMessages.is_object_message(obj):
|
|
439
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
440
|
+
logger.trace(f"Adding field names of message of prefix '{prefix}' (type: {Typing.get_object_class_fullname(obj)})")
|
|
441
|
+
res.extend(self.__get_message_field_names(obj, recursive=recursive, uncollapse_repeated=uncollapse_repeated, add_repeated_index=add_repeated_index, with_unset=with_unset, prefix=prefix, sort_order=sort_order))
|
|
442
|
+
elif len(prefix) > 0:
|
|
443
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
444
|
+
logger.trace(f"Adding field name '{prefix}' (value type: {Typing.get_object_class_fullname(obj)})")
|
|
445
|
+
res.append(prefix)
|
|
446
|
+
else:
|
|
447
|
+
# logger.trace(f"Adding field name '{attr_name}' (value type: {Typing.get_object_class_fullname(attr_val)})")
|
|
448
|
+
raise TechnicalException(f"Object has no field and prefix is empty (object: {obj} ; type: {Typing.get_object_class_fullname(obj)})")
|
|
449
|
+
return res
|
|
450
|
+
|
|
451
|
+
def __get_message_field_names(self, obj, recursive=False, uncollapse_repeated=False, add_repeated_index=True, with_unset=True, prefix="", sort_order=SortOrder.Definition):
|
|
452
|
+
res = []
|
|
453
|
+
attribute_names = self.__get_object_descriptor_field_names(obj, sort_order=sort_order)
|
|
454
|
+
for attr_name in attribute_names:
|
|
455
|
+
attr_val = getattr(obj, attr_name)
|
|
456
|
+
new_prefix = f"{prefix + '.' if len(prefix) > 0 else ''}{attr_name}"
|
|
457
|
+
|
|
458
|
+
# Skip field not set
|
|
459
|
+
if not with_unset:
|
|
460
|
+
set_status = self.__is_message_field_set(obj, attr_name)
|
|
461
|
+
if set_status == False:
|
|
462
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
463
|
+
logger.trace(f"Hide unset field '{attr_name}' in object type '{self.get_object_type_fullname(obj)}' (field type: {Typing.get_object_class_fullname(attr_val)})")
|
|
464
|
+
continue
|
|
465
|
+
|
|
466
|
+
# Skip optional fields that are not set
|
|
467
|
+
if self.__is_message_field_optional(obj, attr_name):
|
|
468
|
+
set_status = self.__is_message_field_set(obj, attr_name)
|
|
469
|
+
if set_status == False:
|
|
470
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
471
|
+
logger.trace(f"Hide unset optional field '{attr_name}' in object type '{self.get_object_type_fullname(obj)}' (field type: {Typing.get_object_class_fullname(attr_val)})")
|
|
472
|
+
continue
|
|
473
|
+
|
|
474
|
+
# Skip oneof field that is not set
|
|
475
|
+
if self.__is_message_field_oneof_field(obj, attr_name):
|
|
476
|
+
set_status = self.__is_message_field_set(obj, attr_name)
|
|
477
|
+
if set_status == False:
|
|
478
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
479
|
+
logger.trace(f"Hide unset oneof field '{attr_name}' in object type '{self.get_object_type_fullname(obj)}' (field type: {Typing.get_object_class_fullname(attr_val)})")
|
|
480
|
+
continue
|
|
481
|
+
|
|
482
|
+
res.extend(self.__get_object_field_names(attr_val, recursive=recursive, uncollapse_repeated=uncollapse_repeated, add_repeated_index=add_repeated_index, with_unset=with_unset, prefix=new_prefix, is_message_field=True, sort_order=sort_order))
|
|
483
|
+
return res
|
|
484
|
+
|
|
485
|
+
def __is_message_field_oneof_field(self, obj, field_name):
|
|
486
|
+
field_descr = self.__get_object_field_descriptor(obj, field_name)
|
|
487
|
+
res = (field_descr.label == FieldDescriptor.LABEL_OPTIONAL
|
|
488
|
+
and field_descr.containing_oneof is not None
|
|
489
|
+
and field_descr.has_presence)
|
|
490
|
+
return res
|
|
491
|
+
|
|
492
|
+
def __is_message_field_optional(self, obj, field_name):
|
|
493
|
+
field_descr = self.__get_object_field_descriptor(obj, field_name)
|
|
494
|
+
res = (field_descr.label == FieldDescriptor.LABEL_OPTIONAL
|
|
495
|
+
and field_descr.containing_oneof is not None and len(field_descr.containing_oneof.fields) == 1
|
|
496
|
+
and field_descr.has_presence)
|
|
497
|
+
return res
|
|
498
|
+
|
|
499
|
+
def __is_message_field_repeated(self, obj, field_name):
|
|
500
|
+
field_descr = self.__get_object_field_descriptor(obj, field_name)
|
|
501
|
+
return (field_descr.label == FieldDescriptor.LABEL_REPEATED)
|
|
502
|
+
|
|
503
|
+
def __is_message_field_required(self, obj, field_name):
|
|
504
|
+
field_descr = self.__get_object_field_descriptor(obj, field_name)
|
|
505
|
+
return (field_descr.label == FieldDescriptor.LABEL_REQUIRED)
|
|
506
|
+
|
|
507
|
+
def __is_message_field_set(self, obj, field_name):
|
|
508
|
+
"""
|
|
509
|
+
If field can distinguish between unpopulated and default values, return if field is set, else return None.
|
|
510
|
+
"""
|
|
511
|
+
try:
|
|
512
|
+
return obj.HasField(field_name)
|
|
513
|
+
except ValueError:
|
|
514
|
+
# logger.trace(f"Field '{field_name}' is not optional. Got error: {exc}")
|
|
515
|
+
return None
|
|
516
|
+
|
|
517
|
+
def __get_object_descriptor_field_names(self, obj, raise_exception=True, sort_order=SortOrder.Definition):
|
|
518
|
+
#TODO EKL: manage oneof fields => return only the name of the oneof field that is defined
|
|
519
|
+
if hasattr(obj, 'DESCRIPTOR'):
|
|
520
|
+
descriptor = getattr(obj, 'DESCRIPTOR')
|
|
521
|
+
# TODO: When it will be possible with python generated code, remove from result the deprecated fields
|
|
522
|
+
# logger.info(f"+++++++++++++ descriptor: {self.__represent_descriptor(descriptor)}")
|
|
523
|
+
res = [f.name for f in descriptor.fields if not hasattr(f, "isDeprecated")]
|
|
524
|
+
if sort_order == SortOrder.Alphabetic:
|
|
525
|
+
res.sort()
|
|
526
|
+
return res
|
|
527
|
+
else:
|
|
528
|
+
# return Typing.get_object_attribute_names(obj)
|
|
529
|
+
if raise_exception:
|
|
530
|
+
raise TechnicalException(f"Not found attribute 'DESCRIPTOR' in object of type '{self.get_object_type_fullname(obj)}' [{obj}]")
|
|
531
|
+
else:
|
|
532
|
+
return []
|
|
533
|
+
|
|
534
|
+
def __get_object_field_descriptor(self, obj, field_name):
|
|
535
|
+
if hasattr(obj, 'DESCRIPTOR'):
|
|
536
|
+
descriptor = getattr(obj, 'DESCRIPTOR')
|
|
537
|
+
if field_name in descriptor.fields_by_name:
|
|
538
|
+
return descriptor.fields_by_name[field_name]
|
|
539
|
+
else:
|
|
540
|
+
raise FunctionalException(f"Field '{field_name}' doesn't exist in type '{self.get_object_type_fullname(obj)}'")
|
|
541
|
+
else:
|
|
542
|
+
raise TechnicalException(f"Not found attribute 'DESCRIPTOR' in object of type '{self.get_object_type_fullname(obj)}' [{obj}]")
|
|
543
|
+
|
|
544
|
+
def __has_object_field(self, obj, field_name=None, field_fullname=None):
|
|
545
|
+
param_in_brackets = None
|
|
546
|
+
if field_name is None:
|
|
547
|
+
field_name, param_in_brackets = self.__split_attribute_fullname(field_fullname)
|
|
548
|
+
|
|
549
|
+
if len(field_name) == 0:
|
|
550
|
+
# Manage field_fullname in format "[XXX]"
|
|
551
|
+
if param_in_brackets is not None:
|
|
552
|
+
if self.is_object_repeated(obj):
|
|
553
|
+
if Converter.is_integer(param_in_brackets):
|
|
554
|
+
li_index = int(param_in_brackets)
|
|
555
|
+
res = li_index < len(obj)
|
|
556
|
+
else:
|
|
557
|
+
raise FunctionalException(f"For repeated objects, the parameter in brackets must be an integer (field fullname: '{field_fullname}')")
|
|
558
|
+
elif self.is_object_map(obj):
|
|
559
|
+
res = param_in_brackets in obj
|
|
560
|
+
# if not res:
|
|
561
|
+
# logger.trace(f"++++++ Key '{param_in_brackets}' in not in map {obj}")
|
|
562
|
+
else:
|
|
563
|
+
raise TechnicalException(f"Unexpected brackets in field fullname '{field_fullname}' for object of type '{self.get_object_type_fullname(obj)}'")
|
|
564
|
+
else:
|
|
565
|
+
raise TechnicalException(f"Unexpected field " + f"fullname '{field_fullname}'" if field_fullname is not None else f"name '{field_name}'")
|
|
566
|
+
elif self.is_object_map(obj):
|
|
567
|
+
res = field_name in obj
|
|
568
|
+
else:
|
|
569
|
+
res = field_name in self.__get_object_descriptor_field_names(obj, False)
|
|
570
|
+
|
|
571
|
+
if not res:
|
|
572
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
573
|
+
logger.trace(f"Field '{field_name}' doesn't exist in type '{self.get_object_type_fullname(obj)}' (existing fields: {self.__get_object_descriptor_field_names(obj, False)})")
|
|
574
|
+
return res
|
|
575
|
+
|
|
576
|
+
def __get_object_field_type_fullname(self, obj, field_name):
|
|
577
|
+
if not self.__has_object_field(obj, field_name):
|
|
578
|
+
raise FunctionalException()
|
|
579
|
+
|
|
580
|
+
field_descr = self.__get_object_field_descriptor(obj, field_name)
|
|
581
|
+
if field_descr.message_type:
|
|
582
|
+
return self.get_object_type_fullname(descriptor=field_descr.message_type)
|
|
583
|
+
elif field_descr.enum_type:
|
|
584
|
+
return self.get_object_type_fullname(descriptor=field_descr.enum_type)
|
|
585
|
+
else:
|
|
586
|
+
return field_descr.type
|
|
587
|
+
|
|
588
|
+
def __get_object_field(self, obj, field_name=None, field_fullname=None, create_field=False):
|
|
589
|
+
param_in_brackets = None
|
|
590
|
+
if field_name is None:
|
|
591
|
+
field_name, param_in_brackets = self.__split_attribute_fullname(field_fullname)
|
|
592
|
+
|
|
593
|
+
if len(field_name) == 0:
|
|
594
|
+
# Manage field_fullname in format "[XXX]"
|
|
595
|
+
if param_in_brackets is not None:
|
|
596
|
+
if self.is_object_repeated(obj):
|
|
597
|
+
if Converter.is_integer(param_in_brackets):
|
|
598
|
+
li_index = int(param_in_brackets)
|
|
599
|
+
res = self.__get_object_repeated_by_index(obj, li_index, add_index=create_field)
|
|
600
|
+
else:
|
|
601
|
+
raise FunctionalException(f"For repeated objects, the parameter in brackets must be an integer (field fullname: '{field_fullname}')")
|
|
602
|
+
elif self.is_object_map(obj):
|
|
603
|
+
res = obj[param_in_brackets]
|
|
604
|
+
else:
|
|
605
|
+
raise TechnicalException(f"Unexpected brackets in field fullname '{field_fullname}' for object of type '{self.get_object_type_fullname(obj)}'")
|
|
606
|
+
else:
|
|
607
|
+
raise TechnicalException(f"Unexpected field " + f"fullname '{field_fullname}'" if field_fullname is not None else f"name '{field_name}'")
|
|
608
|
+
|
|
609
|
+
elif self.is_object_map(obj):
|
|
610
|
+
res = obj[field_name]
|
|
611
|
+
|
|
612
|
+
elif hasattr(obj, field_name):
|
|
613
|
+
if param_in_brackets is not None:
|
|
614
|
+
if Converter.is_integer(param_in_brackets):
|
|
615
|
+
li_index = int(param_in_brackets)
|
|
616
|
+
res = self.__get_object_repeated_field_by_index(obj, field_name, li_index, add_index=create_field)
|
|
617
|
+
else:
|
|
618
|
+
res = getattr(obj, field_name)[param_in_brackets]
|
|
619
|
+
else:
|
|
620
|
+
res = getattr(obj, field_name)
|
|
621
|
+
|
|
622
|
+
# Manage enum
|
|
623
|
+
res = self.__get_enum_name_if_field_is_enum(res, obj=obj, field_name=field_name)
|
|
624
|
+
|
|
625
|
+
elif self.__has_object_field(obj, field_name=field_name):
|
|
626
|
+
if create_field:
|
|
627
|
+
field_type_fullname = self.__get_object_field_type_fullname(obj, field_name)
|
|
628
|
+
if isinstance(field_type_fullname, int):
|
|
629
|
+
raise TechnicalException("Unexpected case: the native types are expected to exist in object")
|
|
630
|
+
res = self.new_object(field_type_fullname)
|
|
631
|
+
setattr(obj, field_name, res)
|
|
632
|
+
else:
|
|
633
|
+
raise FunctionalException(f"Field '{field_name}' exists in type '{self.get_object_type_fullname(obj)}' but not in instance [{obj}]")
|
|
634
|
+
else:
|
|
635
|
+
raise FunctionalException(f"Field '{field_name}' doesn't exist in type '{self.get_object_type_fullname(obj)}'")
|
|
636
|
+
|
|
637
|
+
return res
|
|
638
|
+
|
|
639
|
+
def __get_object_repeated_by_index(self, obj, index, add_index=False):
|
|
640
|
+
if not ProtobufMessages.is_object_repeated(obj):
|
|
641
|
+
raise FunctionalException(f"Object of type '{self.get_object_type_fullname(obj)}' is not a repeated")
|
|
642
|
+
|
|
643
|
+
# Add repeated element if it doesn't exist
|
|
644
|
+
if len(obj) < index + 1:
|
|
645
|
+
if add_index:
|
|
646
|
+
for _ in range(index + 1 - len(obj)):
|
|
647
|
+
res = obj.add()
|
|
648
|
+
else:
|
|
649
|
+
raise FunctionalException(f"Index {index} exceeds repeated length {len(obj)}")
|
|
650
|
+
else:
|
|
651
|
+
res = obj[index]
|
|
652
|
+
|
|
653
|
+
return res
|
|
654
|
+
|
|
655
|
+
def __get_object_repeated_field_by_index(self, obj, field_name, index, add_index=False):
|
|
656
|
+
field_obj = getattr(obj, field_name)
|
|
657
|
+
if not ProtobufMessages.is_object_repeated(field_obj):
|
|
658
|
+
raise FunctionalException(f"Field '{field_name}' is not a repeated in type '{self.get_object_type_fullname(obj)}'")
|
|
659
|
+
if len(field_obj) < index + 1 and not add_index:
|
|
660
|
+
raise FunctionalException(f"Index {index} exceeds repeated length {len(field_obj)} (field '{field_name}' in object of type '{self.get_object_type_fullname(obj)}' [{obj}])")
|
|
661
|
+
|
|
662
|
+
return self.__get_object_repeated_by_index(field_obj, index, add_index)
|
|
663
|
+
|
|
664
|
+
def get_object_type_fullname(self, obj=None, obj_class=None, descriptor=None):
|
|
665
|
+
# None type
|
|
666
|
+
if obj is None and obj_class is None and descriptor is None:
|
|
667
|
+
return None.__class__.__name__
|
|
668
|
+
|
|
669
|
+
# Object -> object class
|
|
670
|
+
if obj is not None:
|
|
671
|
+
return self.get_object_type_fullname(obj_class=type(obj))
|
|
672
|
+
|
|
673
|
+
# Object class -> object class descriptor
|
|
674
|
+
if hasattr(obj_class, 'DESCRIPTOR'):
|
|
675
|
+
return self.get_object_type_fullname(descriptor=obj_class.DESCRIPTOR)
|
|
676
|
+
|
|
677
|
+
# Extract information from descriptor
|
|
678
|
+
if descriptor:
|
|
679
|
+
if hasattr(descriptor, 'full_name'):
|
|
680
|
+
return descriptor.full_name
|
|
681
|
+
elif descriptor.containing_type is not None:
|
|
682
|
+
containing_fullname = self.get_object_type_fullname(obj_class=descriptor.containing_type)
|
|
683
|
+
return containing_fullname + '.' + descriptor.name
|
|
684
|
+
else:
|
|
685
|
+
raise TechnicalException(f"Failed to extract type fullname from descriptor: {self.__represent_descriptor(descriptor)}")
|
|
686
|
+
|
|
687
|
+
# Extract information from classzhDM
|
|
688
|
+
if obj_class.__module__.endswith('_pb2'):
|
|
689
|
+
package_name = os.path.splitext(obj_class.__module__)[0]
|
|
690
|
+
return package_name + '.' + obj_class.__name__
|
|
691
|
+
else:
|
|
692
|
+
return obj_class.__module__ + '.' + obj_class.__name__
|
|
693
|
+
|
|
694
|
+
def __set_object_fields_with_name_value_table(self, obj, table):
|
|
695
|
+
# Verify table structure
|
|
696
|
+
ValueTableManager.verify_table_is_name_value_table(table)
|
|
697
|
+
|
|
698
|
+
for row in table.rows:
|
|
699
|
+
if row.get_cell(1).value_type not in [ValueTypes.NotApplicable]:
|
|
700
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
701
|
+
logger.trace(f"Setting protobuf object field with row ({row})")
|
|
702
|
+
|
|
703
|
+
name = row.get_cell(0).value
|
|
704
|
+
value = row.get_cell(1).value
|
|
705
|
+
|
|
706
|
+
self.set_object_field_value(obj, name, value)
|
|
707
|
+
|
|
708
|
+
def __set_object_fields_with_dict(self, obj, values_dict):
|
|
709
|
+
for name, value in values_dict.items():
|
|
710
|
+
self.set_object_field_value(obj, name, value)
|
|
711
|
+
|
|
712
|
+
def __check_field_value_to_set_is_valid(self, value):
|
|
713
|
+
if value is undefined_argument or value is undefined_value:
|
|
714
|
+
raise ValueError(f"Special objects undefined_* are not valid field values")
|
|
715
|
+
|
|
716
|
+
def __set_object_field(self, obj, field_name=None, field_fullname=None, value=None, create_field=False):
|
|
717
|
+
in_brackets_str = None
|
|
718
|
+
if field_name is None:
|
|
719
|
+
field_name, in_brackets_str = self.__split_attribute_fullname(field_fullname)
|
|
720
|
+
if not self.__has_object_field(obj, field_name):
|
|
721
|
+
raise TechnicalException(f"Field '{field_name}' doesn't exist in type '{self.get_object_type_fullname(obj)}'")
|
|
722
|
+
self.__check_field_value_to_set_is_valid(value)
|
|
723
|
+
|
|
724
|
+
try:
|
|
725
|
+
if hasattr(obj, field_name):
|
|
726
|
+
if in_brackets_str is not None:
|
|
727
|
+
from holado_test.scenario.step_tools import StepTools
|
|
728
|
+
in_brackets_obj = StepTools.evaluate_scenario_parameter(in_brackets_str)
|
|
729
|
+
if isinstance(in_brackets_obj, int):
|
|
730
|
+
li_index = in_brackets_obj
|
|
731
|
+
self.__set_object_repeated_field_by_index(obj, field_name, li_index, value, add_index=create_field)
|
|
732
|
+
else:
|
|
733
|
+
field_obj = getattr(obj, field_name)
|
|
734
|
+
field_obj[in_brackets_obj] = value
|
|
735
|
+
elif self.is_object_map(getattr(obj, field_name)):
|
|
736
|
+
field_obj = getattr(obj, field_name)
|
|
737
|
+
for key in value:
|
|
738
|
+
field_obj[key] = value[key]
|
|
739
|
+
elif self.is_object_repeated(getattr(obj, field_name)):
|
|
740
|
+
self.__set_object_repeated_field(obj, field_name, value, add_index=True)
|
|
741
|
+
else:
|
|
742
|
+
field_type_fullname = self.__get_object_field_type_fullname(obj, field_name)
|
|
743
|
+
if isinstance(field_type_fullname, int):
|
|
744
|
+
self.__set_object_field_attr(obj, field_name, value)
|
|
745
|
+
else:
|
|
746
|
+
field_descr = self.__get_object_field_descriptor(obj, field_name)
|
|
747
|
+
# logger.trace(f"+++++ Setting field '{field_name}' of descriptor: {self.__represent_descriptor(field_descr)}")
|
|
748
|
+
if field_descr.enum_type is not None:
|
|
749
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
750
|
+
logger.trace(f"Setting enum field '{field_name}' (type: {field_type_fullname}) with value [{value}] (type: {Typing.get_object_class_fullname(value)})")
|
|
751
|
+
enum_value = self.__get_enum_value(value, enum_type_descriptor=field_descr.enum_type)
|
|
752
|
+
self.__set_object_field_attr(obj, field_name, enum_value)
|
|
753
|
+
else:
|
|
754
|
+
field_obj = getattr(obj, field_name)
|
|
755
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
756
|
+
logger.trace(f"Setting field '{field_name}' (type: {field_type_fullname}) with value [{value}] (type: {Typing.get_object_class_fullname(value)})")
|
|
757
|
+
try:
|
|
758
|
+
self.__set_object_value(field_obj, value)
|
|
759
|
+
except HAException as exc:
|
|
760
|
+
raise TechnicalException(f"Unmanaged set of value [{value}] (type: {Typing.get_object_class_fullname(value)}) in field of type '{field_type_fullname}' (field '{field_name}' in object of type '{self.get_object_type_fullname(obj)}' [{obj}])\n -> {exc.message}") from exc
|
|
761
|
+
except Exception as exc:
|
|
762
|
+
raise TechnicalException(f"Unmanaged set of value [{value}] (type: {Typing.get_object_class_fullname(value)}) in field of type '{field_type_fullname}' (field '{field_name}' in object of type '{self.get_object_type_fullname(obj)}' [{obj}])\n -> {str(exc)}") from exc
|
|
763
|
+
elif self.__has_object_field(obj, field_name=field_name):
|
|
764
|
+
if create_field:
|
|
765
|
+
field_type_fullname = self.__get_object_field_type_fullname(obj, field_name)
|
|
766
|
+
if isinstance(field_type_fullname, int):
|
|
767
|
+
self.__set_object_field_attr(obj, field_name, value)
|
|
768
|
+
else:
|
|
769
|
+
res = self.new_object(field_type_fullname)
|
|
770
|
+
try:
|
|
771
|
+
self.__set_object_value(res, value)
|
|
772
|
+
except Exception as exc:
|
|
773
|
+
raise TechnicalException(f"Unmanaged set of value [{value}] (type: {Typing.get_object_class_fullname(value)}) in field of type '{field_type_fullname}' (field '{field_name}' in object of type '{self.get_object_type_fullname(obj)}' [{obj}])\n -> {exc.message}") from exc
|
|
774
|
+
setattr(obj, field_name, res)
|
|
775
|
+
else:
|
|
776
|
+
raise FunctionalException(f"Field '{field_name}' exists in type '{self.get_object_type_fullname(obj)}' but not in instance [{obj}]")
|
|
777
|
+
else:
|
|
778
|
+
raise FunctionalException(f"Field '{field_name}' doesn't exist in type '{self.get_object_type_fullname(obj)}'")
|
|
779
|
+
except (FunctionalException, TechnicalException):
|
|
780
|
+
raise
|
|
781
|
+
except Exception as exc:
|
|
782
|
+
if hasattr(obj, field_name):
|
|
783
|
+
field_obj = getattr(obj, field_name)
|
|
784
|
+
raise TechnicalException(f"Failed to set field '{field_name}' (type: '{Typing.get_object_class_fullname(field_obj)}') with value [{value}] (type '{Typing.get_object_class_fullname(value)}')") from exc
|
|
785
|
+
else:
|
|
786
|
+
raise TechnicalException(f"Failed to set field '{field_name}' (type: Unknown) with value [{value}] (type '{Typing.get_object_class_fullname(value)}')") from exc
|
|
787
|
+
|
|
788
|
+
def __set_object_field_attr(self, obj, field_name, value):
|
|
789
|
+
if value is None:
|
|
790
|
+
obj.ClearField(field_name)
|
|
791
|
+
else:
|
|
792
|
+
setattr(obj, field_name, value)
|
|
793
|
+
|
|
794
|
+
def __get_enum_name_if_field_is_enum(self, value, field_descriptor=None, obj=None, field_name=None):
|
|
795
|
+
if field_descriptor is None:
|
|
796
|
+
field_descriptor = self.__get_object_field_descriptor(obj, field_name)
|
|
797
|
+
if field_descriptor.enum_type is not None:
|
|
798
|
+
enum_name = self.__get_enum_name(value, enum_type_descriptor=field_descriptor.enum_type)
|
|
799
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
800
|
+
logger.trace(f"Getting enum field '{field_descriptor.name}' (type: {field_descriptor.enum_type} ; full_name: {field_descriptor.full_name}): value [{value}] -> name [{enum_name}]")
|
|
801
|
+
return enum_name
|
|
802
|
+
else:
|
|
803
|
+
return value
|
|
804
|
+
|
|
805
|
+
def __get_enum_name(self, name_or_value, enum_type=None, enum_type_descriptor=None):
|
|
806
|
+
if enum_type is None and enum_type_descriptor is None:
|
|
807
|
+
raise TechnicalException(f"Parameter 'enum_type' or 'enum_type_descriptor' must be defined")
|
|
808
|
+
if enum_type is not None:
|
|
809
|
+
enum_type_descriptor = enum_type.DESCRIPTOR
|
|
810
|
+
|
|
811
|
+
if isinstance(name_or_value, str):
|
|
812
|
+
return name_or_value
|
|
813
|
+
elif isinstance(name_or_value, int):
|
|
814
|
+
if name_or_value in enum_type_descriptor.values_by_number:
|
|
815
|
+
return self.__get_enum_name_for_value(enum_type_descriptor, name_or_value)
|
|
816
|
+
else:
|
|
817
|
+
raise FunctionalException(f"Enum type '{enum_type_descriptor.full_name}' has no value '{name_or_value}' (possible values: {[k for k in enum_type_descriptor.values_by_number]})")
|
|
818
|
+
elif self.is_object_repeated(name_or_value):
|
|
819
|
+
return [self.__get_enum_name(v, enum_type_descriptor=enum_type_descriptor) for v in name_or_value]
|
|
820
|
+
else:
|
|
821
|
+
raise TechnicalException(f"Unexpected value type '{Typing.get_object_class_fullname(name_or_value)}'")
|
|
822
|
+
|
|
823
|
+
def __get_enum_name_for_value(self, enum_type_descriptor, value):
|
|
824
|
+
enum_type_fullname = self.get_object_type_fullname(descriptor=enum_type_descriptor)
|
|
825
|
+
if not enum_type_fullname in self.__enum_data_by_fullname:
|
|
826
|
+
self.__load_enum_data(enum_type_fullname, enum_type_descriptor)
|
|
827
|
+
return self.__enum_data_by_fullname[enum_type_fullname].values_by_number[value].name
|
|
828
|
+
|
|
829
|
+
def __get_enum_value(self, name_or_value, enum_type=None, enum_type_descriptor=None):
|
|
830
|
+
if enum_type is None and enum_type_descriptor is None:
|
|
831
|
+
raise TechnicalException(f"Parameter 'enum_type' or 'enum_type_descriptor' must be defined")
|
|
832
|
+
if enum_type is not None:
|
|
833
|
+
enum_type_descriptor = enum_type.DESCRIPTOR
|
|
834
|
+
|
|
835
|
+
if isinstance(name_or_value, str):
|
|
836
|
+
if name_or_value in enum_type_descriptor.values_by_name:
|
|
837
|
+
return enum_type_descriptor.values_by_name[name_or_value].number
|
|
838
|
+
else:
|
|
839
|
+
raise FunctionalException(f"Enum type '{enum_type_descriptor.full_name}' has no name '{name_or_value}' (possible names: {[k for k in enum_type_descriptor.values_by_name]})")
|
|
840
|
+
else:
|
|
841
|
+
return name_or_value
|
|
842
|
+
|
|
843
|
+
def __load_enum_data(self, enum_type_fullname, enum_type_descriptor):
|
|
844
|
+
if enum_type_fullname in self.__enum_data_by_fullname:
|
|
845
|
+
raise TechnicalException(f"Data of enum type '{enum_type_fullname}' was already loaded")
|
|
846
|
+
data = NamedTuple('EnumData', values_by_number=dict)
|
|
847
|
+
data.values_by_number = {}
|
|
848
|
+
for value in enum_type_descriptor.values:
|
|
849
|
+
if value.number not in data.values_by_number or value.index > data.values_by_number[value.number].index:
|
|
850
|
+
data.values_by_number[value.number] = value
|
|
851
|
+
self.__enum_data_by_fullname[enum_type_fullname] = data
|
|
852
|
+
|
|
853
|
+
def __set_object_value(self, field_obj, value, raise_exception=True):
|
|
854
|
+
res = False
|
|
855
|
+
for hpt in self.__registered_types:
|
|
856
|
+
if hpt.is_instance_of(field_obj):
|
|
857
|
+
res = hpt.set_object_value(field_obj, value, raise_exception=raise_exception)
|
|
858
|
+
if res:
|
|
859
|
+
break
|
|
860
|
+
|
|
861
|
+
if not res and raise_exception:
|
|
862
|
+
field_classes = inspect.getmro(type(field_obj))
|
|
863
|
+
registered_types_str = ', '.join([f"{t} ({t.protobuf_class()})" for t in self.__registered_types])
|
|
864
|
+
raise TechnicalException(f"Failed to manage type of field {Typing.get_object_class_fullname(field_obj)} (classes: {field_classes}) with registered types (and internal types): {registered_types_str}")
|
|
865
|
+
return res
|
|
866
|
+
|
|
867
|
+
def __set_object_repeated_field(self, obj, field_name, values, add_index=False):
|
|
868
|
+
if not isinstance(values, list):
|
|
869
|
+
raise FunctionalException(f"For repeated field '{field_name}', parameter 'values' is not a list (type: {Typing.get_object_class_fullname(values)})")
|
|
870
|
+
|
|
871
|
+
for index, value in enumerate(values):
|
|
872
|
+
self.__set_object_repeated_field_by_index(obj, field_name, index, value, add_index)
|
|
873
|
+
|
|
874
|
+
def __set_object_repeated_field_by_index(self, obj, field_name, index, value, add_index=False):
|
|
875
|
+
repeated_field_obj = getattr(obj, field_name)
|
|
876
|
+
if not ProtobufMessages.is_object_repeated(repeated_field_obj):
|
|
877
|
+
raise FunctionalException(f"Field '{field_name}' is not a repeated in type '{self.get_object_type_fullname(obj)}'")
|
|
878
|
+
self.__check_field_value_to_set_is_valid(value)
|
|
879
|
+
|
|
880
|
+
field_descr = self.__get_object_field_descriptor(obj, field_name)
|
|
881
|
+
if field_descr.message_type is not None:
|
|
882
|
+
# Get field object at given index
|
|
883
|
+
if len(repeated_field_obj) < index + 1:
|
|
884
|
+
if add_index:
|
|
885
|
+
for _ in range(index + 1 - len(repeated_field_obj)):
|
|
886
|
+
obj_at_index = repeated_field_obj.add()
|
|
887
|
+
else:
|
|
888
|
+
raise FunctionalException(f"Index {index} exceeds repeated length {len(repeated_field_obj)} (field '{field_name}' in type '{self.get_object_type_fullname(obj)}')")
|
|
889
|
+
else:
|
|
890
|
+
obj_at_index = repeated_field_obj[index]
|
|
891
|
+
|
|
892
|
+
# Set field object value
|
|
893
|
+
try:
|
|
894
|
+
self.__set_object_value(obj_at_index, value)
|
|
895
|
+
except Exception as exc:
|
|
896
|
+
raise TechnicalException(f"Unmanaged set of value [{value}] (type: {Typing.get_object_class_fullname(value)}) in repeated field of type '{self.get_object_type_fullname(obj_at_index)}' (at index {index} of field '{field_name}' in object of type '{self.get_object_type_fullname(obj)}' [{obj}])\n -> {exc.message}") from exc
|
|
897
|
+
else:
|
|
898
|
+
if field_descr.enum_type is not None:
|
|
899
|
+
value_to_set = self.__get_enum_value(value, enum_type_descriptor=field_descr.enum_type)
|
|
900
|
+
else:
|
|
901
|
+
value_to_set = value
|
|
902
|
+
|
|
903
|
+
if len(repeated_field_obj) < index:
|
|
904
|
+
if add_index:
|
|
905
|
+
for _ in range(index - len(repeated_field_obj)):
|
|
906
|
+
repeated_field_obj.append(type(value)())
|
|
907
|
+
else:
|
|
908
|
+
raise FunctionalException(f"Index {index} exceeds repeated length {len(repeated_field_obj)} (field '{field_name}' in object [{obj}])")
|
|
909
|
+
|
|
910
|
+
if len(repeated_field_obj) == index:
|
|
911
|
+
if add_index:
|
|
912
|
+
try:
|
|
913
|
+
repeated_field_obj.append(value_to_set)
|
|
914
|
+
except Exception as exc:
|
|
915
|
+
raise TechnicalException(f"Failed to add value [{value_to_set}] in repeated field at index {index} (field '{field_name}' in type '{self.get_object_type_fullname(obj)}')") from exc
|
|
916
|
+
else:
|
|
917
|
+
raise FunctionalException(f"Index {index} exceeds repeated length {len(repeated_field_obj)} (field '{field_name}' in type '{self.get_object_type_fullname(obj)}')")
|
|
918
|
+
else:
|
|
919
|
+
try:
|
|
920
|
+
repeated_field_obj[index] = value_to_set
|
|
921
|
+
except Exception as exc:
|
|
922
|
+
raise TechnicalException(f"Failed to set value [{value_to_set}] in repeated field at index {index} (field '{field_name}' in type '{self.get_object_type_fullname(obj)}')") from exc
|
|
923
|
+
|
|
924
|
+
def __split_attribute_fullname(self, attr_fullname):
|
|
925
|
+
m = self.__regex_attribute_fullname.match(attr_fullname)
|
|
926
|
+
res = [m.group(1), m.group(2)]
|
|
927
|
+
# logger.trace(f"++++++++++ __split_attribute_fullname('{attr_fullname}') => {res}")
|
|
928
|
+
return res
|
|
929
|
+
|
|
930
|
+
def __represent_descriptor(self, descr, indent=0):
|
|
931
|
+
res_str = [str(type(descr))]
|
|
932
|
+
for name, value in Typing.get_object_attributes(descr):
|
|
933
|
+
if "_by_" in name:
|
|
934
|
+
res_str.append(f" {name}:")
|
|
935
|
+
for el in value:
|
|
936
|
+
res_str.append(f" {el}: {self.__represent_descriptor(value[el], 8) if 'Descriptor' in str(type(value[el])) else value[el]}")
|
|
937
|
+
else:
|
|
938
|
+
# if name == "containing_type":
|
|
939
|
+
res_str.append(f" {name}: {value}")
|
|
940
|
+
# else:
|
|
941
|
+
# res_str.append(f" {name}: {self.__represent_descriptor(value, 4) if 'Descriptor' in str(type(value)) else value}")
|
|
942
|
+
return Tools.indent_string(indent, "\n".join(res_str))
|
|
943
|
+
|
|
944
|
+
def _register_types(self):
|
|
945
|
+
# Duration must be registered before Message
|
|
946
|
+
from holado_protobuf.ipc.protobuf.types.google.protobuf import Duration as hpt_Duration
|
|
947
|
+
self.register_type(hpt_Duration)
|
|
948
|
+
|
|
949
|
+
# Timestamp must be registered before Message
|
|
950
|
+
from holado_protobuf.ipc.protobuf.types.google.protobuf import Timestamp as hpt_Timestamp
|
|
951
|
+
self.register_type(hpt_Timestamp)
|
|
952
|
+
|
|
953
|
+
from holado_protobuf.ipc.protobuf.types.google.protobuf import Message as hpt_Message
|
|
954
|
+
self.register_type(hpt_Message)
|
|
955
|
+
|
|
956
|
+
def register_type(self, protobuf_type, index=None):
|
|
957
|
+
"""
|
|
958
|
+
Register a holado protobuf type (subclass of holado_protobuf.ipc.protobuf.abstracts.type.Type)
|
|
959
|
+
"""
|
|
960
|
+
if protobuf_type in self.__registered_types:
|
|
961
|
+
raise TechnicalException(f"Protobuf type '{protobuf_type.__class__.__name__}' is already registered")
|
|
962
|
+
|
|
963
|
+
if index is not None:
|
|
964
|
+
self.__registered_types.insert(index, protobuf_type)
|
|
965
|
+
else:
|
|
966
|
+
self.__registered_types.append(protobuf_type)
|
|
967
|
+
|
|
968
|
+
|