-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* parsing docx in --doc mode as text * Apply suggestions from code review * merge issue fix * udpdated tests for FilePathExtractor * style * documentation updated
- Loading branch information
Showing
21 changed files
with
488 additions
and
91 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import io | ||
import logging | ||
from abc import ABC | ||
from typing import List | ||
|
||
import docx | ||
|
||
from credsweeper.credentials import Candidate | ||
from credsweeper.deep_scanner.abstract_scanner import AbstractScanner | ||
from credsweeper.file_handler.data_content_provider import DataContentProvider | ||
from credsweeper.file_handler.string_content_provider import StringContentProvider | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class DocxScanner(AbstractScanner, ABC): | ||
"""Implements docx scanning""" | ||
|
||
def data_scan( | ||
self, # | ||
data_provider: DataContentProvider, # | ||
depth: int, # | ||
recursive_limit_size: int) -> List[Candidate]: | ||
"""Tries to scan DOCX text with splitting by lines""" | ||
candidates: List[Candidate] = [] | ||
|
||
try: | ||
docx_lines: List[str] = [] | ||
|
||
doc = docx.Document(io.BytesIO(data_provider.data)) | ||
for paragraph in doc.paragraphs: | ||
for line in paragraph.text.splitlines(): | ||
if line: | ||
docx_lines.append(line) | ||
|
||
string_data_provider = StringContentProvider(lines=docx_lines, | ||
file_path=data_provider.file_path, | ||
file_type=data_provider.file_type, | ||
info=f"{data_provider.info}|DOCX") | ||
candidates = self.scanner.scan(string_data_provider) | ||
except Exception as docx_exc: | ||
logger.debug(f"{data_provider.file_path}:{docx_exc}") | ||
return candidates |
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
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.