| Total Complexity | 12 |
| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | """ |
||
| 2 | Common functions for building CPEs |
||
| 3 | """ |
||
| 4 | |||
| 5 | 1 | from __future__ import absolute_import |
|
| 6 | 1 | from __future__ import print_function |
|
| 7 | |||
| 8 | 1 | def extract_subelement(objects, sub_elem_type): |
|
|
|
|||
| 9 | 1 | for obj in objects: |
|
| 10 | 1 | for subelement in obj.getiterator(): |
|
| 11 | 1 | if subelement.get(sub_elem_type): |
|
| 12 | 1 | sub_element = subelement.get(sub_elem_type) |
|
| 13 | 1 | return sub_element |
|
| 14 | |||
| 15 | |||
| 16 | 1 | def extract_env_obj(objects, local_var): |
|
| 17 | 1 | for obj in objects: |
|
| 18 | 1 | env_id = extract_subelement(local_var, 'object_ref') |
|
| 19 | 1 | if env_id == obj.get('id'): |
|
| 20 | 1 | return obj |
|
| 21 | |||
| 22 | |||
| 23 | 1 | def extract_referred_nodes(tree_with_refs, tree_with_ids, attrname): |
|
| 24 | 1 | reflist = [] |
|
| 25 | 1 | elementlist = [] |
|
| 26 | |||
| 27 | 1 | for element in tree_with_refs.getiterator(): |
|
| 28 | 1 | value = element.get(attrname) |
|
| 29 | 1 | if value is not None: |
|
| 30 | 1 | reflist.append(value) |
|
| 31 | |||
| 32 | 1 | for element in tree_with_ids.getiterator(): |
|
| 33 | 1 | if element.get("id") in reflist: |
|
| 34 | 1 | elementlist.append(element) |
|
| 35 | |||
| 36 | return elementlist |
||
| 37 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.