forked from Samsung/CredSweeper
-
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.
Performance optimization (Samsung#304)
* optimization * style fix * suggested text read style * suggestions * Update credsweeper/__main__.py Co-authored-by: ShinHyung Choi <[email protected]> --------- Co-authored-by: ShinHyung Choi <[email protected]>
- Loading branch information
Showing
28 changed files
with
223 additions
and
114 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[flake8] | ||
max-line-length = 120 | ||
extend-ignore = E203,E303,E131 | ||
extend-ignore = E203,E303,E131,E402 | ||
per-file-ignores = __init__.py:F401 |
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1,4 @@ | ||
from credsweeper.common.keyword_checklist import KeywordChecklist | ||
|
||
# use the variable to avoid singleton creation and make testing easier | ||
static_keyword_checklist = KeywordChecklist() |
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 |
---|---|---|
@@ -1,36 +1,32 @@ | ||
import os | ||
from typing import List, Set | ||
from functools import cached_property | ||
from typing import Set | ||
|
||
from credsweeper.utils import Util | ||
from credsweeper.app import APP_PATH | ||
|
||
|
||
class KeywordChecklist: | ||
"""KeywordsChecklist contains words 3 or more letters length""" | ||
__keyword_list: List[str] = [] | ||
__keyword_set: Set[str] | ||
__morpheme_set: Set[str] | ||
KEYWORD_PATH = APP_PATH / "common" / "keyword_checklist.txt" | ||
MORPHEME_PATH = APP_PATH / "common" / "morpheme_checklist.txt" | ||
|
||
def __init__(self) -> None: | ||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
file_path = os.path.join(dir_path, "keyword_checklist.txt") | ||
self.set_list(Util.read_file(file_path)) | ||
# used suggested text read style. split() is preferred because it strips 0x0A on end the file | ||
with open(self.KEYWORD_PATH, 'r') as f: | ||
self.__keyword_set = set(f.read().split()) | ||
|
||
def get_list(self) -> List[str]: | ||
"""Get list with keywords. | ||
@cached_property | ||
def keyword_set(self) -> Set[str]: | ||
"""Get set with keywords. | ||
Return: | ||
List of strings | ||
Set of strings | ||
""" | ||
return self.__keyword_list | ||
return self.__keyword_set | ||
|
||
def set_list(self, keyword_list: List[str]) -> None: | ||
"""Remove old keywords and setup new one. | ||
Args: | ||
keyword_list: list of keywords to be added | ||
""" | ||
keyword_set: Set[str] = set() | ||
for i in keyword_list: | ||
if 3 <= len(i): | ||
keyword_set.add(i) | ||
self.__keyword_list = list(keyword_set) | ||
@cached_property | ||
def keyword_len(self) -> int: | ||
"""Length of keyword_set""" | ||
return len(self.__keyword_set) |
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
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
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
Oops, something went wrong.