| Total Complexity | 6 |
| Total Lines | 33 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | 1 | import re |
|
| 2 | |||
| 3 | 1 | from lxml import etree |
|
| 4 | |||
| 5 | 1 | from .namespaces import NAMESPACES |
|
| 6 | |||
| 7 | |||
| 8 | 1 | class DescriptionParser(): |
|
| 9 | 1 | def __init__(self, ref_value): |
|
| 10 | 1 | self.ref_values = ref_value |
|
| 11 | |||
| 12 | 1 | def performe_sub_tag(self, text): |
|
| 13 | 1 | parts = re.split(r"<\S+sub\s", text) |
|
| 14 | 1 | processed_text = "" |
|
| 15 | 1 | for part in parts: |
|
| 16 | 1 | if part.startswith("idref"): |
|
| 17 | 1 | start_str = part.find("/>") + 2 |
|
| 18 | 1 | id_ref = re.search(r"idref=\"(.*?)\"", part).group(1) |
|
| 19 | 1 | part = f"{self.ref_values[id_ref]}{part[start_str:]}" |
|
| 20 | 1 | processed_text += part |
|
| 21 | 1 | return processed_text |
|
| 22 | |||
| 23 | 1 | def get_full_description(self, rule): |
|
| 24 | 1 | description = rule.find(".//xccdf:description", NAMESPACES) |
|
| 25 | 1 | if description is None: |
|
| 26 | 1 | return None |
|
| 27 | 1 | str_description = etree.tostring(description).decode() |
|
| 28 | 1 | start_tag_description = str_description.find(">") + 1 |
|
| 29 | 1 | end_tag_description = str_description.rfind("</") |
|
| 30 | 1 | description_text = str_description[start_tag_description:end_tag_description] |
|
| 31 | 1 | description_text = description_text.replace("html:", "") |
|
| 32 | return self.performe_sub_tag(description_text) |
||
| 33 |