forked from patched-codes/patchwork
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add paths to inputs of ScanSemgrep step (patched-codes#952)
* add the input * fix * bump version and fix split * add path key
- Loading branch information
Showing
4 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from __future__ import annotations | ||
from typing_extensions import Union, AnyStr | ||
from collections.abc import Iterable, Mapping | ||
|
||
__ITEM_TYPE = Union[AnyStr, Mapping] | ||
|
||
def __parse_to_list_handle_str(input_value: AnyStr, possible_delimiters: Iterable[AnyStr | None]) -> list[str]: | ||
for possible_delimiter in possible_delimiters: | ||
if possible_delimiter is None: | ||
return input_value.split() | ||
|
||
if possible_delimiter in input_value: | ||
return input_value.split(possible_delimiter) | ||
|
||
return [] | ||
|
||
def __parse_to_list_handle_dict(input_value: Mapping, possible_keys: Iterable[AnyStr | None]) -> list[str]: | ||
for possible_key in possible_keys: | ||
if input_value.get(possible_key) is not None: | ||
return input_value.get(possible_key) | ||
|
||
return [] | ||
|
||
def __parse_to_list_handle_iterable(input_value: Iterable[__ITEM_TYPE], possible_keys: Iterable[AnyStr | None]) -> list[str]: | ||
rv = [] | ||
for item in input_value: | ||
if isinstance(item, dict): | ||
for possible_key in possible_keys: | ||
if item.get(possible_key) is not None: | ||
rv.append(item.get(possible_key)) | ||
else: | ||
rv.append(item) | ||
|
||
return rv | ||
|
||
def parse_to_list( | ||
input_value: __ITEM_TYPE | Iterable[__ITEM_TYPE], | ||
possible_delimiters: Iterable[AnyStr | None] | None = None , | ||
possible_keys: Iterable[AnyStr | None] | None = None | ||
) -> list[str]: | ||
if len(input_value) < 1: | ||
return [] | ||
|
||
if possible_delimiters is None: | ||
possible_delimiters = [] | ||
if possible_keys is None: | ||
possible_keys = [] | ||
|
||
value_to_parse = [] | ||
if isinstance(input_value, dict): | ||
value_to_parse = __parse_to_list_handle_dict(input_value, possible_keys) | ||
elif isinstance(input_value, str): | ||
value_to_parse = __parse_to_list_handle_str(input_value, possible_delimiters) | ||
elif isinstance(input_value, Iterable): | ||
value_to_parse = __parse_to_list_handle_iterable(input_value, possible_keys) | ||
|
||
rv = [] | ||
for value in value_to_parse: | ||
stripped_value = value.strip() | ||
if stripped_value == "": | ||
continue | ||
rv.append(stripped_value) | ||
return rv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters