Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: Performance improvement for parsing CPEs #944

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions pontos/cpe/_cpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,22 @@ def _add_quoting(value: str) -> str:
Add quoting for parsing attributes from formatted string format to
Well-Formed CPE Name Data Model (WFN)
"""
result = ""
result: list[str] = []
index = 0
embedded = False

while index < len(value):
c = value[index]
if c.isalnum() or c in ["_"]:
# just add character
result += c
result.append(c)
index += 1
embedded = True
continue

if c == "\\":
# keep escaped character
result += value[index : index + 2]
result.append(value[index : index + 2])
index += 2
embedded = True
continue
Expand All @@ -163,7 +163,7 @@ def _add_quoting(value: str) -> str:
# An unquoted asterisk must appear at the beginning or
# end of the string.
if index == 0 or index == (len(value) - 1):
result += c
result.append(c)
index += 1
embedded = True
continue
Expand All @@ -186,7 +186,7 @@ def _add_quoting(value: str) -> str:
embedded and (value[index + 1] == "?")
)
):
result += c
result.append(c)
index += 1
embedded = False
continue
Expand All @@ -197,11 +197,11 @@ def _add_quoting(value: str) -> str:
)

# all other characters must be quoted
result += f"\\{c}"
result.append(f"\\{c}")
index += 1
embedded = True

return result
return "".join(result)


def unbind_value_from_formatted_string(value: Optional[str]) -> Optional[str]:
Expand Down