Best JavaScript code snippet using chai
cc_toolchain_config.bzl
Source:cc_toolchain_config.bzl
1"""cc_toolchain_config rule for configuring CUDA toolchains on Linux, Mac, and Windows."""2load(3 "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",4 "action_config",5 "env_entry",6 "env_set",7 "feature",8 "feature_set",9 "flag_group",10 "flag_set",11 "tool",12 "tool_path",13 "variable_with_value",14)15load(16 "@bazel_tools//tools/build_defs/cc:action_names.bzl",17 "ASSEMBLE_ACTION_NAME",18 "CC_FLAGS_MAKE_VARIABLE_ACTION_NAME",19 "CLIF_MATCH_ACTION_NAME",20 "CPP_COMPILE_ACTION_NAME",21 "CPP_HEADER_PARSING_ACTION_NAME",22 "CPP_LINK_DYNAMIC_LIBRARY_ACTION_NAME",23 "CPP_LINK_EXECUTABLE_ACTION_NAME",24 "CPP_LINK_NODEPS_DYNAMIC_LIBRARY_ACTION_NAME",25 "CPP_LINK_STATIC_LIBRARY_ACTION_NAME",26 "CPP_MODULE_CODEGEN_ACTION_NAME",27 "CPP_MODULE_COMPILE_ACTION_NAME",28 "C_COMPILE_ACTION_NAME",29 "LINKSTAMP_COMPILE_ACTION_NAME",30 "LTO_BACKEND_ACTION_NAME",31 "LTO_INDEXING_ACTION_NAME",32 "OBJCPP_COMPILE_ACTION_NAME",33 "OBJCPP_EXECUTABLE_ACTION_NAME",34 "OBJC_ARCHIVE_ACTION_NAME",35 "OBJC_COMPILE_ACTION_NAME",36 "OBJC_EXECUTABLE_ACTION_NAME",37 "OBJC_FULLY_LINK_ACTION_NAME",38 "PREPROCESS_ASSEMBLE_ACTION_NAME",39 "STRIP_ACTION_NAME",40)41ACTION_NAMES = struct(42 c_compile = C_COMPILE_ACTION_NAME,43 cpp_compile = CPP_COMPILE_ACTION_NAME,44 linkstamp_compile = LINKSTAMP_COMPILE_ACTION_NAME,45 cc_flags_make_variable = CC_FLAGS_MAKE_VARIABLE_ACTION_NAME,46 cpp_module_codegen = CPP_MODULE_CODEGEN_ACTION_NAME,47 cpp_header_parsing = CPP_HEADER_PARSING_ACTION_NAME,48 cpp_module_compile = CPP_MODULE_COMPILE_ACTION_NAME,49 assemble = ASSEMBLE_ACTION_NAME,50 preprocess_assemble = PREPROCESS_ASSEMBLE_ACTION_NAME,51 lto_indexing = LTO_INDEXING_ACTION_NAME,52 lto_backend = LTO_BACKEND_ACTION_NAME,53 cpp_link_executable = CPP_LINK_EXECUTABLE_ACTION_NAME,54 cpp_link_dynamic_library = CPP_LINK_DYNAMIC_LIBRARY_ACTION_NAME,55 cpp_link_nodeps_dynamic_library = CPP_LINK_NODEPS_DYNAMIC_LIBRARY_ACTION_NAME,56 cpp_link_static_library = CPP_LINK_STATIC_LIBRARY_ACTION_NAME,57 strip = STRIP_ACTION_NAME,58 objc_archive = OBJC_ARCHIVE_ACTION_NAME,59 objc_compile = OBJC_COMPILE_ACTION_NAME,60 objc_executable = OBJC_EXECUTABLE_ACTION_NAME,61 objc_fully_link = OBJC_FULLY_LINK_ACTION_NAME,62 objcpp_compile = OBJCPP_COMPILE_ACTION_NAME,63 objcpp_executable = OBJCPP_EXECUTABLE_ACTION_NAME,64 clif_match = CLIF_MATCH_ACTION_NAME,65 objcopy_embed_data = "objcopy_embed_data",66 ld_embed_data = "ld_embed_data",67)68def _impl(ctx):69 if (ctx.attr.cpu == "darwin"):70 toolchain_identifier = "local_darwin"71 elif (ctx.attr.cpu == "local"):72 toolchain_identifier = "local_linux"73 elif (ctx.attr.cpu == "x64_windows"):74 toolchain_identifier = "local_windows"75 else:76 fail("Unreachable")77 host_system_name = "local"78 target_system_name = "local"79 if (ctx.attr.cpu == "darwin"):80 target_cpu = "darwin"81 elif (ctx.attr.cpu == "local"):82 target_cpu = "local"83 elif (ctx.attr.cpu == "x64_windows"):84 target_cpu = "x64_windows"85 else:86 fail("Unreachable")87 if (ctx.attr.cpu == "local"):88 target_libc = "local"89 elif (ctx.attr.cpu == "darwin"):90 target_libc = "macosx"91 elif (ctx.attr.cpu == "x64_windows"):92 target_libc = "msvcrt"93 else:94 fail("Unreachable")95 if (ctx.attr.cpu == "darwin" or96 ctx.attr.cpu == "local"):97 compiler = "compiler"98 elif (ctx.attr.cpu == "x64_windows"):99 compiler = "msvc-cl"100 else:101 fail("Unreachable")102 abi_version = "local"103 abi_libc_version = "local"104 cc_target_os = None105 builtin_sysroot = None106 all_link_actions = [107 ACTION_NAMES.cpp_link_executable,108 ACTION_NAMES.cpp_link_dynamic_library,109 ACTION_NAMES.cpp_link_nodeps_dynamic_library,110 ]111 cpp_link_dynamic_library_action = action_config(112 action_name = ACTION_NAMES.cpp_link_dynamic_library,113 implies = [114 "nologo",115 "shared_flag",116 "linkstamps",117 "output_execpath_flags",118 "input_param_flags",119 "user_link_flags",120 "linker_subsystem_flag",121 "linker_param_file",122 "msvc_env",123 "no_stripping",124 "has_configured_linker_path",125 "def_file",126 ],127 tools = [tool(path = ctx.attr.msvc_link_path)],128 )129 cpp_link_nodeps_dynamic_library_action = action_config(130 action_name = ACTION_NAMES.cpp_link_nodeps_dynamic_library,131 implies = [132 "nologo",133 "shared_flag",134 "linkstamps",135 "output_execpath_flags",136 "input_param_flags",137 "user_link_flags",138 "linker_subsystem_flag",139 "linker_param_file",140 "msvc_env",141 "no_stripping",142 "has_configured_linker_path",143 "def_file",144 ],145 tools = [tool(path = ctx.attr.msvc_link_path)],146 )147 cpp_link_static_library_action = action_config(148 action_name = ACTION_NAMES.cpp_link_static_library,149 implies = [150 "nologo",151 "archiver_flags",152 "input_param_flags",153 "linker_param_file",154 "msvc_env",155 ],156 tools = [tool(path = ctx.attr.msvc_lib_path)],157 )158 assemble_action = action_config(159 action_name = ACTION_NAMES.assemble,160 implies = [161 "compiler_input_flags",162 "compiler_output_flags",163 "nologo",164 "msvc_env",165 "sysroot",166 ],167 tools = [tool(path = ctx.attr.msvc_ml_path)],168 )169 preprocess_assemble_action = action_config(170 action_name = ACTION_NAMES.preprocess_assemble,171 implies = [172 "compiler_input_flags",173 "compiler_output_flags",174 "nologo",175 "msvc_env",176 "sysroot",177 ],178 tools = [tool(path = ctx.attr.msvc_ml_path)],179 )180 c_compile_action = action_config(181 action_name = ACTION_NAMES.c_compile,182 implies = [183 "compiler_input_flags",184 "compiler_output_flags",185 "nologo",186 "msvc_env",187 "parse_showincludes",188 "user_compile_flags",189 "sysroot",190 "unfiltered_compile_flags",191 ],192 tools = [tool(path = ctx.attr.msvc_cl_path)],193 )194 cpp_compile_action = action_config(195 action_name = ACTION_NAMES.cpp_compile,196 implies = [197 "compiler_input_flags",198 "compiler_output_flags",199 "nologo",200 "msvc_env",201 "parse_showincludes",202 "user_compile_flags",203 "sysroot",204 "unfiltered_compile_flags",205 ],206 tools = [tool(path = ctx.attr.msvc_cl_path)],207 )208 cpp_link_executable_action = action_config(209 action_name = ACTION_NAMES.cpp_link_executable,210 implies = [211 "nologo",212 "linkstamps",213 "output_execpath_flags",214 "input_param_flags",215 "user_link_flags",216 "linker_subsystem_flag",217 "linker_param_file",218 "msvc_env",219 "no_stripping",220 ],221 tools = [tool(path = ctx.attr.msvc_link_path)],222 )223 if (ctx.attr.cpu == "darwin" or224 ctx.attr.cpu == "local"):225 action_configs = []226 elif (ctx.attr.cpu == "x64_windows"):227 action_configs = [228 assemble_action,229 preprocess_assemble_action,230 c_compile_action,231 cpp_compile_action,232 cpp_link_executable_action,233 cpp_link_dynamic_library_action,234 cpp_link_nodeps_dynamic_library_action,235 cpp_link_static_library_action,236 ]237 else:238 fail("Unreachable")239 no_windows_export_all_symbols_feature = feature(name = "no_windows_export_all_symbols")240 pic_feature = feature(241 name = "pic",242 enabled = True,243 flag_sets = [244 flag_set(245 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],246 flag_groups = [247 flag_group(flags = ["-fPIC"], expand_if_available = "pic"),248 flag_group(249 flags = ["-fPIE"],250 expand_if_not_available = "pic",251 ),252 ],253 ),254 ],255 )256 preprocessor_defines_feature = feature(257 name = "preprocessor_defines",258 enabled = True,259 flag_sets = [260 flag_set(261 actions = [262 ACTION_NAMES.assemble,263 ACTION_NAMES.preprocess_assemble,264 ACTION_NAMES.c_compile,265 ACTION_NAMES.cpp_compile,266 ACTION_NAMES.cpp_header_parsing,267 ACTION_NAMES.cpp_module_compile,268 ],269 flag_groups = [270 flag_group(271 flags = ["/D%{preprocessor_defines}"],272 iterate_over = "preprocessor_defines",273 ),274 ],275 ),276 ],277 )278 generate_pdb_file_feature = feature(279 name = "generate_pdb_file",280 requires = [281 feature_set(features = ["dbg"]),282 feature_set(features = ["fastbuild"]),283 ],284 )285 linkstamps_feature = feature(286 name = "linkstamps",287 flag_sets = [288 flag_set(289 actions = all_link_actions,290 flag_groups = [291 flag_group(292 flags = ["%{linkstamp_paths}"],293 iterate_over = "linkstamp_paths",294 expand_if_available = "linkstamp_paths",295 ),296 ],297 ),298 ],299 )300 unfiltered_compile_flags_feature = feature(301 name = "unfiltered_compile_flags",302 flag_sets = ([303 flag_set(304 actions = [305 ACTION_NAMES.preprocess_assemble,306 ACTION_NAMES.c_compile,307 ACTION_NAMES.cpp_compile,308 ACTION_NAMES.cpp_header_parsing,309 ACTION_NAMES.cpp_module_compile,310 ACTION_NAMES.cpp_module_codegen,311 ],312 flag_groups = [313 flag_group(314 flags = ctx.attr.host_unfiltered_compile_flags,315 ),316 ],317 ),318 ] if ctx.attr.host_unfiltered_compile_flags else []),319 )320 determinism_feature = feature(321 name = "determinism",322 flag_sets = [323 flag_set(324 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],325 flag_groups = [326 flag_group(327 flags = [328 "-Wno-builtin-macro-redefined",329 "-D__DATE__=\"redacted\"",330 "-D__TIMESTAMP__=\"redacted\"",331 "-D__TIME__=\"redacted\"",332 ],333 ),334 ],335 ),336 ],337 )338 nologo_feature = feature(339 name = "nologo",340 flag_sets = [341 flag_set(342 actions = [343 ACTION_NAMES.c_compile,344 ACTION_NAMES.cpp_compile,345 ACTION_NAMES.cpp_module_compile,346 ACTION_NAMES.cpp_module_codegen,347 ACTION_NAMES.cpp_header_parsing,348 ACTION_NAMES.assemble,349 ACTION_NAMES.preprocess_assemble,350 ACTION_NAMES.cpp_link_executable,351 ACTION_NAMES.cpp_link_dynamic_library,352 ACTION_NAMES.cpp_link_nodeps_dynamic_library,353 ACTION_NAMES.cpp_link_static_library,354 ],355 flag_groups = [flag_group(flags = ["/nologo"])],356 ),357 ],358 )359 supports_pic_feature = feature(name = "supports_pic", enabled = True)360 output_execpath_flags_feature = feature(361 name = "output_execpath_flags",362 flag_sets = [363 flag_set(364 actions = all_link_actions,365 flag_groups = [366 flag_group(367 flags = ["/OUT:%{output_execpath}"],368 expand_if_available = "output_execpath",369 ),370 ],371 ),372 ],373 )374 default_link_flags_feature = feature(375 name = "default_link_flags",376 enabled = True,377 flag_sets = [378 flag_set(379 actions = all_link_actions,380 flag_groups = [flag_group(flags = ["/MACHINE:X64"])],381 ),382 ],383 )384 if (ctx.attr.cpu == "local"):385 hardening_feature = feature(386 name = "hardening",387 flag_sets = [388 flag_set(389 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],390 flag_groups = [391 flag_group(392 flags = [393 "-U_FORTIFY_SOURCE",394 "-D_FORTIFY_SOURCE=1",395 "-fstack-protector",396 ],397 ),398 ],399 ),400 flag_set(401 actions = [402 ACTION_NAMES.cpp_link_dynamic_library,403 ACTION_NAMES.cpp_link_nodeps_dynamic_library,404 ],405 flag_groups = [flag_group(flags = ["-Wl,-z,relro,-z,now"])],406 ),407 flag_set(408 actions = [ACTION_NAMES.cpp_link_executable],409 flag_groups = [flag_group(flags = ["-pie", "-Wl,-z,relro,-z,now"])],410 ),411 ],412 )413 elif (ctx.attr.cpu == "darwin"):414 hardening_feature = feature(415 name = "hardening",416 flag_sets = [417 flag_set(418 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],419 flag_groups = [420 flag_group(421 flags = [422 "-U_FORTIFY_SOURCE",423 "-D_FORTIFY_SOURCE=1",424 "-fstack-protector",425 ],426 ),427 ],428 ),429 flag_set(430 actions = [ACTION_NAMES.cpp_link_executable],431 flag_groups = [flag_group(flags = ["-pie"])],432 ),433 ],434 )435 else:436 hardening_feature = None437 supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True)438 targets_windows_feature = feature(439 name = "targets_windows",440 enabled = True,441 implies = ["copy_dynamic_libraries_to_binary"],442 )443 msvc_env_feature = feature(444 name = "msvc_env",445 env_sets = [446 env_set(447 actions = [448 ACTION_NAMES.c_compile,449 ACTION_NAMES.cpp_compile,450 ACTION_NAMES.cpp_module_compile,451 ACTION_NAMES.cpp_module_codegen,452 ACTION_NAMES.cpp_header_parsing,453 ACTION_NAMES.assemble,454 ACTION_NAMES.preprocess_assemble,455 ACTION_NAMES.cpp_link_executable,456 ACTION_NAMES.cpp_link_dynamic_library,457 ACTION_NAMES.cpp_link_nodeps_dynamic_library,458 ACTION_NAMES.cpp_link_static_library,459 ],460 env_entries = [461 env_entry(key = "PATH", value = ctx.attr.msvc_env_path),462 env_entry(463 key = "INCLUDE",464 value = ctx.attr.msvc_env_include,465 ),466 env_entry(key = "LIB", value = ctx.attr.msvc_env_lib),467 env_entry(key = "TMP", value = ctx.attr.msvc_env_tmp),468 env_entry(key = "TEMP", value = ctx.attr.msvc_env_tmp),469 ],470 ),471 ],472 )473 linker_subsystem_flag_feature = feature(474 name = "linker_subsystem_flag",475 flag_sets = [476 flag_set(477 actions = all_link_actions,478 flag_groups = [flag_group(flags = ["/SUBSYSTEM:CONSOLE"])],479 ),480 ],481 )482 dynamic_link_msvcrt_no_debug_feature = feature(483 name = "dynamic_link_msvcrt_no_debug",484 flag_sets = [485 flag_set(486 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],487 flag_groups = [flag_group(flags = ["/MD"])],488 ),489 flag_set(490 actions = all_link_actions,491 flag_groups = [flag_group(flags = ["/DEFAULTLIB:msvcrt.lib"])],492 ),493 ],494 requires = [495 feature_set(features = ["fastbuild"]),496 feature_set(features = ["opt"]),497 ],498 )499 warnings_feature = feature(500 name = "warnings",501 flag_sets = [502 flag_set(503 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],504 flag_groups = [505 flag_group(506 flags = ["-Wall"] + ctx.attr.host_compiler_warnings,507 ),508 ],509 ),510 ],511 )512 dynamic_link_msvcrt_debug_feature = feature(513 name = "dynamic_link_msvcrt_debug",514 flag_sets = [515 flag_set(516 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],517 flag_groups = [flag_group(flags = ["/MDd"])],518 ),519 flag_set(520 actions = all_link_actions,521 flag_groups = [flag_group(flags = ["/DEFAULTLIB:msvcrtd.lib"])],522 ),523 ],524 requires = [feature_set(features = ["dbg"])],525 )526 compiler_output_flags_feature = feature(527 name = "compiler_output_flags",528 flag_sets = [529 flag_set(530 actions = [ACTION_NAMES.assemble],531 flag_groups = [532 flag_group(533 flag_groups = [534 flag_group(535 flags = ["/Fo%{output_file}", "/Zi"],536 expand_if_not_available = "output_preprocess_file",537 ),538 ],539 expand_if_available = "output_file",540 expand_if_not_available = "output_assembly_file",541 ),542 ],543 ),544 flag_set(545 actions = [546 ACTION_NAMES.preprocess_assemble,547 ACTION_NAMES.c_compile,548 ACTION_NAMES.cpp_compile,549 ACTION_NAMES.cpp_header_parsing,550 ACTION_NAMES.cpp_module_compile,551 ACTION_NAMES.cpp_module_codegen,552 ],553 flag_groups = [554 flag_group(555 flag_groups = [556 flag_group(557 flags = ["/Fo%{output_file}"],558 expand_if_not_available = "output_preprocess_file",559 ),560 ],561 expand_if_available = "output_file",562 expand_if_not_available = "output_assembly_file",563 ),564 flag_group(565 flag_groups = [566 flag_group(567 flags = ["/Fa%{output_file}"],568 expand_if_available = "output_assembly_file",569 ),570 ],571 expand_if_available = "output_file",572 ),573 flag_group(574 flag_groups = [575 flag_group(576 flags = ["/P", "/Fi%{output_file}"],577 expand_if_available = "output_preprocess_file",578 ),579 ],580 expand_if_available = "output_file",581 ),582 ],583 ),584 ],585 )586 default_compile_flags_feature = feature(587 name = "default_compile_flags",588 enabled = True,589 flag_sets = [590 flag_set(591 actions = [592 ACTION_NAMES.assemble,593 ACTION_NAMES.preprocess_assemble,594 ACTION_NAMES.linkstamp_compile,595 ACTION_NAMES.c_compile,596 ACTION_NAMES.cpp_compile,597 ACTION_NAMES.cpp_header_parsing,598 ACTION_NAMES.cpp_module_compile,599 ACTION_NAMES.cpp_module_codegen,600 ACTION_NAMES.lto_backend,601 ACTION_NAMES.clif_match,602 ],603 flag_groups = [604 flag_group(605 flags = [606 "/DCOMPILER_MSVC",607 "/DNOMINMAX",608 "/D_WIN32_WINNT=0x0600",609 "/D_CRT_SECURE_NO_DEPRECATE",610 "/D_CRT_SECURE_NO_WARNINGS",611 "/D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS",612 "/bigobj",613 "/Zm500",614 "/J",615 "/Gy",616 "/GF",617 "/EHsc",618 "/wd4351",619 "/wd4291",620 "/wd4250",621 "/wd4996",622 ],623 ),624 ],625 ),626 ],627 )628 static_link_msvcrt_debug_feature = feature(629 name = "static_link_msvcrt_debug",630 flag_sets = [631 flag_set(632 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],633 flag_groups = [flag_group(flags = ["/MTd"])],634 ),635 flag_set(636 actions = all_link_actions,637 flag_groups = [flag_group(flags = ["/DEFAULTLIB:libcmtd.lib"])],638 ),639 ],640 requires = [feature_set(features = ["dbg"])],641 )642 static_link_msvcrt_feature = feature(name = "static_link_msvcrt")643 if (ctx.attr.cpu == "darwin" or644 ctx.attr.cpu == "local"):645 dbg_feature = feature(646 name = "dbg",647 flag_sets = [648 flag_set(649 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],650 flag_groups = [flag_group(flags = ["-g"])],651 ),652 ],653 implies = ["common"],654 )655 elif (ctx.attr.cpu == "x64_windows"):656 dbg_feature = feature(657 name = "dbg",658 flag_sets = [659 flag_set(660 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],661 flag_groups = [flag_group(flags = ["/Od", "/Z7", "/DDEBUG"])],662 ),663 flag_set(664 actions = all_link_actions,665 flag_groups = [flag_group(flags = ["/DEBUG:FULL", "/INCREMENTAL:NO"])],666 ),667 ],668 implies = ["generate_pdb_file"],669 )670 else:671 dbg_feature = None672 undefined_dynamic_feature = feature(673 name = "undefined-dynamic",674 flag_sets = [675 flag_set(676 actions = [677 ACTION_NAMES.cpp_link_dynamic_library,678 ACTION_NAMES.cpp_link_nodeps_dynamic_library,679 ACTION_NAMES.cpp_link_executable,680 ],681 flag_groups = [flag_group(flags = ["-undefined", "dynamic_lookup"])],682 ),683 ],684 )685 parse_showincludes_feature = feature(686 name = "parse_showincludes",687 flag_sets = [688 flag_set(689 actions = [690 ACTION_NAMES.preprocess_assemble,691 ACTION_NAMES.c_compile,692 ACTION_NAMES.cpp_compile,693 ACTION_NAMES.cpp_module_compile,694 ACTION_NAMES.cpp_header_parsing,695 ],696 flag_groups = [flag_group(flags = ["/showIncludes"])],697 ),698 ],699 )700 linker_param_file_feature = feature(701 name = "linker_param_file",702 flag_sets = [703 flag_set(704 actions = all_link_actions +705 [ACTION_NAMES.cpp_link_static_library],706 flag_groups = [707 flag_group(708 flags = ["@%{linker_param_file}"],709 expand_if_available = "linker_param_file",710 ),711 ],712 ),713 ],714 )715 static_link_msvcrt_no_debug_feature = feature(716 name = "static_link_msvcrt_no_debug",717 flag_sets = [718 flag_set(719 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],720 flag_groups = [flag_group(flags = ["/MT"])],721 ),722 flag_set(723 actions = all_link_actions,724 flag_groups = [flag_group(flags = ["/DEFAULTLIB:libcmt.lib"])],725 ),726 ],727 requires = [728 feature_set(features = ["fastbuild"]),729 feature_set(features = ["opt"]),730 ],731 )732 supports_interface_shared_libraries_feature = feature(733 name = "supports_interface_shared_libraries",734 enabled = True,735 )736 disable_assertions_feature = feature(737 name = "disable-assertions",738 flag_sets = [739 flag_set(740 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],741 flag_groups = [flag_group(flags = ["-DNDEBUG"])],742 ),743 ],744 )745 if (ctx.attr.cpu == "x64_windows"):746 fastbuild_feature = feature(747 name = "fastbuild",748 flag_sets = [749 flag_set(750 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],751 flag_groups = [flag_group(flags = ["/Od", "/Z7", "/DDEBUG"])],752 ),753 flag_set(754 actions = all_link_actions,755 flag_groups = [756 flag_group(flags = ["/DEBUG:FASTLINK", "/INCREMENTAL:NO"]),757 ],758 ),759 ],760 implies = ["generate_pdb_file"],761 )762 elif (ctx.attr.cpu == "darwin" or763 ctx.attr.cpu == "local"):764 fastbuild_feature = feature(name = "fastbuild", implies = ["common"])765 else:766 fastbuild_feature = None767 user_compile_flags_feature = feature(768 name = "user_compile_flags",769 flag_sets = [770 flag_set(771 actions = [772 ACTION_NAMES.preprocess_assemble,773 ACTION_NAMES.c_compile,774 ACTION_NAMES.cpp_compile,775 ACTION_NAMES.cpp_header_parsing,776 ACTION_NAMES.cpp_module_compile,777 ACTION_NAMES.cpp_module_codegen,778 ],779 flag_groups = [780 flag_group(781 flags = ["%{user_compile_flags}"],782 iterate_over = "user_compile_flags",783 expand_if_available = "user_compile_flags",784 ),785 ],786 ),787 ],788 )789 compiler_input_flags_feature = feature(790 name = "compiler_input_flags",791 flag_sets = [792 flag_set(793 actions = [794 ACTION_NAMES.assemble,795 ACTION_NAMES.preprocess_assemble,796 ACTION_NAMES.c_compile,797 ACTION_NAMES.cpp_compile,798 ACTION_NAMES.cpp_header_parsing,799 ACTION_NAMES.cpp_module_compile,800 ACTION_NAMES.cpp_module_codegen,801 ],802 flag_groups = [803 flag_group(804 flags = ["/c", "%{source_file}"],805 expand_if_available = "source_file",806 ),807 ],808 ),809 ],810 )811 no_legacy_features_feature = feature(name = "no_legacy_features")812 archiver_flags_feature = feature(813 name = "archiver_flags",814 flag_sets = [815 flag_set(816 actions = [ACTION_NAMES.cpp_link_static_library],817 flag_groups = [818 flag_group(819 flags = ["/OUT:%{output_execpath}"],820 expand_if_available = "output_execpath",821 ),822 ],823 ),824 ],825 )826 redirector_feature = feature(827 name = "redirector",828 enabled = True,829 flag_sets = [830 flag_set(831 actions = [832 ACTION_NAMES.c_compile,833 ACTION_NAMES.cpp_compile,834 ACTION_NAMES.cpp_module_compile,835 ACTION_NAMES.cpp_module_codegen,836 ACTION_NAMES.cpp_header_parsing,837 ACTION_NAMES.assemble,838 ACTION_NAMES.preprocess_assemble,839 ],840 flag_groups = [841 flag_group(842 flags = [843 "-B",844 "external/local_config_cuda/crosstool/windows/msvc_wrapper_for_nvcc.py",845 ],846 ),847 ],848 ),849 ],850 )851 linker_bin_path_feature = feature(852 name = "linker-bin-path",853 flag_sets = [854 flag_set(855 actions = all_link_actions,856 flag_groups = [flag_group(flags = ["-B" + ctx.attr.linker_bin_path])],857 ),858 ],859 )860 if (ctx.attr.cpu == "local"):861 opt_feature = feature(862 name = "opt",863 flag_sets = [864 flag_set(865 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],866 flag_groups = [867 flag_group(868 flags = ["-g0", "-O2", "-ffunction-sections", "-fdata-sections"],869 ),870 ],871 ),872 flag_set(873 actions = [874 ACTION_NAMES.cpp_link_dynamic_library,875 ACTION_NAMES.cpp_link_nodeps_dynamic_library,876 ACTION_NAMES.cpp_link_executable,877 ],878 flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])],879 ),880 ],881 implies = ["common", "disable-assertions"],882 )883 elif (ctx.attr.cpu == "darwin"):884 opt_feature = feature(885 name = "opt",886 flag_sets = [887 flag_set(888 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],889 flag_groups = [890 flag_group(891 flags = ["-g0", "-O2", "-ffunction-sections", "-fdata-sections"],892 ),893 ],894 ),895 ],896 implies = ["common", "disable-assertions"],897 )898 elif (ctx.attr.cpu == "x64_windows"):899 opt_feature = feature(900 name = "opt",901 flag_sets = [902 flag_set(903 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],904 flag_groups = [flag_group(flags = ["/O2", "/DNDEBUG"])],905 ),906 ],907 )908 else:909 opt_feature = None910 include_paths_feature = feature(911 name = "include_paths",912 enabled = True,913 flag_sets = [914 flag_set(915 actions = [916 ACTION_NAMES.assemble,917 ACTION_NAMES.preprocess_assemble,918 ACTION_NAMES.c_compile,919 ACTION_NAMES.cpp_compile,920 ACTION_NAMES.cpp_header_parsing,921 ACTION_NAMES.cpp_module_compile,922 ],923 flag_groups = [924 flag_group(925 flags = ["/I%{quote_include_paths}"],926 iterate_over = "quote_include_paths",927 ),928 flag_group(929 flags = ["/I%{include_paths}"],930 iterate_over = "include_paths",931 ),932 flag_group(933 flags = ["/I%{system_include_paths}"],934 iterate_over = "system_include_paths",935 ),936 ],937 ),938 ],939 )940 shared_flag_feature = feature(941 name = "shared_flag",942 flag_sets = [943 flag_set(944 actions = [945 ACTION_NAMES.cpp_link_dynamic_library,946 ACTION_NAMES.cpp_link_nodeps_dynamic_library,947 ],948 flag_groups = [flag_group(flags = ["/DLL"])],949 ),950 ],951 )952 windows_export_all_symbols_feature = feature(name = "windows_export_all_symbols")953 frame_pointer_feature = feature(954 name = "frame-pointer",955 flag_sets = [956 flag_set(957 actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],958 flag_groups = [flag_group(flags = ["-fno-omit-frame-pointer"])],959 ),960 ],961 )962 build_id_feature = feature(963 name = "build-id",964 flag_sets = [965 flag_set(966 actions = all_link_actions,967 flag_groups = [968 flag_group(969 flags = ["-Wl,--build-id=md5", "-Wl,--hash-style=gnu"],970 ),971 ],972 ),973 ],974 )975 sysroot_feature = feature(976 name = "sysroot",977 flag_sets = [978 flag_set(979 actions = [980 ACTION_NAMES.assemble,981 ACTION_NAMES.preprocess_assemble,982 ACTION_NAMES.c_compile,983 ACTION_NAMES.cpp_compile,984 ACTION_NAMES.cpp_header_parsing,985 ACTION_NAMES.cpp_module_compile,986 ACTION_NAMES.cpp_module_codegen,987 ACTION_NAMES.cpp_link_executable,988 ACTION_NAMES.cpp_link_dynamic_library,989 ACTION_NAMES.cpp_link_nodeps_dynamic_library,990 ],991 flag_groups = [992 flag_group(993 flags = ["--sysroot=%{sysroot}"],994 iterate_over = "sysroot",995 expand_if_available = "sysroot",996 ),997 ],998 ),999 ],1000 )1001 def_file_feature = feature(1002 name = "def_file",1003 flag_sets = [1004 flag_set(1005 actions = all_link_actions,1006 flag_groups = [1007 flag_group(1008 flags = ["/DEF:%{def_file_path}", "/ignore:4070"],1009 expand_if_available = "def_file_path",1010 ),1011 ],1012 ),1013 ],1014 )1015 if (ctx.attr.cpu == "darwin"):1016 stdlib_feature = feature(1017 name = "stdlib",1018 flag_sets = [1019 flag_set(1020 actions = all_link_actions,1021 flag_groups = [flag_group(flags = ["-lc++"])],1022 ),1023 ],1024 )1025 elif (ctx.attr.cpu == "local"):1026 stdlib_feature = feature(1027 name = "stdlib",1028 flag_sets = [1029 flag_set(1030 actions = all_link_actions,1031 flag_groups = [flag_group(flags = ["-lstdc++"])],1032 ),1033 ],1034 )1035 else:1036 stdlib_feature = None1037 no_stripping_feature = feature(name = "no_stripping")1038 alwayslink_feature = feature(1039 name = "alwayslink",1040 flag_sets = [1041 flag_set(1042 actions = [1043 ACTION_NAMES.cpp_link_dynamic_library,1044 ACTION_NAMES.cpp_link_nodeps_dynamic_library,1045 ACTION_NAMES.cpp_link_executable,1046 ],1047 flag_groups = [flag_group(flags = ["-Wl,-no-as-needed"])],1048 ),1049 ],1050 )1051 input_param_flags_feature = feature(1052 name = "input_param_flags",1053 flag_sets = [1054 flag_set(1055 actions = [1056 ACTION_NAMES.cpp_link_dynamic_library,1057 ACTION_NAMES.cpp_link_nodeps_dynamic_library,1058 ],1059 flag_groups = [1060 flag_group(1061 flags = ["/IMPLIB:%{interface_library_output_path}"],1062 expand_if_available = "interface_library_output_path",1063 ),1064 ],1065 ),1066 flag_set(1067 actions = all_link_actions +1068 [ACTION_NAMES.cpp_link_static_library],1069 flag_groups = [1070 flag_group(1071 iterate_over = "libraries_to_link",1072 flag_groups = [1073 flag_group(1074 iterate_over = "libraries_to_link.object_files",1075 flag_groups = [flag_group(flags = ["%{libraries_to_link.object_files}"])],1076 expand_if_equal = variable_with_value(1077 name = "libraries_to_link.type",1078 value = "object_file_group",1079 ),1080 ),1081 flag_group(1082 flag_groups = [flag_group(flags = ["%{libraries_to_link.name}"])],1083 expand_if_equal = variable_with_value(1084 name = "libraries_to_link.type",1085 value = "object_file",1086 ),1087 ),1088 flag_group(1089 flag_groups = [flag_group(flags = ["%{libraries_to_link.name}"])],1090 expand_if_equal = variable_with_value(1091 name = "libraries_to_link.type",1092 value = "interface_library",1093 ),1094 ),1095 flag_group(1096 flag_groups = [1097 flag_group(1098 flags = ["%{libraries_to_link.name}"],1099 expand_if_false = "libraries_to_link.is_whole_archive",1100 ),1101 flag_group(1102 flags = ["/WHOLEARCHIVE:%{libraries_to_link.name}"],1103 expand_if_true = "libraries_to_link.is_whole_archive",1104 ),1105 ],1106 expand_if_equal = variable_with_value(1107 name = "libraries_to_link.type",1108 value = "static_library",1109 ),1110 ),1111 ],1112 expand_if_available = "libraries_to_link",1113 ),1114 ],1115 ),1116 ],1117 )1118 if (ctx.attr.cpu == "local"):1119 no_canonical_prefixes_feature = feature(1120 name = "no-canonical-prefixes",1121 flag_sets = [1122 flag_set(1123 actions = [1124 ACTION_NAMES.c_compile,1125 ACTION_NAMES.cpp_compile,1126 ACTION_NAMES.cpp_link_executable,1127 ACTION_NAMES.cpp_link_dynamic_library,1128 ACTION_NAMES.cpp_link_nodeps_dynamic_library,1129 ],1130 flag_groups = [1131 flag_group(1132 flags = [1133 "-no-canonical-prefixes",1134 ] + ctx.attr.extra_no_canonical_prefixes_flags,1135 ),1136 ],1137 ),1138 ],1139 )1140 elif (ctx.attr.cpu == "darwin"):1141 no_canonical_prefixes_feature = feature(1142 name = "no-canonical-prefixes",1143 flag_sets = [1144 flag_set(1145 actions = [1146 ACTION_NAMES.c_compile,1147 ACTION_NAMES.cpp_compile,1148 ACTION_NAMES.cpp_link_executable,1149 ACTION_NAMES.cpp_link_dynamic_library,1150 ACTION_NAMES.cpp_link_nodeps_dynamic_library,1151 ],1152 flag_groups = [flag_group(flags = ["-no-canonical-prefixes"])],1153 ),1154 ],1155 )1156 else:1157 no_canonical_prefixes_feature = None1158 has_configured_linker_path_feature = feature(name = "has_configured_linker_path")1159 copy_dynamic_libraries_to_binary_feature = feature(name = "copy_dynamic_libraries_to_binary")1160 user_link_flags_feature = feature(1161 name = "user_link_flags",1162 flag_sets = [1163 flag_set(1164 actions = all_link_actions,1165 flag_groups = [1166 flag_group(1167 flags = ["%{user_link_flags}"],1168 iterate_over = "user_link_flags",1169 expand_if_available = "user_link_flags",1170 ),1171 ],1172 ),1173 ],1174 )1175 cpp11_feature = feature(1176 name = "c++11",1177 flag_sets = [1178 flag_set(1179 actions = [ACTION_NAMES.cpp_compile],1180 flag_groups = [flag_group(flags = ["-std=c++11"])],1181 ),1182 ],1183 )1184 if (ctx.attr.cpu == "local"):1185 common_feature = feature(1186 name = "common",1187 implies = [1188 "stdlib",1189 "c++11",1190 "determinism",1191 "alwayslink",1192 "hardening",1193 "warnings",1194 "frame-pointer",1195 "build-id",1196 "no-canonical-prefixes",1197 "linker-bin-path",1198 ],1199 )1200 elif (ctx.attr.cpu == "darwin"):1201 common_feature = feature(1202 name = "common",1203 implies = [1204 "stdlib",1205 "c++11",1206 "determinism",1207 "hardening",1208 "warnings",1209 "frame-pointer",1210 "no-canonical-prefixes",1211 "linker-bin-path",1212 "undefined-dynamic",1213 ],1214 )1215 else:1216 common_feature = None1217 if (ctx.attr.cpu == "local"):1218 features = [1219 cpp11_feature,1220 stdlib_feature,1221 determinism_feature,1222 alwayslink_feature,1223 pic_feature,1224 hardening_feature,1225 warnings_feature,1226 frame_pointer_feature,1227 build_id_feature,1228 no_canonical_prefixes_feature,1229 disable_assertions_feature,1230 linker_bin_path_feature,1231 common_feature,1232 opt_feature,1233 fastbuild_feature,1234 dbg_feature,1235 supports_dynamic_linker_feature,1236 supports_pic_feature,1237 ]1238 elif (ctx.attr.cpu == "darwin"):1239 features = [1240 cpp11_feature,1241 stdlib_feature,1242 determinism_feature,1243 pic_feature,1244 hardening_feature,1245 warnings_feature,1246 frame_pointer_feature,1247 no_canonical_prefixes_feature,1248 disable_assertions_feature,1249 linker_bin_path_feature,1250 undefined_dynamic_feature,1251 common_feature,1252 opt_feature,1253 fastbuild_feature,1254 dbg_feature,1255 supports_dynamic_linker_feature,1256 supports_pic_feature,1257 ]1258 elif (ctx.attr.cpu == "x64_windows"):1259 features = [1260 no_legacy_features_feature,1261 redirector_feature,1262 nologo_feature,1263 has_configured_linker_path_feature,1264 no_stripping_feature,1265 targets_windows_feature,1266 copy_dynamic_libraries_to_binary_feature,1267 default_compile_flags_feature,1268 msvc_env_feature,1269 include_paths_feature,1270 preprocessor_defines_feature,1271 parse_showincludes_feature,1272 generate_pdb_file_feature,1273 shared_flag_feature,1274 linkstamps_feature,1275 output_execpath_flags_feature,1276 archiver_flags_feature,1277 input_param_flags_feature,1278 linker_subsystem_flag_feature,1279 user_link_flags_feature,1280 default_link_flags_feature,1281 linker_param_file_feature,1282 static_link_msvcrt_feature,1283 static_link_msvcrt_no_debug_feature,1284 dynamic_link_msvcrt_no_debug_feature,1285 static_link_msvcrt_debug_feature,1286 dynamic_link_msvcrt_debug_feature,1287 dbg_feature,1288 fastbuild_feature,1289 opt_feature,1290 user_compile_flags_feature,1291 sysroot_feature,1292 unfiltered_compile_flags_feature,1293 compiler_output_flags_feature,1294 compiler_input_flags_feature,1295 def_file_feature,1296 windows_export_all_symbols_feature,1297 no_windows_export_all_symbols_feature,1298 supports_dynamic_linker_feature,1299 supports_interface_shared_libraries_feature,1300 ]1301 else:1302 fail("Unreachable")1303 cxx_builtin_include_directories = ctx.attr.builtin_include_directories1304 if (ctx.attr.cpu == "x64_windows"):1305 tool_paths = [1306 tool_path(name = "ar", path = ctx.attr.msvc_lib_path),1307 tool_path(name = "ml", path = ctx.attr.msvc_ml_path),1308 tool_path(name = "cpp", path = ctx.attr.msvc_cl_path),1309 tool_path(name = "gcc", path = ctx.attr.msvc_cl_path),1310 tool_path(name = "gcov", path = "wrapper/bin/msvc_nop.bat"),1311 tool_path(name = "ld", path = ctx.attr.msvc_link_path),1312 tool_path(name = "nm", path = "wrapper/bin/msvc_nop.bat"),1313 tool_path(1314 name = "objcopy",1315 path = "wrapper/bin/msvc_nop.bat",1316 ),1317 tool_path(1318 name = "objdump",1319 path = "wrapper/bin/msvc_nop.bat",1320 ),1321 tool_path(1322 name = "strip",1323 path = "wrapper/bin/msvc_nop.bat",1324 ),1325 ]1326 elif (ctx.attr.cpu == "local"):1327 tool_paths = [1328 tool_path(name = "gcc", path = ctx.attr.host_compiler_path),1329 tool_path(name = "ar", path = ctx.attr.host_compiler_prefix + "/ar"),1330 tool_path(name = "compat-ld", path = ctx.attr.host_compiler_prefix + "/ld"),1331 tool_path(name = "cpp", path = ctx.attr.host_compiler_prefix + "/cpp"),1332 tool_path(name = "dwp", path = ctx.attr.host_compiler_prefix + "/dwp"),1333 tool_path(name = "gcov", path = ctx.attr.host_compiler_prefix + "/gcov"),1334 tool_path(name = "ld", path = ctx.attr.host_compiler_prefix + "/ld"),1335 tool_path(name = "nm", path = ctx.attr.host_compiler_prefix + "/nm"),1336 tool_path(name = "objcopy", path = ctx.attr.host_compiler_prefix + "/objcopy"),1337 tool_path(name = "objdump", path = ctx.attr.host_compiler_prefix + "/objdump"),1338 tool_path(name = "strip", path = ctx.attr.host_compiler_prefix + "/strip"),1339 ]1340 elif (ctx.attr.cpu == "darwin"):1341 tool_paths = [1342 tool_path(name = "gcc", path = ctx.attr.host_compiler_path),1343 tool_path(name = "ar", path = ctx.attr.host_compiler_prefix + "/libtool"),1344 tool_path(name = "compat-ld", path = ctx.attr.host_compiler_prefix + "/ld"),1345 tool_path(name = "cpp", path = ctx.attr.host_compiler_prefix + "/cpp"),1346 tool_path(name = "dwp", path = ctx.attr.host_compiler_prefix + "/dwp"),1347 tool_path(name = "gcov", path = ctx.attr.host_compiler_prefix + "/gcov"),1348 tool_path(name = "ld", path = ctx.attr.host_compiler_prefix + "/ld"),1349 tool_path(name = "nm", path = ctx.attr.host_compiler_prefix + "/nm"),1350 tool_path(name = "objcopy", path = ctx.attr.host_compiler_prefix + "/objcopy"),1351 tool_path(name = "objdump", path = ctx.attr.host_compiler_prefix + "/objdump"),1352 tool_path(name = "strip", path = ctx.attr.host_compiler_prefix + "/strip"),1353 ]1354 else:1355 fail("Unreachable")1356 out = ctx.actions.declare_file(ctx.label.name)1357 ctx.actions.write(out, "Fake executable")1358 return [1359 cc_common.create_cc_toolchain_config_info(1360 ctx = ctx,1361 features = features,1362 action_configs = action_configs,1363 artifact_name_patterns = [],1364 cxx_builtin_include_directories = cxx_builtin_include_directories,1365 toolchain_identifier = toolchain_identifier,1366 host_system_name = host_system_name,1367 target_system_name = target_system_name,1368 target_cpu = target_cpu,1369 target_libc = target_libc,1370 compiler = compiler,1371 abi_version = abi_version,1372 abi_libc_version = abi_libc_version,1373 tool_paths = tool_paths,1374 make_variables = [],1375 builtin_sysroot = builtin_sysroot,1376 cc_target_os = cc_target_os,1377 ),1378 DefaultInfo(1379 executable = out,1380 ),1381 ]1382cc_toolchain_config = rule(1383 implementation = _impl,1384 attrs = {1385 "cpu": attr.string(mandatory = True, values = ["darwin", "local", "x64_windows"]),1386 "builtin_include_directories": attr.string_list(),1387 "extra_no_canonical_prefixes_flags": attr.string_list(),1388 "host_compiler_path": attr.string(),1389 "host_compiler_prefix": attr.string(),1390 "host_compiler_warnings": attr.string_list(),1391 "host_unfiltered_compile_flags": attr.string_list(),1392 "linker_bin_path": attr.string(),1393 "msvc_cl_path": attr.string(default = "msvc_not_used"),1394 "msvc_env_include": attr.string(default = "msvc_not_used"),1395 "msvc_env_lib": attr.string(default = "msvc_not_used"),1396 "msvc_env_path": attr.string(default = "msvc_not_used"),1397 "msvc_env_tmp": attr.string(default = "msvc_not_used"),1398 "msvc_lib_path": attr.string(default = "msvc_not_used"),1399 "msvc_link_path": attr.string(default = "msvc_not_used"),1400 "msvc_ml_path": attr.string(default = "msvc_not_used"),1401 },1402 provides = [CcToolchainConfigInfo],1403 executable = True,...
iec104_information_elements.py
Source:iec104_information_elements.py
1# This file is part of Scapy2# See http://www.secdev.org/projects/scapy for more information3# Copyright (C) Thomas Tannhaeuser <hecke@naberius.de>4# This program is published under a GPLv2 license5# scapy.contrib.status = skip6"""7 information element definitions used by IEC 60870-5-101/1048 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~9 :description:10 This module provides the information element (IE) definitions used to11 compose the ASDUs (Application Service Data Units) used within the12 IEC 60870-5-101 and IEC 60870-5-104 protocol.13 normative references:14 - IEC 60870-5-4:1993 (atomic base types / data format)15 - IEC 60870-5-101:2003 (information elements (sec. 7.2.6) and16 ASDU definition (sec. 7.3))17 - IEC 60870-5-104:2006 (information element TSC (sec. 8.8, p. 44))18 :TODO:19 - some definitions should use signed types as outlined in the standard20 - normed value element should use a float type21"""22from scapy.contrib.scada.iec104.iec104_fields import \23 IEC60870_5_4_NormalizedFixPoint, IEC104SignedSevenBitValue, \24 LESignedShortField, LEIEEEFloatField25from scapy.fields import BitEnumField, ByteEnumField, ByteField, \26 ThreeBytesField, \27 BitField, LEShortField, LESignedIntField28def _generate_attributes_and_dicts(cls):29 """30 create class attributes and dict entries for range-based attributes31 class attributes will take the form: cls.<attribute_name_prefix>_<index>32 dictionary entries will be generated as:33 the_dict[index] = "<dict_entry_prefix> (<index>)"34 expects a GENERATED_ATTRIBUTES attribute within the class that contains a35 list of the specification for the attributes and dictionary entries to be36 generated. each list entry must have this format:37 (attribute_name_prefix, dict_entry_prefix, dictionary, first_index,38 last_index)39 with40 <attribute_name_prefix> - the prefix of the attribute name41 first_index - index of the first attribute to be generated42 last_index - index of the last attribute to be generated43 :param cls: the class the attributes should be added to44 :return: cls extended by generated attributes45 """46 for attribute_name_prefix, dict_entry_prefix, the_dict, first_index, \47 last_index \48 in cls.GENERATED_ATTRIBUTES:49 for index in range(first_index, last_index + 1):50 the_dict[index] = '{} ({})'.format(dict_entry_prefix, index)51 setattr(cls, '{}_{}'.format(attribute_name_prefix, index), index)52 return cls53class IEC104_IE_CommonQualityFlags:54 """55 common / shared information element quality flags56 """57 IV_FLAG_VALID = 058 IV_FLAG_INVALID = 159 IV_FLAGS = {60 IV_FLAG_VALID: 'valid',61 IV_FLAG_INVALID: 'invalid'62 }63 NT_FLAG_CURRENT_VALUE = 064 NT_FLAG_OLD_VALUE = 165 NT_FLAGS = {66 NT_FLAG_CURRENT_VALUE: 'current value',67 NT_FLAG_OLD_VALUE: 'old value'68 }69 SB_FLAG_NOT_SUBSTITUTED = 070 SB_FLAG_SUBSTITUTED = 171 SB_FLAGS = {72 SB_FLAG_NOT_SUBSTITUTED: 'not substituted',73 SB_FLAG_SUBSTITUTED: 'substituted'74 }75 BL_FLAG_NOT_BLOCKED = 076 BL_FLAG_BLOCKED = 177 BL_FLAGS = {78 BL_FLAG_NOT_BLOCKED: 'not blocked',79 BL_FLAG_BLOCKED: 'blocked'80 }81 EI_FLAG_ELAPSED_TIME_VALID = 082 EI_FLAG_ELAPSED_TIME_INVALID = 183 EI_FLAGS = {84 EI_FLAG_ELAPSED_TIME_VALID: 'elapsed time valid',85 EI_FLAG_ELAPSED_TIME_INVALID: 'elapsed time invalid'86 }87class IEC104_IE_SIQ(IEC104_IE_CommonQualityFlags):88 """89 SIQ - single point information with quality descriptor90 EN 60870-5-101:2003, sec. 7.2.6.1 (p. 44)91 """92 SPI_FLAG_STATE_OFF = 093 SPI_FLAG_STATE_ON = 194 SPI_FLAGS = {95 SPI_FLAG_STATE_OFF: 'off',96 SPI_FLAG_STATE_ON: 'on'97 }98 informantion_element_fields = [99 BitEnumField('iv', 0, 1, IEC104_IE_CommonQualityFlags.IV_FLAGS),100 # invalid101 BitEnumField('nt', 0, 1, IEC104_IE_CommonQualityFlags.NT_FLAGS),102 # live or cached old value103 BitEnumField('sb', 0, 1, IEC104_IE_CommonQualityFlags.SB_FLAGS),104 # value substituted105 BitEnumField('bl', 0, 1, IEC104_IE_CommonQualityFlags.BL_FLAGS),106 # blocked107 BitField('reserved', 0, 3),108 BitEnumField('spi_value', 0, 1, SPI_FLAGS)109 ]110class IEC104_IE_DIQ(IEC104_IE_CommonQualityFlags):111 """112 DIQ - double-point information with quality descriptor113 EN 60870-5-101:2003, sec. 7.2.6.2 (p. 44)114 """115 DPI_FLAG_STATE_UNDEFINED_OR_TRANSIENT = 0116 DPI_FLAG_STATE_OFF = 1117 DPI_FLAG_STATE_ON = 2118 DPI_FLAG_STATE_UNDEFINED = 3119 DPI_FLAGS = {120 DPI_FLAG_STATE_UNDEFINED_OR_TRANSIENT: 'undefined/transient',121 DPI_FLAG_STATE_OFF: 'off',122 DPI_FLAG_STATE_ON: 'on',123 DPI_FLAG_STATE_UNDEFINED: 'undefined'124 }125 informantion_element_fields = [126 BitEnumField('iv', 0, 1, IEC104_IE_CommonQualityFlags.IV_FLAGS),127 # invalid128 BitEnumField('nt', 0, 1, IEC104_IE_CommonQualityFlags.NT_FLAGS),129 # live or cached old value130 BitEnumField('sb', 0, 1, IEC104_IE_CommonQualityFlags.SB_FLAGS),131 # value substituted132 BitEnumField('bl', 0, 1, IEC104_IE_CommonQualityFlags.BL_FLAGS),133 # blocked134 BitField('reserved', 0, 2),135 BitEnumField('dpi_value', 0, 2, DPI_FLAGS)136 ]137class IEC104_IE_QDS(IEC104_IE_CommonQualityFlags):138 """139 QDS - quality descriptor separate object140 EN 60870-5-101:2003, sec. 7.2.6.3 (p. 45)141 """142 OV_FLAG_NO_OVERFLOW = 0143 OV_FLAG_OVERFLOW = 1144 OV_FLAGS = {145 OV_FLAG_NO_OVERFLOW: 'no overflow',146 OV_FLAG_OVERFLOW: 'overflow'147 }148 informantion_element_fields = [149 BitEnumField('iv', 0, 1, IEC104_IE_CommonQualityFlags.IV_FLAGS),150 # invalid151 BitEnumField('nt', 0, 1, IEC104_IE_CommonQualityFlags.NT_FLAGS),152 # live or cached old value153 BitEnumField('sb', 0, 1, IEC104_IE_CommonQualityFlags.SB_FLAGS),154 # value substituted155 BitEnumField('bl', 0, 1, IEC104_IE_CommonQualityFlags.BL_FLAGS),156 # blocked157 BitField('reserved', 0, 3),158 BitEnumField('ov', 0, 1, OV_FLAGS), # overflow159 ]160class IEC104_IE_QDP(IEC104_IE_CommonQualityFlags):161 """162 QDP - quality descriptor protection equipment separate object163 EN 60870-5-101:2003, sec. 7.2.6.4 (p. 46)164 """165 informantion_element_fields = [166 BitEnumField('iv', 0, 1, IEC104_IE_CommonQualityFlags.IV_FLAGS),167 # invalid168 BitEnumField('nt', 0, 1, IEC104_IE_CommonQualityFlags.NT_FLAGS),169 # live or cached old value170 BitEnumField('sb', 0, 1, IEC104_IE_CommonQualityFlags.SB_FLAGS),171 # value substituted172 BitEnumField('bl', 0, 1, IEC104_IE_CommonQualityFlags.BL_FLAGS),173 # blocked174 BitEnumField('ei', 0, 1, IEC104_IE_CommonQualityFlags.EI_FLAGS),175 # blocked176 BitField('reserved', 0, 3)177 ]178class IEC104_IE_VTI:179 """180 VTI - value with transient state indication181 EN 60870-5-101:2003, sec. 7.2.6.5 (p. 47)182 """183 TRANSIENT_STATE_DISABLED = 0184 TRANSIENT_STATE_ENABLED = 1185 TRANSIENT_STATE_FLAGS = {186 TRANSIENT_STATE_DISABLED: 'device not in transient state',187 TRANSIENT_STATE_ENABLED: 'device in transient state'188 }189 informantion_element_fields = [190 BitEnumField('transient_state', 0, 1, TRANSIENT_STATE_FLAGS),191 IEC104SignedSevenBitValue('value', 0)192 ]193class IEC104_IE_NVA:194 """195 NVA - normed value196 EN 60870-5-101:2003, sec. 7.2.6.6 (p. 47)197 """198 informantion_element_fields = [199 IEC60870_5_4_NormalizedFixPoint('normed_value', 0)200 ]201class IEC104_IE_SVA:202 """203 SVA - scaled value204 EN 60870-5-101:2003, sec. 7.2.6.7 (p. 47)205 """206 informantion_element_fields = [207 LESignedShortField('scaled_value', 0)208 ]209class IEC104_IE_R32_IEEE_STD_754:210 """211 R32-IEEE STD 754 - short floating point value212 EN 60870-5-101:2003, sec. 7.2.6.8 (p. 47)213 """214 informantion_element_fields = [215 LEIEEEFloatField('scaled_value', 0)216 ]217class IEC104_IE_BCR:218 """219 BCR - binary counter reading220 EN 60870-5-101:2003, sec. 7.2.6.9 (p. 47)221 """222 CA_FLAG_COUNTER_NOT_ADJUSTED = 0223 CA_FLAG_COUNTER_ADJUSTED = 1224 CA_FLAGS = {225 CA_FLAG_COUNTER_NOT_ADJUSTED: 'counter not adjusted',226 CA_FLAG_COUNTER_ADJUSTED: 'counter adjusted'227 }228 CY_FLAG_NO_OVERFLOW = 0229 CY_FLAG_OVERFLOW = 1230 CY_FLAGS = {231 CY_FLAG_NO_OVERFLOW: 'no overflow',232 CY_FLAG_OVERFLOW: 'overflow'233 }234 informantion_element_fields = [235 LESignedIntField('counter_value', 0),236 BitEnumField('iv', 0, 1, IEC104_IE_CommonQualityFlags.IV_FLAGS),237 # invalid238 BitEnumField('ca', 0, 1, CA_FLAGS), # counter adjusted239 BitEnumField('cy', 0, 1, CY_FLAGS), # carry flag / overflow240 BitField('sq', 0, 5) # sequence241 ]242class IEC104_IE_SEP(IEC104_IE_CommonQualityFlags):243 """244 SEP - single event of protection equipment245 EN 60870-5-101:2003, sec. 7.2.6.10 (p. 48)246 """247 ES_FLAG_STATE_UNDEFINED_0 = 0248 ES_FLAG_STATE_OFF = 1249 ES_FLAG_STATE_ON = 2250 ES_FLAG_STATE_UNDEFINED_3 = 3251 ES_FLAGS = {252 ES_FLAG_STATE_UNDEFINED_0: 'undefined (0)',253 ES_FLAG_STATE_OFF: 'off',254 ES_FLAG_STATE_ON: 'on',255 ES_FLAG_STATE_UNDEFINED_3: 'undefined (3)',256 }257 informantion_element_fields = [258 BitEnumField('iv', 0, 1, IEC104_IE_CommonQualityFlags.IV_FLAGS),259 # invalid260 BitEnumField('nt', 0, 1, IEC104_IE_CommonQualityFlags.NT_FLAGS),261 # live or cached old value262 BitEnumField('sb', 0, 1, IEC104_IE_CommonQualityFlags.SB_FLAGS),263 # value substituted264 BitEnumField('bl', 0, 1, IEC104_IE_CommonQualityFlags.BL_FLAGS),265 # blocked266 BitEnumField('ei', 0, 1, IEC104_IE_CommonQualityFlags.EI_FLAGS),267 # time valid268 BitField('reserved', 0, 1),269 BitEnumField('es', 0, 2, ES_FLAGS), # event state270 ]271class IEC104_IE_SPE:272 """273 SPE - start events of protection equipment274 EN 60870-5-101:2003, sec. 7.2.6.11 (p. 48)275 """276 GS_FLAG_NO_GENERAL_TRIGGER = 0277 GS_FLAG_GENERAL_TRIGGER = 1278 GS_FLAGS = {279 GS_FLAG_NO_GENERAL_TRIGGER: 'general trigger',280 GS_FLAG_GENERAL_TRIGGER: 'no general trigger'281 }282 # protection relays - start of operation - fault detection per phase283 SL_FLAG_START_OPR_PHASE_L1_NO_TRIGGER = 0284 SL_FLAG_START_OPR_PHASE_L1_TRIGGER = 1285 SL_FLAG_START_OPR_PHASE_L2_NO_TRIGGER = 0286 SL_FLAG_START_OPR_PHASE_L2_TRIGGER = 1287 SL_FLAG_START_OPR_PHASE_L3_NO_TRIGGER = 0288 SL_FLAG_START_OPR_PHASE_L3_TRIGGER = 1289 SL_FLAGS = {290 SL_FLAG_START_OPR_PHASE_L1_NO_TRIGGER: 'no start of operation',291 SL_FLAG_START_OPR_PHASE_L1_TRIGGER: 'start of operation'292 }293 # protection event start caused by earth current294 SIE_FLAG_START_OPR_PHASE_IE_NO_TRIGGER = 0295 SIE_FLAG_START_OPR_PHASE_IE_TRIGGER = 1296 SIE_FLAGS = {297 SIE_FLAG_START_OPR_PHASE_IE_NO_TRIGGER: 'no start of operation',298 SIE_FLAG_START_OPR_PHASE_IE_TRIGGER: 'start of operation'299 }300 # direction of the started protection event301 SRD_FLAG_DIRECTION_FORWARD = 0302 SRD_FLAG_DIRECTION_BACKWARD = 1303 SRD_FLAGS = {304 SRD_FLAG_DIRECTION_FORWARD: 'forward',305 SRD_FLAG_DIRECTION_BACKWARD: 'backward'306 }307 informantion_element_fields = [308 BitField('reserved', 0, 2),309 BitEnumField('srd', 0, 1, SRD_FLAGS),310 BitEnumField('sie', 0, 1, SIE_FLAGS),311 BitEnumField('sl3', 0, 1, SL_FLAGS),312 BitEnumField('sl2', 0, 1, SL_FLAGS),313 BitEnumField('sl1', 0, 1, SL_FLAGS),314 BitEnumField('gs', 0, 1, GS_FLAGS)315 ]316class IEC104_IE_OCI:317 """318 OCI - output circuit information of protection equipment319 EN 60870-5-101:2003, sec. 7.2.6.12 (p. 49)320 """321 # all 3 phases off command322 GC_FLAG_NO_GENERAL_COMMAND_OFF = 0323 GC_FLAG_GENERAL_COMMAND_OFF = 1324 GC_FLAGS = {325 GC_FLAG_NO_GENERAL_COMMAND_OFF: 'no general off',326 GC_FLAG_GENERAL_COMMAND_OFF: 'general off'327 }328 # phase based off command329 # protection relays - start of operation - fault detection per phase330 CL_FLAG_NO_COMMAND_L1_OFF = 0331 CL_FLAG_COMMAND_L1_OFF = 1332 CL_FLAG_NO_COMMAND_L2_OFF = 0333 CL_FLAG_COMMAND_L2_OFF = 1334 CL_FLAG_NO_COMMAND_L3_OFF = 0335 CL_FLAG_COMMAND_L3_OFF = 1336 CL_FLAGS = {337 CL_FLAG_NO_COMMAND_L1_OFF: 'no command off',338 CL_FLAG_COMMAND_L1_OFF: 'no command off'339 }340 informantion_element_fields = [341 BitField('reserved', 0, 4),342 BitEnumField('cl3', 0, 1, CL_FLAGS), # command Lx343 BitEnumField('cl2', 0, 1, CL_FLAGS),344 BitEnumField('cl1', 0, 1, CL_FLAGS),345 BitEnumField('gc', 0, 1, GC_FLAGS), # general off346 ]347class IEC104_IE_BSI:348 """349 BSI - binary state information350 EN 60870-5-101:2003, sec. 7.2.6.13 (p. 49)351 """352 informantion_element_fields = [353 BitField('bsi', 0, 32)354 ]355class IEC104_IE_FBP:356 """357 FBP - fixed test bit pattern358 EN 60870-5-101:2003, sec. 7.2.6.14 (p. 49)359 """360 informantion_element_fields = [361 LEShortField('fbp', 0)362 ]363@_generate_attributes_and_dicts364class IEC104_IE_QOC:365 """366 QOC - qualifier of command367 EN 60870-5-101:2003, sec. 7.2.6.26 (p. 54)368 """369 QU_FLAG_NO_ADDITIONAL_PARAMETERS = 0370 QU_FLAG_SHORT_COMMAND_EXEC_TIME = 1 # e.g. controlling a power switch371 QU_FLAG_LONG_COMMAND_EXEC_TIME = 2372 QU_FLAG_PERMANENT_COMMAND = 3373 QU_FLAGS = {374 QU_FLAG_NO_ADDITIONAL_PARAMETERS: 'no additional parameter',375 QU_FLAG_SHORT_COMMAND_EXEC_TIME: 'short execution time',376 QU_FLAG_LONG_COMMAND_EXEC_TIME: 'long execution time',377 QU_FLAG_PERMANENT_COMMAND: 'permanent command',378 }379 GENERATED_ATTRIBUTES = [380 ('QU_FLAG_RESERVED_COMPATIBLE', 'reserved - compatible', QU_FLAGS, 4,381 8),382 ('QU_FLAG_RESERVED_PREDEFINED_FUNCTION',383 'reserved - predefined function', QU_FLAGS, 9, 15),384 ('QU_FLAG_RESERVED_PRIVATE', 'reserved - private', QU_FLAGS, 16, 31)385 ]386 SE_FLAG_EXECUTE = 0387 SE_FLAG_SELECT = 1388 SE_FLAGS = {389 SE_FLAG_EXECUTE: 'execute',390 SE_FLAG_SELECT: 'select'391 }392 informantion_element_fields = [393 BitEnumField('s/e', 0, 1, SE_FLAGS),394 BitEnumField('qu', 0, 5, QU_FLAGS)395 ]396class IEC104_IE_SCO(IEC104_IE_QOC):397 """398 SCO - single command399 EN 60870-5-101:2003, sec. 7.2.6.15 (p. 50)400 """401 SCS_FLAG_STATE_OFF = 0402 SCS_FLAG_STATE_ON = 1403 SCS_FLAGS = {404 SCS_FLAG_STATE_OFF: 'off',405 SCS_FLAG_STATE_ON: 'on'406 }407 informantion_element_fields = IEC104_IE_QOC.informantion_element_fields + [408 BitField('reserved', 0, 1),409 BitEnumField('scs', 0, 1, SCS_FLAGS)410 ]411class IEC104_IE_DCO(IEC104_IE_QOC):412 """413 DCO - double command414 EN 60870-5-101:2003, sec. 7.2.6.16 (p. 50)415 """416 DCS_FLAG_STATE_INVALID_0 = 0417 DCS_FLAG_STATE_OFF = 1418 DCS_FLAG_STATE_ON = 2419 DCS_FLAG_STATE_INVALID_3 = 3420 DCS_FLAGS = {421 DCS_FLAG_STATE_INVALID_0: 'invalid (0)',422 DCS_FLAG_STATE_OFF: 'off',423 DCS_FLAG_STATE_ON: 'on',424 DCS_FLAG_STATE_INVALID_3: 'invalid (3)',425 }426 informantion_element_fields = IEC104_IE_QOC.informantion_element_fields + [427 BitEnumField('dcs', 0, 2, DCS_FLAGS)428 ]429class IEC104_IE_RCO(IEC104_IE_QOC):430 """431 RCO - regulating step command432 EN 60870-5-101:2003, sec. 7.2.6.17 (p. 50)433 """434 RCO_FLAG_STATE_INVALID_0 = 0435 RCO_FLAG_STATE_STEP_DOWN = 1436 RCO_FLAG_STATE_STEP_UP = 2437 RCO_FLAG_STATE_INVALID_3 = 3438 RCO_FLAGS = {439 RCO_FLAG_STATE_INVALID_0: 'invalid (0)',440 RCO_FLAG_STATE_STEP_DOWN: 'step down',441 RCO_FLAG_STATE_STEP_UP: 'step up',442 RCO_FLAG_STATE_INVALID_3: 'invalid (3)',443 }444 informantion_element_fields = IEC104_IE_QOC.informantion_element_fields + [445 BitEnumField('rcs', 0, 2, RCO_FLAGS)446 ]447class IEC104_IE_CP56TIME2A(IEC104_IE_CommonQualityFlags):448 """449 CP56Time2a - dual time, 7 octets450 (milliseconds, valid flag, minutes, hours,451 summer-time-indicator, day of month, weekday, years)452 well, someone should have talked to them about the idea of the453 unix timestamp...454 EN 60870-5-101:2003, sec. 7.2.6.18 (p. 50)455 time representation format according IEC 60870-5-4:1993, sec. 6.8, p. 23456 """457 WEEK_DAY_FLAG_UNUSED = 0458 WEEK_DAY_FLAG_MONDAY = 1459 WEEK_DAY_FLAG_TUESDAY = 2460 WEEK_DAY_FLAG_WEDNESDAY = 3461 WEEK_DAY_FLAG_THURSDAY = 4462 WEEK_DAY_FLAG_FRIDAY = 5463 WEEK_DAY_FLAG_SATURDAY = 6464 WEEK_DAY_FLAG_SUNDAY = 7465 WEEK_DAY_FLAGS = {466 WEEK_DAY_FLAG_UNUSED: 'unused',467 WEEK_DAY_FLAG_MONDAY: 'Monday',468 WEEK_DAY_FLAG_TUESDAY: 'Tuesday',469 WEEK_DAY_FLAG_WEDNESDAY: 'Wednesday',470 WEEK_DAY_FLAG_THURSDAY: 'Thursday',471 WEEK_DAY_FLAG_FRIDAY: 'Friday',472 WEEK_DAY_FLAG_SATURDAY: 'Saturday',473 WEEK_DAY_FLAG_SUNDAY: 'Sunday'474 }475 GEN_FLAG_REALTIME = 0476 GEN_FLAG_SUBSTITUTED_TIME = 1477 GEN_FLAGS = {478 GEN_FLAG_REALTIME: 'real time',479 GEN_FLAG_SUBSTITUTED_TIME: 'substituted time'480 }481 SU_FLAG_NORMAL_TIME = 0482 SU_FLAG_SUMMER_TIME = 1483 SU_FLAGS = {484 SU_FLAG_NORMAL_TIME: 'normal time',485 SU_FLAG_SUMMER_TIME: 'summer time'486 }487 informantion_element_fields = [488 LEShortField('sec_milli', 0),489 BitEnumField('iv', 0, 1, IEC104_IE_CommonQualityFlags.IV_FLAGS),490 BitEnumField('gen', 0, 1, GEN_FLAGS),491 # only valid in monitor direction ToDo: special treatment needed?492 BitField('minutes', 0, 6),493 BitEnumField('su', 0, 1, SU_FLAGS),494 BitField('reserved_2', 0, 2),495 BitField('hours', 0, 5),496 BitEnumField('weekday', 0, 3, WEEK_DAY_FLAGS),497 BitField('day-of-month', 0, 5),498 BitField('reserved_3', 0, 4),499 BitField('month', 0, 4),500 BitField('reserved_4', 0, 1),501 BitField('year', 0, 7),502 ]503class IEC104_IE_CP56TIME2A_START_TIME(IEC104_IE_CP56TIME2A):504 """505 derived IE, used for ASDU that requires two CP56TIME2A timestamps for506 defining a range507 """508 _DERIVED_IE = True509 informantion_element_fields = [510 LEShortField('start_sec_milli', 0),511 BitEnumField('start_iv', 0, 1, IEC104_IE_CommonQualityFlags.IV_FLAGS),512 BitEnumField('start_gen', 0, 1, IEC104_IE_CP56TIME2A.GEN_FLAGS),513 # only valid in monitor direction ToDo: special treatment needed?514 BitField('start_minutes', 0, 6),515 BitEnumField('start_su', 0, 1, IEC104_IE_CP56TIME2A.SU_FLAGS),516 BitField('start_reserved_2', 0, 2),517 BitField('start_hours', 0, 5),518 BitEnumField('start_weekday', 0, 3,519 IEC104_IE_CP56TIME2A.WEEK_DAY_FLAGS),520 BitField('start_day-of-month', 0, 5),521 BitField('start_reserved_3', 0, 4),522 BitField('start_month', 0, 4),523 BitField('start_reserved_4', 0, 1),524 BitField('start_year', 0, 7),525 ]526class IEC104_IE_CP56TIME2A_STOP_TIME(IEC104_IE_CP56TIME2A):527 """528 derived IE, used for ASDU that requires two CP56TIME2A timestamps for529 defining a range530 """531 _DERIVED_IE = True532 informantion_element_fields = [533 LEShortField('stop_sec_milli', 0),534 BitEnumField('stop_iv', 0, 1, IEC104_IE_CommonQualityFlags.IV_FLAGS),535 BitEnumField('stop_gen', 0, 1, IEC104_IE_CP56TIME2A.GEN_FLAGS),536 # only valid in monitor direction ToDo: special treatment needed?537 BitField('stop_minutes', 0, 6),538 BitEnumField('stop_su', 0, 1, IEC104_IE_CP56TIME2A.SU_FLAGS),539 BitField('stop_reserved_2', 0, 2),540 BitField('stop_hours', 0, 5),541 BitEnumField('stop_weekday', 0, 3,542 IEC104_IE_CP56TIME2A.WEEK_DAY_FLAGS),543 BitField('stop_day-of-month', 0, 5),544 BitField('stop_reserved_3', 0, 4),545 BitField('stop_month', 0, 4),546 BitField('stop_reserved_4', 0, 1),547 BitField('stop_year', 0, 7),548 ]549class IEC104_IE_CP24TIME2A(IEC104_IE_CP56TIME2A):550 """551 CP24Time2a - dual time, 3 octets552 (milliseconds, valid flag, minutes)553 EN 60870-5-101:2003, sec. 7.2.6.19 (p. 51)554 time representation format according IEC 60870-5-4:1993, sec. 6.8, p. 23,555 octet 4..7 discarded556 """557 informantion_element_fields = \558 IEC104_IE_CP56TIME2A.informantion_element_fields[:4]559class IEC104_IE_CP16TIME2A:560 """561 CP16Time2a - dual time, 2 octets562 (milliseconds)563 EN 60870-5-101:2003, sec. 7.2.6.20 (p. 51)564 """565 informantion_element_fields = [566 LEShortField('sec_milli', 0)567 ]568class IEC104_IE_CP16TIME2A_ELAPSED:569 """570 derived IE, used in ASDU using more than one CP* field and this one is571 used to show an elapsed time572 """573 _DERIVED_IE = True574 informantion_element_fields = [575 LEShortField('elapsed_sec_milli', 0)576 ]577class IEC104_IE_CP16TIME2A_PROTECTION_ACTIVE:578 """579 derived IE, used in ASDU using more than one CP* field and this one is580 used to show an protection activation time581 """582 _DERIVED_IE = True583 informantion_element_fields = [584 LEShortField('prot_act_sec_milli', 0)585 ]586class IEC104_IE_CP16TIME2A_PROTECTION_COMMAND:587 """588 derived IE, used in ASDU using more than one CP* field and this one is589 used to show an protection command time590 """591 _DERIVED_IE = True592 informantion_element_fields = [593 LEShortField('prot_cmd_sec_milli', 0)594 ]595@_generate_attributes_and_dicts596class IEC104_IE_COI:597 """598 COI - cause of initialization599 EN 60870-5-101:2003, sec. 7.2.6.21 (p. 51)600 """601 LPC_FLAG_LOCAL_PARAMETER_UNCHANGED = 0602 LPC_FLAG_LOCAL_PARAMETER_CHANGED = 1603 LPC_FLAGS = {604 LPC_FLAG_LOCAL_PARAMETER_UNCHANGED: 'unchanged',605 LPC_FLAG_LOCAL_PARAMETER_CHANGED: 'changed'606 }607 COI_FLAG_LOCAL_POWER_ON = 0608 COI_FLAG_LOCAL_MANUAL_RESET = 1609 COI_FLAG_REMOTE_RESET = 2610 COI_FLAGS = {611 COI_FLAG_LOCAL_POWER_ON: 'local power on',612 COI_FLAG_LOCAL_MANUAL_RESET: 'manual reset',613 COI_FLAG_REMOTE_RESET: 'remote reset'614 }615 GENERATED_ATTRIBUTES = [616 ('COI_FLAG_COMPATIBLE_RESERVED', 'compatible reserved', COI_FLAGS, 3,617 31),618 ('COI_FLAG_PRIVATE_RESERVED', 'private reserved', COI_FLAGS, 32, 127)619 ]620 informantion_element_fields = [621 BitEnumField('local_param_state', 0, 1, LPC_FLAGS),622 BitEnumField('coi', 0, 7, COI_FLAGS)623 ]624@_generate_attributes_and_dicts625class IEC104_IE_QOI:626 """627 QOI - qualifier of interrogation628 EN 60870-5-101:2003, sec. 7.2.6.22 (p. 52)629 """630 QOI_FLAG_UNUSED = 0631 QOI_FLAG_STATION_INTERROGATION = 20632 QOI_FLAG_GROUP_1_INTERROGATION = 21633 QOI_FLAG_GROUP_2_INTERROGATION = 22634 QOI_FLAG_GROUP_3_INTERROGATION = 23635 QOI_FLAG_GROUP_4_INTERROGATION = 24636 QOI_FLAG_GROUP_5_INTERROGATION = 25637 QOI_FLAG_GROUP_6_INTERROGATION = 26638 QOI_FLAG_GROUP_7_INTERROGATION = 27639 QOI_FLAG_GROUP_8_INTERROGATION = 28640 QOI_FLAG_GROUP_9_INTERROGATION = 29641 QOI_FLAG_GROUP_10_INTERROGATION = 30642 QOI_FLAG_GROUP_11_INTERROGATION = 31643 QOI_FLAG_GROUP_12_INTERROGATION = 32644 QOI_FLAG_GROUP_13_INTERROGATION = 33645 QOI_FLAG_GROUP_14_INTERROGATION = 34646 QOI_FLAG_GROUP_15_INTERROGATION = 35647 QOI_FLAG_GROUP_16_INTERROGATION = 36648 QOI_FLAGS = {649 QOI_FLAG_UNUSED: 'unused',650 QOI_FLAG_STATION_INTERROGATION: 'station interrogation',651 QOI_FLAG_GROUP_1_INTERROGATION: 'group 1 interrogation',652 QOI_FLAG_GROUP_2_INTERROGATION: 'group 2 interrogation',653 QOI_FLAG_GROUP_3_INTERROGATION: 'group 3 interrogation',654 QOI_FLAG_GROUP_4_INTERROGATION: 'group 4 interrogation',655 QOI_FLAG_GROUP_5_INTERROGATION: 'group 5 interrogation',656 QOI_FLAG_GROUP_6_INTERROGATION: 'group 6 interrogation',657 QOI_FLAG_GROUP_7_INTERROGATION: 'group 7 interrogation',658 QOI_FLAG_GROUP_8_INTERROGATION: 'group 8 interrogation',659 QOI_FLAG_GROUP_9_INTERROGATION: 'group 9 interrogation',660 QOI_FLAG_GROUP_10_INTERROGATION: 'group 10 interrogation',661 QOI_FLAG_GROUP_11_INTERROGATION: 'group 11 interrogation',662 QOI_FLAG_GROUP_12_INTERROGATION: 'group 12 interrogation',663 QOI_FLAG_GROUP_13_INTERROGATION: 'group 13 interrogation',664 QOI_FLAG_GROUP_14_INTERROGATION: 'group 14 interrogation',665 QOI_FLAG_GROUP_15_INTERROGATION: 'group 15 interrogation',666 QOI_FLAG_GROUP_16_INTERROGATION: 'group 16 interrogation'667 }668 GENERATED_ATTRIBUTES = [669 ('QOI_FLAG_COMPATIBLE_RESERVED', 'compatible reserved', QOI_FLAGS, 1,670 19),671 ('QOI_FLAG_COMPATIBLE_RESERVED', 'compatible reserved', QOI_FLAGS, 37,672 63),673 ('QOI_FLAG_PRIVATE_RESERVED', 'private reserved', QOI_FLAGS, 64, 255)674 ]675 informantion_element_fields = [676 ByteEnumField('qoi', 0, QOI_FLAGS)677 ]678@_generate_attributes_and_dicts679class IEC104_IE_QCC:680 """681 QCC - qualifier of counter interrogation command682 EN 60870-5-101:2003, sec. 7.2.6.23 (p. 52)683 """684 # request flags685 RQT_FLAG_UNUSED = 0686 RQT_FLAG_GROUP_1_COUNTER_INTERROGATION = 1687 RQT_FLAG_GROUP_2_COUNTER_INTERROGATION = 2688 RQT_FLAG_GROUP_3_COUNTER_INTERROGATION = 3689 RQT_FLAG_GROUP_4_COUNTER_INTERROGATION = 4690 RQT_FLAG_GENERAL_COUNTER_INTERROGATION = 5691 RQT_FLAGS = {692 RQT_FLAG_UNUSED: 'unused',693 RQT_FLAG_GROUP_1_COUNTER_INTERROGATION: 'counter group 1 '694 'interrogation',695 RQT_FLAG_GROUP_2_COUNTER_INTERROGATION: 'counter group 2 '696 'interrogation',697 RQT_FLAG_GROUP_3_COUNTER_INTERROGATION: 'counter group 3 '698 'interrogation',699 RQT_FLAG_GROUP_4_COUNTER_INTERROGATION: 'counter group 4 '700 'interrogation',701 RQT_FLAG_GENERAL_COUNTER_INTERROGATION: 'general counter '702 'interrogation',703 }704 GENERATED_ATTRIBUTES = [705 ('RQT_FLAG_COMPATIBLE_RESERVED', 'compatible reserved', RQT_FLAGS, 6,706 31),707 ('RQT_FLAG_PRIVATE_RESERVED', 'private reserved', RQT_FLAGS, 32, 63),708 ]709 FRZ_FLAG_QUERY = 0710 FRZ_FLAG_SAVE_COUNTER_WITHOUT_RESET = 1711 FRZ_FLAG_SAVE_COUNTER_AND_RESET = 2712 FRZ_FLAG_COUNTER_RESET = 3713 FRZ_FLAGS = {714 FRZ_FLAG_QUERY: 'query',715 FRZ_FLAG_SAVE_COUNTER_WITHOUT_RESET: 'save counter, no counter reset',716 FRZ_FLAG_SAVE_COUNTER_AND_RESET: 'save counter and reset counter',717 FRZ_FLAG_COUNTER_RESET: 'reset counter'718 }719 informantion_element_fields = [720 BitEnumField('frz', 0, 2, FRZ_FLAGS),721 BitEnumField('rqt', 0, 6, RQT_FLAGS)722 ]723@_generate_attributes_and_dicts724class IEC104_IE_QPM:725 """726 QPM - qualifier of parameter of measured values727 EN 60870-5-101:2003, sec. 7.2.6.24 (p. 53)728 """729 KPA_FLAG_UNUSED = 0730 KPA_FLAG_THRESHOLD = 1731 KPA_FLAG_SMOOTHING_FACTOR = 2732 KPA_FLAG_LOWER_LIMIT_FOR_MEAS_TX = 3733 KPA_FLAG_UPPER_LIMIT_FOR_MEAS_TX = 4734 KPA_FLAGS = {735 KPA_FLAG_UNUSED: 'unused',736 KPA_FLAG_THRESHOLD: 'threshold',737 KPA_FLAG_SMOOTHING_FACTOR: 'smoothing factor',738 KPA_FLAG_LOWER_LIMIT_FOR_MEAS_TX: 'lower limit meas transmit',739 KPA_FLAG_UPPER_LIMIT_FOR_MEAS_TX: 'upper limit meas transmit'740 }741 GENERATED_ATTRIBUTES = [742 ('KPA_FLAG_COMPATIBLE_RESERVED', 'compatible reserved', KPA_FLAGS, 5,743 31),744 ('KPA_FLAG_PRIVATE_RESERVED', 'private reserved', KPA_FLAGS, 32, 63)745 ]746 LPC_FLAG_LOCAL_PARAMETER_MOT_CHANGED = 0747 LPC_FLAG_LOCAL_PARAMETER_CHANGED = 1748 LPC_FLAGS = {749 LPC_FLAG_LOCAL_PARAMETER_MOT_CHANGED: 'local parameter not changed',750 LPC_FLAG_LOCAL_PARAMETER_CHANGED: 'local parameter changed'751 }752 POP_FLAG_PARAM_EFFECTIVE = 0753 POP_FLAG_PARAM_INEFFECTIVE = 1754 POP_FLAGS = {755 POP_FLAG_PARAM_EFFECTIVE: 'parameter effective',756 POP_FLAG_PARAM_INEFFECTIVE: 'parameter ineffective',757 }758 informantion_element_fields = [759 BitEnumField('pop', 0, 1, POP_FLAGS), # usually unused, should be zero760 BitEnumField('lpc', 0, 1, LPC_FLAGS), # usually unused, should be zero761 BitEnumField('kpa', 0, 6, KPA_FLAGS),762 ]763@_generate_attributes_and_dicts764class IEC104_IE_QPA:765 """766 QPA - qualifier of parameter activation767 EN 60870-5-101:2003, sec. 7.2.6.25 (p. 53)768 """769 QPA_FLAG_UNUSED = 0770 QPA_FLAG_ACT_DEACT_LOADED_PARAM_OA_0 = 1771 QPA_FLAG_ACT_DEACT_LOADED_PARAM = 2772 QPA_FLAG_ACT_DEACT_CYCLIC_TX = 3773 QPA_FLAGS = {774 QPA_FLAG_UNUSED: 'unused',775 QPA_FLAG_ACT_DEACT_LOADED_PARAM_OA_0: 'act/deact loaded parameters '776 'for object addr 0',777 QPA_FLAG_ACT_DEACT_LOADED_PARAM: 'act/deact loaded parameters for '778 'given object addr',779 QPA_FLAG_ACT_DEACT_CYCLIC_TX: 'act/deact cyclic transfer of object '780 'given by object addr',781 }782 GENERATED_ATTRIBUTES = [783 ('QPA_FLAG_COMPATIBLE_RESERVED', 'compatible reserved', QPA_FLAGS, 4,784 127),785 ('QPA_FLAG_PRIVATE_RESERVED', 'private reserved', QPA_FLAGS, 128, 255)786 ]787 informantion_element_fields = [788 ByteEnumField('qpa', 0, QPA_FLAGS)789 ]790@_generate_attributes_and_dicts791class IEC104_IE_QRP:792 """793 QRP - Qualifier of reset process command794 EN 60870-5-101:2003, sec. 7.2.6.27 (p. 54)795 """796 QRP_FLAG_UNUSED = 0797 QRP_FLAG_GENERAL_PROCESS_RESET = 1798 QRP_FLAG_RESET_EVENT_BUFFER = 2799 QRP_FLAGS = {800 QRP_FLAG_UNUSED: 'unsued',801 QRP_FLAG_GENERAL_PROCESS_RESET: 'general process reset',802 QRP_FLAG_RESET_EVENT_BUFFER: 'reset event buffer'803 }804 GENERATED_ATTRIBUTES = [805 ('QRP_FLAG_COMPATIBLE_RESERVED', 'compatible reserved', QRP_FLAGS, 3,806 127),807 ('QRP_FLAG_PRIVATE_RESERVED', 'private reserved', QRP_FLAGS, 128, 255),808 ]809 informantion_element_fields = [810 ByteEnumField('qrp', 0, QRP_FLAGS)811 ]812@_generate_attributes_and_dicts813class IEC104_IE_FRQ:814 """815 FRQ - file ready qualifier816 EN 60870-5-101:2003, sec. 7.2.6.28 (p. 54)817 """818 FR_FLAG_UNUSED = 0819 FR_FLAGS = {820 FR_FLAG_UNUSED: 'unused'821 }822 GENERATED_ATTRIBUTES = [823 ('FR_FLAG_COMPATIBLE_RESERVED', 'compatible reserved',824 FR_FLAGS, 1, 63),825 ('FR_FLAG_PRIVATE_RESERVED', 'private reserved', FR_FLAGS, 64, 127),826 ]827 FRACK_FLAG_POSITIVE_ACK = 0828 FRACK_FLAG_NEGATIVE_ACK = 1829 FRACK_FLAGS = {830 FRACK_FLAG_POSITIVE_ACK: 'positive ack',831 FRACK_FLAG_NEGATIVE_ACK: 'negative ack'832 }833 informantion_element_fields = [834 BitEnumField('fr_ack', 0, 1, FRACK_FLAGS),835 BitEnumField('fr', 0, 7, FR_FLAGS)836 ]837@_generate_attributes_and_dicts838class IEC104_IE_SRQ:839 """840 SRQ - sequence ready qualifier841 EN 60870-5-101:2003, sec. 7.2.6.29 (p. 54)842 """843 SR_FLAG_UNUSED = 0844 SR_FLAGS = {845 SR_FLAG_UNUSED: 'unused'846 }847 GENERATED_ATTRIBUTES = [848 ('SR_FLAG_COMPATIBLE_RESERVED', 'compatible reserved',849 SR_FLAGS, 1, 63),850 ('SR_FLAG_PRIVATE_RESERVED', 'private reserved', SR_FLAGS, 64, 127),851 ]852 SLOAD_FLAG_SECTION_READY = 0853 SLOAD_FLAG_SECTION_NOT_READY = 1854 SLAOD_FLAGS = {855 SLOAD_FLAG_SECTION_READY: 'section ready',856 SLOAD_FLAG_SECTION_NOT_READY: 'section not ready'857 }858 informantion_element_fields = [859 BitEnumField('section_load_state', 0, 1, SLAOD_FLAGS),860 BitEnumField('sr', 0, 7, SR_FLAGS)861 ]862@_generate_attributes_and_dicts863class IEC104_IE_SCQ:864 """865 SCQ - select and call qualifier866 EN 60870-5-101:2003, sec. 7.2.6.30 (p. 55)867 """868 SEL_CALL_FLAG_UNUSED = 0869 SEL_CALL_FLAG_FILE_SELECT = 1870 SEL_CALL_FLAG_FILE_REQUEST = 2871 SEL_CALL_FLAG_FILE_ABORT = 3872 SEL_CALL_FLAG_FILE_DELETE = 4873 SEL_CALL_FLAG_SECTION_SELECTION = 5874 SEL_CALL_FLAG_SECTION_REQUEST = 6875 SEL_CALL_FLAG_SECTION_ABORT = 7876 SEL_CALL_FLAGS = {877 SEL_CALL_FLAG_UNUSED: 'unused',878 SEL_CALL_FLAG_FILE_SELECT: 'file select',879 SEL_CALL_FLAG_FILE_REQUEST: 'file request',880 SEL_CALL_FLAG_FILE_ABORT: 'file abort',881 SEL_CALL_FLAG_FILE_DELETE: 'file delete',882 SEL_CALL_FLAG_SECTION_SELECTION: 'section selection',883 SEL_CALL_FLAG_SECTION_REQUEST: 'section request',884 SEL_CALL_FLAG_SECTION_ABORT: 'section abort'885 }886 SEL_CALL_ERR_FLAG_UNUSED = 0887 SEL_CALL_ERR_FLAG_REQ_MEM_AREA_NO_AVAIL = 1888 SEL_CALL_ERR_FLAG_INVALID_CHECKSUM = 2889 SEL_CALL_ERR_FLAG_UNEXPECTED_COMMUNICATION_SERVICE = 3890 SEL_CALL_ERR_FLAG_UNEXPECTED_FILENAME = 4891 SEL_CALL_ERR_FLAG_UNEXPECTED_SECTION_NAME = 5892 SEL_CALL_ERR_FLAG_COMPATIBLE_RESERVED_6 = 6893 SEL_CALL_ERR_FLAG_COMPATIBLE_RESERVED_7 = 7894 SEL_CALL_ERR_FLAG_COMPATIBLE_RESERVED_8 = 8895 SEL_CALL_ERR_FLAG_COMPATIBLE_RESERVED_9 = 9896 SEL_CALL_ERR_FLAG_COMPATIBLE_RESERVED_10 = 10897 SEL_CALL_ERR_FLAG_PRIVATE_RESERVED_11 = 11898 SEL_CALL_ERR_FLAG_PRIVATE_RESERVED_12 = 12899 SEL_CALL_ERR_FLAG_PRIVATE_RESERVED_13 = 13900 SEL_CALL_ERR_FLAG_PRIVATE_RESERVED_14 = 14901 SEL_CALL_ERR_FLAG_PRIVATE_RESERVED_15 = 15902 SEL_CALL_ERR_FLAGS = {903 SEL_CALL_ERR_FLAG_UNUSED: 'unused',904 SEL_CALL_ERR_FLAG_REQ_MEM_AREA_NO_AVAIL: 'requested memory area '905 'not available',906 SEL_CALL_ERR_FLAG_INVALID_CHECKSUM: 'invalid checksum',907 SEL_CALL_ERR_FLAG_UNEXPECTED_COMMUNICATION_SERVICE: 'unexpected '908 'communication '909 'service',910 SEL_CALL_ERR_FLAG_UNEXPECTED_FILENAME: 'unexpected file name',911 SEL_CALL_ERR_FLAG_UNEXPECTED_SECTION_NAME: 'unexpected section name'912 }913 GENERATED_ATTRIBUTES = [914 ('SEL_CALL_FLAG_COMPATIBLE_RESERVED', 'compatible reserved',915 SEL_CALL_FLAGS, 8, 10),916 ('SEL_CALL_FLAG_PRIVATE_RESERVED', 'private reserved', SEL_CALL_FLAGS,917 11, 15),918 ('SEL_CALL_ERR_FLAG_COMPATIBLE_RESERVED', 'compatible reserved',919 SEL_CALL_ERR_FLAGS, 6, 10),920 ('SEL_CALL_ERR_FLAG_PRIVATE_RESERVED', 'private reserved',921 SEL_CALL_ERR_FLAGS, 11, 15)922 ]923 informantion_element_fields = [924 BitEnumField('errors', 0, 4, SEL_CALL_ERR_FLAGS),925 BitEnumField('select_call', 0, 4, SEL_CALL_FLAGS)926 ]927@_generate_attributes_and_dicts928class IEC104_IE_LSQ:929 """930 LSQ - last section or segment qualifier931 EN 60870-5-101:2003, sec. 7.2.6.31 (p. 55)932 """933 LSQ_FLAG_UNUSED = 0934 LSQ_FLAG_FILE_TRANSFER_NO_ABORT = 1935 LSQ_FLAG_FILE_TRANSFER_ABORT = 2936 LSQ_FLAG_SECTION_TRANSFER_NO_ABORT = 3937 LSQ_FLAG_SECTION_TRANSFER_ABORT = 4938 LSQ_FLAGS = {939 LSQ_FLAG_UNUSED: 'unused',940 LSQ_FLAG_FILE_TRANSFER_NO_ABORT: 'file transfer - no abort',941 LSQ_FLAG_FILE_TRANSFER_ABORT: 'file transfer - aborted',942 LSQ_FLAG_SECTION_TRANSFER_NO_ABORT: 'section transfer - no abort',943 LSQ_FLAG_SECTION_TRANSFER_ABORT: 'section transfer - aborted',944 }945 GENERATED_ATTRIBUTES = [946 ('LSQ_FLAG_COMPATIBLE_RESERVED', 'compatible reserved', LSQ_FLAGS, 5,947 127),948 ('LSQ_FLAG_PRIVATE_RESERVED', 'private reserved', LSQ_FLAGS, 128, 255),949 ]950 informantion_element_fields = [951 ByteEnumField('lsq', 0, LSQ_FLAGS)952 ]953@_generate_attributes_and_dicts954class IEC104_IE_AFQ:955 """956 AFQ - acknowledge file or section qualifier957 EN 60870-5-101:2003, sec. 7.2.6.32 (p. 55)958 """959 ACK_FILE_OR_SEC_FLAG_UNUSED = 0960 ACK_FILE_OR_SEC_FLAG_POSITIVE_ACK_FILE_TRANSFER = 1961 ACK_FILE_OR_SEC_FLAG_NEGATIVE_ACK_FILE_TRANSFER = 2962 ACK_FILE_OR_SEC_FLAG_POSITIVE_ACK_SECTION_TRANSFER = 3963 ACK_FILE_OR_SEC_FLAG_NEGATIVE_ACK_SECTION_TRANSFER = 4964 ACK_FILE_OR_SEC_FLAGS = {965 ACK_FILE_OR_SEC_FLAG_UNUSED: 'unused',966 ACK_FILE_OR_SEC_FLAG_POSITIVE_ACK_FILE_TRANSFER: 'positive acknowledge'967 ' file transfer',968 ACK_FILE_OR_SEC_FLAG_NEGATIVE_ACK_FILE_TRANSFER: 'negative acknowledge'969 ' file transfer',970 ACK_FILE_OR_SEC_FLAG_POSITIVE_ACK_SECTION_TRANSFER: 'positive '971 'acknowledge '972 'section transfer',973 ACK_FILE_OR_SEC_FLAG_NEGATIVE_ACK_SECTION_TRANSFER: 'negative '974 'acknowledge '975 'section transfer'976 }977 ACK_FILE_OR_SEC_ERR_FLAG_UNUSED = 0978 ACK_FILE_OR_SEC_ERR_FLAG_REQ_MEM_AREA_NO_AVAIL = 1979 ACK_FILE_OR_SEC_ERR_FLAG_INVALID_CHECKSUM = 2980 ACK_FILE_OR_SEC_ERR_FLAG_UNEXPECTED_COMMUNICATION_SERVICE = 3981 ACK_FILE_OR_SEC_ERR_FLAG_UNEXPECTED_FILENAME = 4982 ACK_FILE_OR_SEC_ERR_FLAG_UNEXPECTED_SECTION_NAME = 5983 ACK_FILE_OR_SEC_ERR_FLAGS = {984 ACK_FILE_OR_SEC_ERR_FLAG_UNUSED: 'unused',985 ACK_FILE_OR_SEC_ERR_FLAG_REQ_MEM_AREA_NO_AVAIL: 'requested memory '986 'area not available',987 ACK_FILE_OR_SEC_ERR_FLAG_INVALID_CHECKSUM: 'invalid checksum',988 ACK_FILE_OR_SEC_ERR_FLAG_UNEXPECTED_COMMUNICATION_SERVICE: 'unexpected'989 ' communica'990 'tion '991 'service',992 ACK_FILE_OR_SEC_ERR_FLAG_UNEXPECTED_FILENAME: 'unexpected file name',993 ACK_FILE_OR_SEC_ERR_FLAG_UNEXPECTED_SECTION_NAME: 'unexpected '994 'section name'995 }996 GENERATED_ATTRIBUTES = [997 ('ACK_FILE_OR_SEC_FLAG_COMPATIBLE_RESERVED', 'compatible reserved',998 ACK_FILE_OR_SEC_FLAGS, 5, 10),999 ('ACK_FILE_OR_SEC_FLAG_PRIVATE_RESERVED', 'private reserved',1000 ACK_FILE_OR_SEC_FLAGS, 11, 15),1001 ('ACK_FILE_OR_SEC_ERR_FLAG_COMPATIBLE_RESERVED', 'compatible reserved',1002 ACK_FILE_OR_SEC_ERR_FLAGS, 6, 10),1003 ('ACK_FILE_OR_SEC_ERR_FLAG_PRIVATE_RESERVED', 'private reserved',1004 ACK_FILE_OR_SEC_ERR_FLAGS, 11, 15)1005 ]1006 informantion_element_fields = [1007 BitEnumField('errors', 0, 4, ACK_FILE_OR_SEC_ERR_FLAGS),1008 BitEnumField('ack_file_or_sec', 0, 4, ACK_FILE_OR_SEC_FLAGS)1009 ]1010class IEC104_IE_NOF:1011 """1012 NOF - name of file1013 EN 60870-5-101:2003, sec. 7.2.6.33 (p. 56)1014 """1015 informantion_element_fields = [1016 LEShortField('file_name', 0)1017 ]1018class IEC104_IE_NOS:1019 """1020 NOS - name of section1021 EN 60870-5-101:2003, sec. 7.2.6.34 (p. 56)1022 """1023 informantion_element_fields = [1024 ByteField('section_name', 0)1025 ]1026class IEC104_IE_LOF:1027 """1028 LOF - length of file or section1029 EN 60870-5-101:2003, sec. 7.2.6.35 (p. 55)1030 """1031 informantion_element_fields = [1032 ThreeBytesField('file_length', 0)1033 ]1034class IEC104_IE_LOS:1035 """1036 LOS - length of segment1037 EN 60870-5-101:2003, sec. 7.2.6.36 (p. 56)1038 """1039 informantion_element_fields = [1040 ByteField('segment_length', 0)1041 ]1042class IEC104_IE_CHS:1043 """1044 CHS - checksum1045 EN 60870-5-101:2003, sec. 7.2.6.37 (p. 56)1046 """1047 informantion_element_fields = [1048 ByteField('checksum', 0)1049 ]1050@_generate_attributes_and_dicts1051class IEC104_IE_SOF:1052 """1053 SOF - status of file1054 EN 60870-5-101:2003, sec. 7.2.6.38 (p. 56)1055 """1056 STATUS_FLAG_UNUSED = 01057 STATUS_FLAGS = {1058 STATUS_FLAG_UNUSED: 'unused'1059 }1060 GENERATED_ATTRIBUTES = [1061 ('STATUS_FLAG_COMPATIBLE_RESERVED', 'compatible reserved',1062 STATUS_FLAGS, 1, 15),1063 ('STATUS_FLAG_PRIVATE_RESERVED', 'private reserved',1064 STATUS_FLAGS, 16, 32)1065 ]1066 LFD_FLAG_NEXT_FILE_OF_DIR_FOLLOWS = 01067 LFD_FLAG_LAST_FILE_OF_DIR = 11068 LFD_FLAGS = {1069 LFD_FLAG_NEXT_FILE_OF_DIR_FOLLOWS: 'next file of dir follows',1070 LFD_FLAG_LAST_FILE_OF_DIR: 'last file of dir'1071 }1072 FOR_FLAG_NAME_DEFINES_FILE = 01073 FOR_FLAG_NAME_DEFINES_SUBDIR = 11074 FOR_FLAGS = {1075 FOR_FLAG_NAME_DEFINES_FILE: 'name defines file',1076 FOR_FLAG_NAME_DEFINES_SUBDIR: 'name defines subdirectory'1077 }1078 FA_FLAG_FILE_WAITS_FOR_TRANSFER = 01079 FA_FLAG_FILE_TRANSFER_IS_ACTIVE = 11080 FA_FLAGS = {1081 FA_FLAG_FILE_WAITS_FOR_TRANSFER: 'file waits for transfer',1082 FA_FLAG_FILE_TRANSFER_IS_ACTIVE: 'transfer of file active'1083 }1084 informantion_element_fields = [1085 BitEnumField('fa', 0, 1, FA_FLAGS),1086 BitEnumField('for', 0, 1, FOR_FLAGS),1087 BitEnumField('lfd', 0, 1, LFD_FLAGS),1088 BitEnumField('status', 0, 5, STATUS_FLAGS)1089 ]1090@_generate_attributes_and_dicts1091class IEC104_IE_QOS:1092 """1093 QOS - qualifier of set-point command1094 EN 60870-5-101:2003, sec. 7.2.6.39 (p. 57)1095 """1096 QL_FLAG_UNUSED = 01097 QL_FLAGS = {1098 QL_FLAG_UNUSED: 'unused'1099 }1100 GENERATED_ATTRIBUTES = [1101 ('QL_FLAG_COMPATIBLE_RESERVED', 'compatible reserved',1102 QL_FLAGS, 1, 63),1103 ('QL_FLAG_PRIVATE_RESERVED', 'private reserved',1104 QL_FLAGS, 64, 127)1105 ]1106 SE_FLAG_EXECUTE = 01107 SE_FLAG_SELECT = 11108 SE_FLAGS = {1109 SE_FLAG_EXECUTE: 'execute',1110 SE_FLAG_SELECT: 'select'1111 }1112 informantion_element_fields = [1113 BitEnumField('action', 0, 1, SE_FLAGS),1114 BitEnumField('ql', 0, 7, QL_FLAGS)1115 ]1116class IEC104_IE_SCD:1117 """1118 SCD - status and status change detection1119 EN 60870-5-101:2003, sec. 7.2.6.40 (p. 57)1120 """1121 ST_FLAG_STATE_OFF = 01122 ST_FLAG_STATE_ON = 11123 ST_FLAGS = {1124 ST_FLAG_STATE_OFF: 'off',1125 ST_FLAG_STATE_ON: 'on'1126 }1127 CD_FLAG_STATE_NOT_CHANGED = 01128 CD_FLAG_STATE_CHANGED = 11129 CD_FLAGS = {1130 CD_FLAG_STATE_NOT_CHANGED: 'state not changed',1131 CD_FLAG_STATE_CHANGED: 'state changed'1132 }1133 informantion_element_fields = [1134 BitEnumField('cd_16', 0, 1, CD_FLAGS),1135 BitEnumField('cd_15', 0, 1, CD_FLAGS),1136 BitEnumField('cd_14', 0, 1, CD_FLAGS),1137 BitEnumField('cd_13', 0, 1, CD_FLAGS),1138 BitEnumField('cd_12', 0, 1, CD_FLAGS),1139 BitEnumField('cd_11', 0, 1, CD_FLAGS),1140 BitEnumField('cd_10', 0, 1, CD_FLAGS),1141 BitEnumField('cd_9', 0, 1, CD_FLAGS),1142 BitEnumField('cd_8', 0, 1, CD_FLAGS),1143 BitEnumField('cd_7', 0, 1, CD_FLAGS),1144 BitEnumField('cd_6', 0, 1, CD_FLAGS),1145 BitEnumField('cd_5', 0, 1, CD_FLAGS),1146 BitEnumField('cd_4', 0, 1, CD_FLAGS),1147 BitEnumField('cd_3', 0, 1, CD_FLAGS),1148 BitEnumField('cd_2', 0, 1, CD_FLAGS),1149 BitEnumField('cd_1', 0, 1, CD_FLAGS),1150 BitEnumField('st_16', 0, 1, ST_FLAGS),1151 BitEnumField('st_15', 0, 1, ST_FLAGS),1152 BitEnumField('st_14', 0, 1, ST_FLAGS),1153 BitEnumField('st_13', 0, 1, ST_FLAGS),1154 BitEnumField('st_12', 0, 1, ST_FLAGS),1155 BitEnumField('st_11', 0, 1, ST_FLAGS),1156 BitEnumField('st_10', 0, 1, ST_FLAGS),1157 BitEnumField('st_9', 0, 1, ST_FLAGS),1158 BitEnumField('st_8', 0, 1, ST_FLAGS),1159 BitEnumField('st_7', 0, 1, ST_FLAGS),1160 BitEnumField('st_6', 0, 1, ST_FLAGS),1161 BitEnumField('st_5', 0, 1, ST_FLAGS),1162 BitEnumField('st_4', 0, 1, ST_FLAGS),1163 BitEnumField('st_3', 0, 1, ST_FLAGS),1164 BitEnumField('st_2', 0, 1, ST_FLAGS),1165 BitEnumField('st_1', 0, 1, ST_FLAGS),1166 ]1167class IEC104_IE_TSC:1168 """1169 TSC - test sequence counter1170 EN 60870-5-104:2006, sec. 8.8 (p. 44)1171 """1172 informantion_element_fields = [1173 LEShortField('tsc', 0)...
gflags.pyi
Source:gflags.pyi
...31 def flags_by_module_id_dict(self) -> Dict[int, List[Flag]]: ...32 FlagsByModuleIdDict = flags_by_module_id_dict33 def key_flags_by_module_dict(self) -> Dict[str, List[Flag]]: ...34 KeyFlagsByModuleDict = key_flags_by_module_dict35 def find_module_defining_flag(self, flagname: str, default: str = ...) -> str: ...36 FindModuleDefiningFlag = find_module_defining_flag37 def find_module_id_defining_flag(self, flagname: str, default: int = ...) -> int: ...38 FindModuleIdDefiningFlag = find_module_id_defining_flag39 def append_flag_values(self, flag_values: FlagValues) -> None: ...40 AppendFlagValues = append_flag_values41 def remove_flag_values(self, flag_values: FlagValues) -> None: ...42 RemoveFlagValues = remove_flag_values43 def __setitem__(self, name: str, flag: Flag) -> None: ...44 def __getitem__(self, name: str) -> Flag: ...45 def __getattr__(self, name: str) -> Any: ...46 def __setattr__(self, name: str, value: Any): ...47 def __delattr__(self, flag_name: str) -> None: ...48 def set_default(self, name: str, value: Any) -> None: ...49 SetDefault = set_default50 def __contains__(self, name: str) -> bool: ...51 has_key = __contains__52 def __iter__(self) -> Iterable[str]: ...53 def __call__(self, argv: List[str], known_only: bool = ...) -> List[str]: ...54 def reset(self) -> None: ...55 Reset = reset56 def RegisteredFlags(self) -> List[str]: ...57 def flag_values_dict(self) -> Dict[str, Any]: ...58 FlagValuesDict = flag_values_dict59 def __str__(self) -> str: ...60 def GetHelp(self, prefix: str = ...) -> str: ...61 def module_help(self, module: Union[ModuleType, str]) -> str: ...62 ModuleHelp = module_help63 def main_module_help(self) -> str: ...64 MainModuleHelp = main_module_help65 def get(self, name: str, default: Any) -> Any: ...66 def ShortestUniquePrefixes(self, fl: Dict[str, Flag]) -> Dict[str, str]: ...67 def ExtractFilename(self, flagfile_str: str) -> str: ...68 def read_flags_from_files(self, argv: List[str], force_gnu: bool = ...) -> List[str]: ...69 ReadFlagsFromFiles = read_flags_from_files70 def flags_into_string(self) -> str: ...71 FlagsIntoString = flags_into_string72 def append_flags_into_file(self, filename: str) -> None: ...73 AppendFlagsIntoFile = append_flags_into_file74 def write_help_in_xml_format(self, outfile: IO[str] = ...) -> None: ...75 WriteHelpInXMLFormat = write_help_in_xml_format76 # TODO validator: gflags_validators.Validator77 def AddValidator(self, validator: Any) -> None: ...78FLAGS: FlagValues79class Flag:80 name: str81 default: Any82 default_as_str: str83 value: Any84 help: str85 short_name: str86 boolean = False87 present = False88 parser: ArgumentParser89 serializer: ArgumentSerializer90 allow_override = False91 def __init__(self, parser: ArgumentParser, serializer: ArgumentSerializer, name: str,92 default: Optional[str], help_string: str, short_name: str = ..., boolean: bool = ...,93 allow_override: bool = ...) -> None: ...94 def Parse(self, argument: Any) -> Any: ...95 def Unparse(self) -> None: ...96 def Serialize(self) -> str: ...97 def SetDefault(self, value: Any) -> None: ...98 def Type(self) -> str: ...99 def WriteInfoInXMLFormat(self, outfile: IO[str], module_name: str, is_key: bool = ..., indent: str = ...) -> None: ...100class ArgumentParser(object):101 syntactic_help: str102 # TODO what is this103 def parse(self, argument: Any) -> Any: ...104 Parser = parse105 def flag_type(self) -> str: ...106 Type = flag_type107 def WriteCustomInfoInXMLFormat(self, outfile: IO[str], indent: str) -> None: ...108class ArgumentSerializer:109 def Serialize(self, value: Any) -> unicode: ...110class ListSerializer(ArgumentSerializer):111 def __init__(self, list_sep: str) -> None: ...112 def Serialize(self, value: List[Any]) -> str: ...113def register_validator(flag_name: str,114 checker: Callable[[Any], bool],115 message: str = ...,116 flag_values: FlagValues = ...) -> None: ...117RegisterValidator = register_validator118def mark_flag_as_required(flag_name: str, flag_values: FlagValues = ...) -> None: ...119MarkFlagAsRequired = mark_flag_as_required120def DEFINE(parser: ArgumentParser, name: str, default: Any, help: str,121 flag_values: FlagValues = ..., serializer: ArgumentSerializer = ..., **args: Any) -> None: ...122def DEFINE_flag(flag: Flag, flag_values: FlagValues = ...) -> None: ...123def declare_key_flag(flag_name: str, flag_values: FlagValues = ...) -> None: ...124DECLARE_key_flag = declare_key_flag125def adopt_module_key_flags(module: ModuleType, flag_values: FlagValues = ...) -> None: ...126ADOPT_module_key_flags = adopt_module_key_flags127def DEFINE_string(name: str, default: Optional[str], help: str, flag_values: FlagValues = ..., **args: Any): ...128class BooleanParser(ArgumentParser):129 def Convert(self, argument: Any) -> bool: ...130 def Parse(self, argument: Any) -> bool: ...131class BooleanFlag(Flag):132 def __init__(self, name: str, default: Optional[bool], help: str, short_name=..., **args: Any) -> None: ...133def DEFINE_boolean(name: str, default: Optional[bool], help: str, flag_values: FlagValues = ..., **args: Any) -> None: ...134DEFINE_bool = DEFINE_boolean135class HelpFlag(BooleanFlag):136 def __init__(self) -> None: ...137 def Parse(self, arg: Any) -> None: ......
flags.py
Source:flags.py
1# This Source Code Form is subject to the terms of the Mozilla Public2# License, v. 2.0. If a copy of the MPL was not distributed with this3# file, You can obtain one at http://mozilla.org/MPL/2.0/.4from __future__ import absolute_import5import re6from distutils.version import LooseVersion7from mozpack.errors import errors8from collections import OrderedDict9class Flag(object):10 '''11 Class for flags in manifest entries in the form:12 "flag" (same as "flag=true")13 "flag=yes|true|1"14 "flag=no|false|0"15 '''16 def __init__(self, name):17 '''18 Initialize a Flag with the given name.19 '''20 self.name = name21 self.value = None22 def add_definition(self, definition):23 '''24 Add a flag value definition. Replaces any previously set value.25 '''26 if definition == self.name:27 self.value = True28 return29 assert(definition.startswith(self.name))30 if definition[len(self.name)] != '=':31 return errors.fatal('Malformed flag: %s' % definition)32 value = definition[len(self.name) + 1:]33 if value in ('yes', 'true', '1', 'no', 'false', '0'):34 self.value = value35 else:36 return errors.fatal('Unknown value in: %s' % definition)37 def matches(self, value):38 '''39 Return whether the flag value matches the given value. The values40 are canonicalized for comparison.41 '''42 if value in ('yes', 'true', '1', True):43 return self.value in ('yes', 'true', '1', True)44 if value in ('no', 'false', '0', False):45 return self.value in ('no', 'false', '0', False, None)46 raise RuntimeError('Invalid value: %s' % value)47 def __str__(self):48 '''49 Serialize the flag value in the same form given to the last50 add_definition() call.51 '''52 if self.value is None:53 return ''54 if self.value is True:55 return self.name56 return '%s=%s' % (self.name, self.value)57 def __eq__(self, other):58 return str(self) == other59class StringFlag(object):60 '''61 Class for string flags in manifest entries in the form:62 "flag=string"63 "flag!=string"64 '''65 def __init__(self, name):66 '''67 Initialize a StringFlag with the given name.68 '''69 self.name = name70 self.values = []71 def add_definition(self, definition):72 '''73 Add a string flag definition.74 '''75 assert(definition.startswith(self.name))76 value = definition[len(self.name):]77 if value.startswith('='):78 self.values.append(('==', value[1:]))79 elif value.startswith('!='):80 self.values.append(('!=', value[2:]))81 else:82 return errors.fatal('Malformed flag: %s' % definition)83 def matches(self, value):84 '''85 Return whether one of the string flag definitions matches the given86 value.87 For example,88 flag = StringFlag('foo')89 flag.add_definition('foo!=bar')90 flag.matches('bar') returns False91 flag.matches('qux') returns True92 flag = StringFlag('foo')93 flag.add_definition('foo=bar')94 flag.add_definition('foo=baz')95 flag.matches('bar') returns True96 flag.matches('baz') returns True97 flag.matches('qux') returns False98 '''99 if not self.values:100 return True101 for comparison, val in self.values:102 if eval('value %s val' % comparison):103 return True104 return False105 def __str__(self):106 '''107 Serialize the flag definitions in the same form given to each108 add_definition() call.109 '''110 res = []111 for comparison, val in self.values:112 if comparison == '==':113 res.append('%s=%s' % (self.name, val))114 else:115 res.append('%s!=%s' % (self.name, val))116 return ' '.join(res)117 def __eq__(self, other):118 return str(self) == other119class VersionFlag(object):120 '''121 Class for version flags in manifest entries in the form:122 "flag=version"123 "flag<=version"124 "flag<version"125 "flag>=version"126 "flag>version"127 '''128 def __init__(self, name):129 '''130 Initialize a VersionFlag with the given name.131 '''132 self.name = name133 self.values = []134 def add_definition(self, definition):135 '''136 Add a version flag definition.137 '''138 assert(definition.startswith(self.name))139 value = definition[len(self.name):]140 if value.startswith('='):141 self.values.append(('==', LooseVersion(value[1:])))142 elif len(value) > 1 and value[0] in ['<', '>']:143 if value[1] == '=':144 if len(value) < 3:145 return errors.fatal('Malformed flag: %s' % definition)146 self.values.append((value[0:2], LooseVersion(value[2:])))147 else:148 self.values.append((value[0], LooseVersion(value[1:])))149 else:150 return errors.fatal('Malformed flag: %s' % definition)151 def matches(self, value):152 '''153 Return whether one of the version flag definitions matches the given154 value.155 For example,156 flag = VersionFlag('foo')157 flag.add_definition('foo>=1.0')158 flag.matches('1.0') returns True159 flag.matches('1.1') returns True160 flag.matches('0.9') returns False161 flag = VersionFlag('foo')162 flag.add_definition('foo>=1.0')163 flag.add_definition('foo<0.5')164 flag.matches('0.4') returns True165 flag.matches('1.0') returns True166 flag.matches('0.6') returns False167 '''168 value = LooseVersion(value)169 if not self.values:170 return True171 for comparison, val in self.values:172 if eval('value %s val' % comparison):173 return True174 return False175 def __str__(self):176 '''177 Serialize the flag definitions in the same form given to each178 add_definition() call.179 '''180 res = []181 for comparison, val in self.values:182 if comparison == '==':183 res.append('%s=%s' % (self.name, val))184 else:185 res.append('%s%s%s' % (self.name, comparison, val))186 return ' '.join(res)187 def __eq__(self, other):188 return str(self) == other189class Flags(OrderedDict):190 '''191 Class to handle a set of flags definitions given on a single manifest192 entry.193 '''194 FLAGS = {195 'application': StringFlag,196 'appversion': VersionFlag,197 'platformversion': VersionFlag,198 'contentaccessible': Flag,199 'os': StringFlag,200 'osversion': VersionFlag,201 'abi': StringFlag,202 'platform': Flag,203 'xpcnativewrappers': Flag,204 'tablet': Flag,205 'process': StringFlag,206 }207 RE = re.compile(r'([!<>=]+)')208 def __init__(self, *flags):209 '''210 Initialize a set of flags given in string form.211 flags = Flags('contentaccessible=yes', 'appversion>=3.5')212 '''213 OrderedDict.__init__(self)214 for f in flags:215 name = self.RE.split(f)216 name = name[0]217 if not name in self.FLAGS:218 errors.fatal('Unknown flag: %s' % name)219 continue220 if not name in self:221 self[name] = self.FLAGS[name](name)222 self[name].add_definition(f)223 def __str__(self):224 '''225 Serialize the set of flags.226 '''227 return ' '.join(str(self[k]) for k in self)228 def match(self, **filter):229 '''230 Return whether the set of flags match the set of given filters.231 flags = Flags('contentaccessible=yes', 'appversion>=3.5',232 'application=foo')233 flags.match(application='foo') returns True234 flags.match(application='foo', appversion='3.5') returns True235 flags.match(application='foo', appversion='3.0') returns False236 '''237 for name, value in filter.iteritems():238 if not name in self:239 continue240 if not self[name].matches(value):241 return False...
gflags_validators_test.py
Source:gflags_validators_test.py
1#!/usr/bin/env python2# Copyright (c) 2010, Google Inc.3# All rights reserved.4#5# Redistribution and use in source and binary forms, with or without6# modification, are permitted provided that the following conditions are7# met:8#9# * Redistributions of source code must retain the above copyright10# notice, this list of conditions and the following disclaimer.11# * Redistributions in binary form must reproduce the above12# copyright notice, this list of conditions and the following disclaimer13# in the documentation and/or other materials provided with the14# distribution.15# * Neither the name of Google Inc. nor the names of its16# contributors may be used to endorse or promote products derived from17# this software without specific prior written permission.18#19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS20# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT21# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR22# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT23# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,24# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT25# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,26# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY27# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT28# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE29# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.30"""Testing that flags validators framework does work.31This file tests that each flag validator called when it should be, and that32failed validator will throw an exception, etc.33"""34__author__ = 'olexiy@google.com (Olexiy Oryeshko)'35import gflags_googletest as googletest36import gflags37import gflags_validators38class SimpleValidatorTest(googletest.TestCase):39 """Testing gflags.RegisterValidator() method."""40 def setUp(self):41 super(SimpleValidatorTest, self).setUp()42 self.flag_values = gflags.FlagValues()43 self.call_args = []44 def testSuccess(self):45 def Checker(x):46 self.call_args.append(x)47 return True48 gflags.DEFINE_integer('test_flag', None, 'Usual integer flag',49 flag_values=self.flag_values)50 gflags.RegisterValidator('test_flag',51 Checker,52 message='Errors happen',53 flag_values=self.flag_values)54 argv = ('./program')55 self.flag_values(argv)56 self.assertEquals(None, self.flag_values.test_flag)57 self.flag_values.test_flag = 258 self.assertEquals(2, self.flag_values.test_flag)59 self.assertEquals([None, 2], self.call_args)60 def testDefaultValueNotUsedSuccess(self):61 def Checker(x):62 self.call_args.append(x)63 return True64 gflags.DEFINE_integer('test_flag', None, 'Usual integer flag',65 flag_values=self.flag_values)66 gflags.RegisterValidator('test_flag',67 Checker,68 message='Errors happen',69 flag_values=self.flag_values)70 argv = ('./program', '--test_flag=1')71 self.flag_values(argv)72 self.assertEquals(1, self.flag_values.test_flag)73 self.assertEquals([1], self.call_args)74 def testValidatorNotCalledWhenOtherFlagIsChanged(self):75 def Checker(x):76 self.call_args.append(x)77 return True78 gflags.DEFINE_integer('test_flag', 1, 'Usual integer flag',79 flag_values=self.flag_values)80 gflags.DEFINE_integer('other_flag', 2, 'Other integer flag',81 flag_values=self.flag_values)82 gflags.RegisterValidator('test_flag',83 Checker,84 message='Errors happen',85 flag_values=self.flag_values)86 argv = ('./program')87 self.flag_values(argv)88 self.assertEquals(1, self.flag_values.test_flag)89 self.flag_values.other_flag = 390 self.assertEquals([1], self.call_args)91 def testExceptionRaisedIfCheckerFails(self):92 def Checker(x):93 self.call_args.append(x)94 return x == 195 gflags.DEFINE_integer('test_flag', None, 'Usual integer flag',96 flag_values=self.flag_values)97 gflags.RegisterValidator('test_flag',98 Checker,99 message='Errors happen',100 flag_values=self.flag_values)101 argv = ('./program', '--test_flag=1')102 self.flag_values(argv)103 try:104 self.flag_values.test_flag = 2105 raise AssertionError('gflags.IllegalFlagValue expected')106 except gflags.IllegalFlagValue, e:107 self.assertEquals('flag --test_flag=2: Errors happen', str(e))108 self.assertEquals([1, 2], self.call_args)109 def testExceptionRaisedIfCheckerRaisesException(self):110 def Checker(x):111 self.call_args.append(x)112 if x == 1:113 return True114 raise gflags_validators.Error('Specific message')115 gflags.DEFINE_integer('test_flag', None, 'Usual integer flag',116 flag_values=self.flag_values)117 gflags.RegisterValidator('test_flag',118 Checker,119 message='Errors happen',120 flag_values=self.flag_values)121 argv = ('./program', '--test_flag=1')122 self.flag_values(argv)123 try:124 self.flag_values.test_flag = 2125 raise AssertionError('gflags.IllegalFlagValue expected')126 except gflags.IllegalFlagValue, e:127 self.assertEquals('flag --test_flag=2: Specific message', str(e))128 self.assertEquals([1, 2], self.call_args)129 def testErrorMessageWhenCheckerReturnsFalseOnStart(self):130 def Checker(x):131 self.call_args.append(x)132 return False133 gflags.DEFINE_integer('test_flag', None, 'Usual integer flag',134 flag_values=self.flag_values)135 gflags.RegisterValidator('test_flag',136 Checker,137 message='Errors happen',138 flag_values=self.flag_values)139 argv = ('./program', '--test_flag=1')140 try:141 self.flag_values(argv)142 raise AssertionError('gflags.IllegalFlagValue expected')143 except gflags.IllegalFlagValue, e:144 self.assertEquals('flag --test_flag=1: Errors happen', str(e))145 self.assertEquals([1], self.call_args)146 def testErrorMessageWhenCheckerRaisesExceptionOnStart(self):147 def Checker(x):148 self.call_args.append(x)149 raise gflags_validators.Error('Specific message')150 gflags.DEFINE_integer('test_flag', None, 'Usual integer flag',151 flag_values=self.flag_values)152 gflags.RegisterValidator('test_flag',153 Checker,154 message='Errors happen',155 flag_values=self.flag_values)156 argv = ('./program', '--test_flag=1')157 try:158 self.flag_values(argv)159 raise AssertionError('IllegalFlagValue expected')160 except gflags.IllegalFlagValue, e:161 self.assertEquals('flag --test_flag=1: Specific message', str(e))162 self.assertEquals([1], self.call_args)163 def testValidatorsCheckedInOrder(self):164 def Required(x):165 self.calls.append('Required')166 return x is not None167 def Even(x):168 self.calls.append('Even')169 return x % 2 == 0170 self.calls = []171 self._DefineFlagAndValidators(Required, Even)172 self.assertEquals(['Required', 'Even'], self.calls)173 self.calls = []174 self._DefineFlagAndValidators(Even, Required)175 self.assertEquals(['Even', 'Required'], self.calls)176 def _DefineFlagAndValidators(self, first_validator, second_validator):177 local_flags = gflags.FlagValues()178 gflags.DEFINE_integer('test_flag', 2, 'test flag', flag_values=local_flags)179 gflags.RegisterValidator('test_flag',180 first_validator,181 message='',182 flag_values=local_flags)183 gflags.RegisterValidator('test_flag',184 second_validator,185 message='',186 flag_values=local_flags)187 argv = ('./program')188 local_flags(argv)189if __name__ == '__main__':...
gtest_help_test.py
Source:gtest_help_test.py
1#!/usr/bin/env python2#3# Copyright 2009, Google Inc.4# All rights reserved.5#6# Redistribution and use in source and binary forms, with or without7# modification, are permitted provided that the following conditions are8# met:9#10# * Redistributions of source code must retain the above copyright11# notice, this list of conditions and the following disclaimer.12# * Redistributions in binary form must reproduce the above13# copyright notice, this list of conditions and the following disclaimer14# in the documentation and/or other materials provided with the15# distribution.16# * Neither the name of Google Inc. nor the names of its17# contributors may be used to endorse or promote products derived from18# this software without specific prior written permission.19#20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS21# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT22# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR23# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT24# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,25# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT26# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,27# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY28# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE30# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.31"""Tests the --help flag of Google C++ Testing Framework.32SYNOPSIS33 gtest_help_test.py --build_dir=BUILD/DIR34 # where BUILD/DIR contains the built gtest_help_test_ file.35 gtest_help_test.py36"""37__author__ = 'wan@google.com (Zhanyong Wan)'38import os39import re40import gtest_test_utils41IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux'42IS_WINDOWS = os.name == 'nt'43PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('gtest_help_test_')44FLAG_PREFIX = '--gtest_'45DEATH_TEST_STYLE_FLAG = FLAG_PREFIX + 'death_test_style'46STREAM_RESULT_TO_FLAG = FLAG_PREFIX + 'stream_result_to'47UNKNOWN_FLAG = FLAG_PREFIX + 'unknown_flag_for_testing'48LIST_TESTS_FLAG = FLAG_PREFIX + 'list_tests'49INCORRECT_FLAG_VARIANTS = [re.sub('^--', '-', LIST_TESTS_FLAG),50 re.sub('^--', '/', LIST_TESTS_FLAG),51 re.sub('_', '-', LIST_TESTS_FLAG)]52INTERNAL_FLAG_FOR_TESTING = FLAG_PREFIX + 'internal_flag_for_testing'53SUPPORTS_DEATH_TESTS = "DeathTest" in gtest_test_utils.Subprocess(54 [PROGRAM_PATH, LIST_TESTS_FLAG]).output55# The help message must match this regex.56HELP_REGEX = re.compile(57 FLAG_PREFIX + r'list_tests.*' +58 FLAG_PREFIX + r'filter=.*' +59 FLAG_PREFIX + r'also_run_disabled_tests.*' +60 FLAG_PREFIX + r'repeat=.*' +61 FLAG_PREFIX + r'shuffle.*' +62 FLAG_PREFIX + r'random_seed=.*' +63 FLAG_PREFIX + r'color=.*' +64 FLAG_PREFIX + r'print_time.*' +65 FLAG_PREFIX + r'output=.*' +66 FLAG_PREFIX + r'break_on_failure.*' +67 FLAG_PREFIX + r'throw_on_failure.*' +68 FLAG_PREFIX + r'catch_exceptions=0.*',69 re.DOTALL)70def RunWithFlag(flag):71 """Runs gtest_help_test_ with the given flag.72 Returns:73 the exit code and the text output as a tuple.74 Args:75 flag: the command-line flag to pass to gtest_help_test_, or None.76 """77 if flag is None:78 command = [PROGRAM_PATH]79 else:80 command = [PROGRAM_PATH, flag]81 child = gtest_test_utils.Subprocess(command)82 return child.exit_code, child.output83class GTestHelpTest(gtest_test_utils.TestCase):84 """Tests the --help flag and its equivalent forms."""85 def TestHelpFlag(self, flag):86 """Verifies correct behavior when help flag is specified.87 The right message must be printed and the tests must88 skipped when the given flag is specified.89 Args:90 flag: A flag to pass to the binary or None.91 """92 exit_code, output = RunWithFlag(flag)93 self.assertEquals(0, exit_code)94 self.assert_(HELP_REGEX.search(output), output)95 if IS_LINUX:96 self.assert_(STREAM_RESULT_TO_FLAG in output, output)97 else:98 self.assert_(STREAM_RESULT_TO_FLAG not in output, output)99 if SUPPORTS_DEATH_TESTS and not IS_WINDOWS:100 self.assert_(DEATH_TEST_STYLE_FLAG in output, output)101 else:102 self.assert_(DEATH_TEST_STYLE_FLAG not in output, output)103 def TestNonHelpFlag(self, flag):104 """Verifies correct behavior when no help flag is specified.105 Verifies that when no help flag is specified, the tests are run106 and the help message is not printed.107 Args:108 flag: A flag to pass to the binary or None.109 """110 exit_code, output = RunWithFlag(flag)111 self.assert_(exit_code != 0)112 self.assert_(not HELP_REGEX.search(output), output)113 def testPrintsHelpWithFullFlag(self):114 self.TestHelpFlag('--help')115 def testPrintsHelpWithShortFlag(self):116 self.TestHelpFlag('-h')117 def testPrintsHelpWithQuestionFlag(self):118 self.TestHelpFlag('-?')119 def testPrintsHelpWithWindowsStyleQuestionFlag(self):120 self.TestHelpFlag('/?')121 def testPrintsHelpWithUnrecognizedGoogleTestFlag(self):122 self.TestHelpFlag(UNKNOWN_FLAG)123 def testPrintsHelpWithIncorrectFlagStyle(self):124 for incorrect_flag in INCORRECT_FLAG_VARIANTS:125 self.TestHelpFlag(incorrect_flag)126 def testRunsTestsWithoutHelpFlag(self):127 """Verifies that when no help flag is specified, the tests are run128 and the help message is not printed."""129 self.TestNonHelpFlag(None)130 def testRunsTestsWithGtestInternalFlag(self):131 """Verifies that the tests are run and no help message is printed when132 a flag starting with Google Test prefix and 'internal_' is supplied."""133 self.TestNonHelpFlag(INTERNAL_FLAG_FOR_TESTING)134if __name__ == '__main__':...
test_chrome_flags.py
Source:test_chrome_flags.py
...10 Flags,11)12from mozpack.errors import ErrorMessage13class TestFlag(unittest.TestCase):14 def test_flag(self):15 flag = Flag('flag')16 self.assertEqual(str(flag), '')17 self.assertTrue(flag.matches(False))18 self.assertTrue(flag.matches('false'))19 self.assertFalse(flag.matches('true'))20 self.assertRaises(ErrorMessage, flag.add_definition, 'flag=')21 self.assertRaises(ErrorMessage, flag.add_definition, 'flag=42')22 self.assertRaises(ErrorMessage, flag.add_definition, 'flag!=false')23 flag.add_definition('flag=1')24 self.assertEqual(str(flag), 'flag=1')25 self.assertTrue(flag.matches(True))26 self.assertTrue(flag.matches('1'))27 self.assertFalse(flag.matches('no'))28 flag.add_definition('flag=true')29 self.assertEqual(str(flag), 'flag=true')30 self.assertTrue(flag.matches(True))31 self.assertTrue(flag.matches('true'))32 self.assertFalse(flag.matches('0'))33 flag.add_definition('flag=no')34 self.assertEqual(str(flag), 'flag=no')35 self.assertTrue(flag.matches('false'))36 self.assertFalse(flag.matches('1'))37 flag.add_definition('flag')38 self.assertEqual(str(flag), 'flag')39 self.assertFalse(flag.matches('false'))40 self.assertTrue(flag.matches('true'))41 self.assertFalse(flag.matches(False))42 def test_string_flag(self):43 flag = StringFlag('flag')44 self.assertEqual(str(flag), '')45 self.assertTrue(flag.matches('foo'))46 self.assertRaises(ErrorMessage, flag.add_definition, 'flag>=2')47 flag.add_definition('flag=foo')48 self.assertEqual(str(flag), 'flag=foo')49 self.assertTrue(flag.matches('foo'))50 self.assertFalse(flag.matches('bar'))51 flag.add_definition('flag=bar')52 self.assertEqual(str(flag), 'flag=foo flag=bar')53 self.assertTrue(flag.matches('foo'))54 self.assertTrue(flag.matches('bar'))55 self.assertFalse(flag.matches('baz'))56 flag = StringFlag('flag')57 flag.add_definition('flag!=bar')58 self.assertEqual(str(flag), 'flag!=bar')59 self.assertTrue(flag.matches('foo'))60 self.assertFalse(flag.matches('bar'))61 def test_version_flag(self):62 flag = VersionFlag('flag')63 self.assertEqual(str(flag), '')64 self.assertTrue(flag.matches('1.0'))65 self.assertRaises(ErrorMessage, flag.add_definition, 'flag!=2')66 flag.add_definition('flag=1.0')67 self.assertEqual(str(flag), 'flag=1.0')68 self.assertTrue(flag.matches('1.0'))69 self.assertFalse(flag.matches('2.0'))70 flag.add_definition('flag=2.0')71 self.assertEqual(str(flag), 'flag=1.0 flag=2.0')72 self.assertTrue(flag.matches('1.0'))73 self.assertTrue(flag.matches('2.0'))74 self.assertFalse(flag.matches('3.0'))75 flag = VersionFlag('flag')...
flag_changer_test.py
Source:flag_changer_test.py
1#!/usr/bin/env python2# Copyright 2017 The Chromium Authors. All rights reserved.3# Use of this source code is governed by a BSD-style license that can be4# found in the LICENSE file.5import posixpath6import unittest7from devil.android import flag_changer8_CMDLINE_FILE = 'chrome-command-line'9class _FakeDevice(object):10 def __init__(self):11 self.build_type = 'user'12 self.has_root = True13 self.file_system = {}14 def HasRoot(self):15 return self.has_root16 def PathExists(self, filepath):17 return filepath in self.file_system18 def RemovePath(self, path, **_kwargs):19 self.file_system.pop(path)20 def WriteFile(self, path, contents, **_kwargs):21 self.file_system[path] = contents22 def ReadFile(self, path, **_kwargs):23 return self.file_system[path]24class FlagChangerTest(unittest.TestCase):25 def setUp(self):26 self.device = _FakeDevice()27 # pylint: disable=protected-access28 self.cmdline_path = posixpath.join(flag_changer._CMDLINE_DIR, _CMDLINE_FILE)29 self.cmdline_path_legacy = posixpath.join(30 flag_changer._CMDLINE_DIR_LEGACY, _CMDLINE_FILE)31 def testFlagChanger_removeLegacyCmdLine(self):32 self.device.WriteFile(self.cmdline_path_legacy, 'chrome --old --stuff')33 self.assertTrue(self.device.PathExists(self.cmdline_path_legacy))34 changer = flag_changer.FlagChanger(self.device, 'chrome-command-line')35 self.assertEquals(36 changer._cmdline_path, # pylint: disable=protected-access37 self.cmdline_path)38 self.assertFalse(self.device.PathExists(self.cmdline_path_legacy))39 def testFlagChanger_mustBeFileName(self):40 with self.assertRaises(ValueError):41 flag_changer.FlagChanger(self.device, '/data/local/chrome-command-line')42class ParseSerializeFlagsTest(unittest.TestCase):43 def _testQuoteFlag(self, flag, expected_quoted_flag):44 # Start with an unquoted flag, check that it's quoted as expected.45 # pylint: disable=protected-access46 quoted_flag = flag_changer._QuoteFlag(flag)47 self.assertEqual(quoted_flag, expected_quoted_flag)48 # Check that it survives a round-trip.49 parsed_flags = flag_changer._ParseFlags('_ %s' % quoted_flag)50 self.assertEqual(len(parsed_flags), 1)51 self.assertEqual(flag, parsed_flags[0])52 def testQuoteFlag_simple(self):53 self._testQuoteFlag('--simple-flag', '--simple-flag')54 def testQuoteFlag_withSimpleValue(self):55 self._testQuoteFlag('--key=value', '--key=value')56 def testQuoteFlag_withQuotedValue1(self):57 self._testQuoteFlag('--key=valueA valueB', '--key="valueA valueB"')58 def testQuoteFlag_withQuotedValue2(self):59 self._testQuoteFlag(60 '--key=this "should" work', r'--key="this \"should\" work"')61 def testQuoteFlag_withQuotedValue3(self):62 self._testQuoteFlag(63 "--key=this is 'fine' too", '''--key="this is 'fine' too"''')64 def testQuoteFlag_withQuotedValue4(self):65 self._testQuoteFlag(66 "--key='I really want to keep these quotes'",67 '''--key="'I really want to keep these quotes'"''')68 def testQuoteFlag_withQuotedValue5(self):69 self._testQuoteFlag(70 "--this is a strange=flag", '"--this is a strange=flag"')71 def testQuoteFlag_withEmptyValue(self):72 self._testQuoteFlag('--some-flag=', '--some-flag=')73 def _testParseCmdLine(self, command_line, expected_flags):74 # Start with a command line, check that flags are parsed as expected.75 # pylint: disable=protected-access76 flags = flag_changer._ParseFlags(command_line)77 self.assertItemsEqual(flags, expected_flags)78 # Check that flags survive a round-trip.79 # Note: Although new_command_line and command_line may not match, they80 # should describe the same set of flags.81 new_command_line = flag_changer._SerializeFlags(flags)82 new_flags = flag_changer._ParseFlags(new_command_line)83 self.assertItemsEqual(new_flags, expected_flags)84 def testParseCmdLine_simple(self):85 self._testParseCmdLine(86 'chrome --foo --bar="a b" --baz=true --fine="ok"',87 ['--foo', '--bar=a b', '--baz=true', '--fine=ok'])88 def testParseCmdLine_withFancyQuotes(self):89 self._testParseCmdLine(90 r'''_ --foo="this 'is' ok"91 --bar='this \'is\' too'92 --baz="this \'is\' tricky"93 ''',94 ["--foo=this 'is' ok",95 "--bar=this 'is' too",96 r"--baz=this \'is\' tricky"])97 def testParseCmdLine_withUnterminatedQuote(self):98 self._testParseCmdLine(99 '_ --foo --bar="I forgot something',100 ['--foo', '--bar=I forgot something'])101if __name__ == '__main__':...
Using AI Code Generation
1var fs = require('fs');2var zlib = require('zlib');3fs.createReadStream('input.txt')4 .pipe(zlib.createGzip())5 .pipe(fs.createWriteStream('input.txt.gz'));6console.log("File Compressed.");
Using AI Code Generation
1var express = require('express');2var app = express();3app.route('/Book')4.get(function(req,res){5 res.send('Get a random book');6})7.post(function(req,res){8 res.send('Add a book');9})10.put(function(req,res){11 res.send('Update the book');12});13app.listen(3000);14console.log("Server is running at port 3000");
Using AI Code Generation
1var express = require('express'),2 app = express(),3 mongoose = require('mongoose'),4 Task = require('./api/models/todoListModel'),5 bodyParser = require('body-parser');6mongoose.Promise = global.Promise;7app.use(bodyParser.urlencoded({ extended: true }));8app.use(bodyParser.json());9var routes = require('./api/routes/todoListRoutes');10routes(app);11app.listen(port);12console.log('todo list RESTful API server started on: ' + port);13'use strict';14var mongoose = require('mongoose');15var Schema = mongoose.Schema;
Using AI Code Generation
1var fs = require('fs');2fs.readFile('test.txt', 'utf8', function(err, data) {3 if (err) throw err;4 console.log(data);5});6fs.readFile('test2.txt', 'utf8', function(err, data) {7 if (err) throw err;8 console.log(data);9});10fs.readFile('test3.txt', 'utf8', function(err, data) {11 if (err) throw err;12 console.log(data);13});14var fs = require('fs');15fs.readFile('test.txt', 'utf8', function(err, data) {16 if (err) throw err;17 console.log(data);18 fs.readFile('test2.txt', 'utf8', function(err, data) {19 if (err) throw err;20 console.log(data);21 fs.readFile('test3.txt', 'utf8', function(err, data) {22 if (err) throw err;23 console.log(data);24 });25 });26});
Using AI Code Generation
1const express = require('express');2const app = express();3const port = 3000;4const fs = require('fs');5app.get('/', (req, res) => {6 res.send('Hello World!');7});8app.get('/test', (req, res) => {9 res.send('Hello World!').status(200).end();10});11app.get('/test2', (req, res) => {12 res.status(200).send('Hello World!').end();13});14app.get('/test3', (req, res) => {15 res.status(200).end('Hello World!');16});17app.get('/test4', (req, res) => {18 res.write('Hello World!').end();19});20app.get('/test5', (req, res) => {21 res.write('Hello World!').status(200).end();22});23app.get('/test6', (req, res) => {24 res.status(200).write('Hello World!').end();25});26app.get('/test7', (req, res) => {27 res.writeHead(200, {28 }).end('<h1>Hello World!</h1>');29});30app.get('/test8', (req, res) => {31 res.writeHead(200, {32 }).end('<h1>Hello World!</h1>');33});34app.get('/test9', (req, res) => {35 res.writeHead(200, {36 }).end('<h1>Hello World!</h1>');37});38app.get('/test10', (req, res) => {39 res.writeHead(200, {40 }).end('<h1>Hello World!</h1>');41});42app.get('/test11', (req, res) => {43 res.writeHead(200, {44 }).end('<h1>Hello World!</h1>');45});46app.get('/test12', (req, res) => {47 res.writeHead(200, {48 }).end('<h1>Hello World!</h1>');49});50app.get('/test13', (req, res) => {51 res.writeHead(200, {52 }).end('<h1>Hello World!</h1>');53});
Using AI Code Generation
1var flag = true;2var x = 0;3var y = 0;4var z = 0;5var a = 0;6var b = 0;7var c = 0;8var d = 0;9if (flag == true) {10 x = 1;11 y = 2;12 z = 3;13 a = 4;14 b = 5;15 c = 6;16 d = 7;17}18var flag = true;19var x = 0;20var y = 0;21var z = 0;22var a = 0;23var b = 0;24var c = 0;25var d = 0;26if (flag == true) {27 x = 1;28 y = 2;29 z = 3;30 a = 4;31 b = 5;32 c = 6;33 d = 7;34}35var flag = true;36var x = 0;37var y = 0;38var z = 0;39var a = 0;40var b = 0;41var c = 0;42var d = 0;43if (flag == true) {44 x = 1;45 y = 2;46 z = 3;47 a = 4;48 b = 5;49 c = 6;50 d = 7;51}52var flag = true;53var x = 0;54var y = 0;55var z = 0;56var a = 0;57var b = 0;58var c = 0;59var d = 0;60if (flag == true) {61 x = 1;62 y = 2;63 z = 3;64 a = 4;65 b = 5;66 c = 6;67 d = 7;68}69var flag = true;70var x = 0;
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!