Skip to content

Commit

Permalink
Merge 1094415 into adcb526
Browse files Browse the repository at this point in the history
  • Loading branch information
camfairchild committed Oct 4, 2020
2 parents adcb526 + 1094415 commit 62dd655
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Implemented ExactWordAnalyzer to match words exactly rather than partially ([08ebdbc](https://github.com/d-Rickyy-b/pastepwn/commits/08ebdbc3fb5c8431486f8367e039e8580c67770a))

- Implemented BasicAnalyzer.unique(), which can be used to filter out duplicate matches from BasicAnalyzer.match() ([18dee8a](https://github.com/d-Rickyy-b/pastepwn/commits/18dee8ae3026b187a46afe044360305197341f7e))

## [1.3.1] - 2020-06-20
### Fixed
- The PastebinScraper could not recognize error messages with IPv6 addresses.
Expand Down
13 changes: 12 additions & 1 deletion pastepwn/analyzers/basicanalyzer.py
Expand Up @@ -34,13 +34,24 @@ def add_action(self, action):
self._check_action(action)
self.actions.append(action)

def match(self, paste):
def match(self, paste, unique_matches=False):
"""
Checks if a certain paste is matched by the conditions set for this analyzer
:param paste: A :class:`pastepwn.core.paste` object which should be matched
:param unique_matches: A boolean that specifies if matches should be unique.
defaults to False
:return: :obj:`bool` if the paste has been matched
"""
raise NotImplementedError("Your analyzer must implement the match method!")

@staticmethod
def unique(matches):
"""
Takes a list of matches and returns a list with no duplicates.
:param matches: A list of matches
:return: A filtered list of matches retaining order
"""
return sorted(set(matches), key=matches.index)

def _check_action(self, action):
"""Check if a passed action is a subclass of BasicAction"""
Expand Down
21 changes: 21 additions & 0 deletions pastepwn/analyzers/tests/basicanalyzer_test.py
Expand Up @@ -99,6 +99,27 @@ def test_error_logging_init_class(self):

self.assertEqual(log.output, ["ERROR:pastepwn.analyzers.basicanalyzer:You passed a class as action for 'BasicAnalyzer' but an instance of an action was expected!"])

def test_unique(self):
"""Check if running unique() on a list of matches returns a list with
no duplicates"""
# Some lists with and without duplicates
test_lists = [
[],
["a", "a"],
["a", "b"],
["a", "b", "a"]
]
self.assertEqual(BasicAnalyzer.unique(test_lists[0]), [],
msg="BasicAnalyzer.unique() left a duplicate!")
self.assertEqual(BasicAnalyzer.unique(test_lists[1]), ["a"],
msg="BasicAnalyzer.unique() left a duplicate!")
# Should preserve order
self.assertEqual(BasicAnalyzer.unique(test_lists[2]), ["a", "b"],
msg="BasicAnalyzer.unique() left a duplicate!")
self.assertEqual(BasicAnalyzer.unique(test_lists[3]), ["a", "b"],
msg="BasicAnalyzer.unique() left a duplicate!")



if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion requirements_minimum.txt
@@ -1 +1 @@
requests==2.22.0
requests==2.23.0

0 comments on commit 62dd655

Please sign in to comment.