holado 0.2.1__py3-none-any.whl → 0.2.3__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.

Potentially problematic release.


This version of holado might be problematic. Click here for more details.

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