From 9ce67a1ae0572a4c265c9616e47e4d92be323dce Mon Sep 17 00:00:00 2001 From: Ponicode-bot Date: Thu, 5 Nov 2020 11:41:37 +0000 Subject: [PATCH] [ponicode-pull-request] Ponicode wrote new docstrings! --- pastepwn/actions/basicaction.py | 6 ++ pastepwn/actions/databaseaction.py | 7 ++ pastepwn/actions/emailaction.py | 12 ++++ pastepwn/actions/genericaction.py | 16 +++++ pastepwn/actions/ircaction.py | 17 +++++ pastepwn/actions/logaction.py | 15 ++++ pastepwn/actions/mispaction.py | 7 ++ pastepwn/actions/savejsonaction.py | 7 ++ pastepwn/actions/twitteraction.py | 11 +++ pastepwn/analyzers/awsaccesskeyanalyzer.py | 7 ++ pastepwn/analyzers/awssecretkeyanalyzer.py | 7 ++ pastepwn/analyzers/awssessiontokenanalyzer.py | 7 ++ .../analyzers/azuresubscriptionkeyanalyzer.py | 7 ++ pastepwn/analyzers/base64analyzer.py | 8 +++ pastepwn/analyzers/base64asciianalyzer.py | 9 +++ pastepwn/analyzers/basicanalyzer.py | 29 ++++++++ pastepwn/analyzers/battlenetkeyanalyzer.py | 7 ++ pastepwn/analyzers/bcrypthashanalyzer.py | 7 ++ pastepwn/analyzers/dbconnstringanalyzer.py | 7 ++ .../analyzers/emailpasswordpairanalyzer.py | 8 +++ pastepwn/analyzers/genericanalyzer.py | 9 +++ pastepwn/analyzers/googleapikeyanalyzer.py | 7 ++ pastepwn/analyzers/googleoauthkeyanalyzer.py | 7 ++ pastepwn/analyzers/ibananalyzer.py | 8 +++ pastepwn/analyzers/ipv4addressanalyzer.py | 7 ++ .../tests/andanalyzer_test.py | 30 ++++++++ .../tests/logicalbaseanalyzer_test.py | 30 ++++++++ .../logicalanalyzers/tests/oranalyzer_test.py | 30 ++++++++ pastepwn/analyzers/mailanalyzer.py | 7 ++ pastepwn/analyzers/mailchimpapikeyanalyzer.py | 7 ++ pastepwn/analyzers/md5hashanalyzer.py | 7 ++ pastepwn/analyzers/megalinkanalyzer.py | 7 ++ pastepwn/analyzers/pastebinurlanalyzer.py | 8 +++ pastepwn/analyzers/pastetitleanalyzer.py | 10 +++ pastepwn/analyzers/privatekeyanalyzer.py | 7 ++ pastepwn/analyzers/regexanalyzer.py | 9 +++ pastepwn/analyzers/shahashanalyzer.py | 7 ++ pastepwn/analyzers/stripeapikeyanalyzer.py | 7 ++ .../analyzers/tests/adobekeyanalyzer_test.py | 6 ++ .../tests/alwaystrueanalyzer_test.py | 18 +++++ .../tests/awsaccesskeyanalyzer_test.py | 18 +++++ .../tests/awssecretkeyanalyzer_test.py | 6 ++ .../tests/awssessiontokenanalyzer_test.py | 6 ++ .../azuresubscriptionkeyanalyzer_test.py | 6 ++ .../analyzers/tests/base64analyzer_test.py | 6 ++ .../tests/base64asciianalyzer_test.py | 6 ++ .../analyzers/tests/basicanalyzer_test.py | 6 ++ .../tests/battlenetkeyanalyzer_test.py | 6 ++ .../tests/bcrypthashanalyzer_test.py | 30 ++++++++ .../tests/creditcardanalyzer_test.py | 6 ++ .../tests/databasedumpanalyzer_test.py | 12 ++++ .../tests/dbconnstringanalyzer_test.py | 12 ++++ .../tests/emailpasswordpairanalyzer_test.py | 6 ++ .../analyzers/tests/epickeyanalyzer_test.py | 6 ++ .../tests/facebookaccesstokenanalyzer_test.py | 18 +++++ .../analyzers/tests/genericanalyzer_test.py | 6 ++ .../tests/googleapikeyanalyzer_test.py | 6 ++ .../tests/googleoauthkeyanalyzer_test.py | 6 ++ pastepwn/analyzers/tests/hashanalyzer_test.py | 36 ++++++++++ pastepwn/analyzers/tests/ibananalyzer_test.py | 42 +++++++++++ .../tests/ipv4addressanalyzer_test.py | 18 +++++ pastepwn/analyzers/tests/mailanalyzer_test.py | 6 ++ .../tests/mailchimpapikeyanalyzer_test.py | 6 ++ .../analyzers/tests/md5hashanalyzer_test.py | 6 ++ .../analyzers/tests/megalinkanalyzer_test.py | 6 ++ .../analyzers/tests/mergedanalyzer_test.py | 7 ++ .../tests/microsoftkeyanalyzer_test.py | 6 ++ .../analyzers/tests/originkeyanalyzer_test.py | 6 ++ .../tests/pastebinurlanalyzer_test.py | 18 +++++ .../tests/pastetitleanalyzer_test.py | 24 +++++++ .../tests/phonenumberanalyzer_test.py | 6 ++ .../tests/privatekeyanalyzer_test.py | 6 ++ .../analyzers/tests/regexanalyzer_test.py | 32 +++++++++ .../analyzers/tests/shahashanalyzer_test.py | 6 ++ .../tests/slacktokenanalyzer_test.py | 6 ++ .../tests/slackwebhookanalyzer_test.py | 6 ++ .../analyzers/tests/steamkeyanalyzer_test.py | 6 ++ .../tests/stripeapikeyanalyzer_test.py | 6 ++ .../analyzers/tests/uplaykeyanalyzer_test.py | 6 ++ pastepwn/analyzers/tests/wordanalyzer_test.py | 54 +++++++++++++++ pastepwn/analyzers/uplaykeyanalyzer.py | 7 ++ pastepwn/analyzers/urlanalyzer.py | 9 +++ pastepwn/analyzers/wordanalyzer.py | 17 +++++ pastepwn/core/actionhandler.py | 15 ++++ pastepwn/core/paste.py | 21 ++++++ pastepwn/core/pastedispatcher.py | 28 ++++++++ pastepwn/core/scrapinghandler.py | 8 +++ pastepwn/core/tests/paste_test.py | 36 ++++++++++ pastepwn/database/abstractdb.py | 6 ++ pastepwn/database/mongodb.py | 53 ++++++++++++++ pastepwn/database/mysqldb.py | 69 +++++++++++++++++++ pastepwn/database/sqlitedb.py | 63 +++++++++++++++++ pastepwn/database/tests/mongodb_test.py | 18 +++++ pastepwn/database/tests/sqlite_test.py | 18 +++++ pastepwn/errors/errors.py | 13 ++++ pastepwn/errors/tests/errors_test.py | 6 ++ pastepwn/scraping/basicscraper.py | 7 ++ .../exceptions/ipnotregisterederror.py | 7 ++ pastepwn/scraping/pastebin/pastebinscraper.py | 9 +++ .../pastebin/tests/pastebinscraper_test.py | 37 ++++++++++ pastepwn/util/dictwrapper.py | 7 ++ pastepwn/util/request.py | 58 ++++++++++++++++ pastepwn/util/tests/dictwrapper_test.py | 18 +++++ pastepwn/util/tests/listify_test.py | 18 +++++ 104 files changed, 1460 insertions(+) diff --git a/pastepwn/actions/basicaction.py b/pastepwn/actions/basicaction.py index f388fe82..fa659ac2 100644 --- a/pastepwn/actions/basicaction.py +++ b/pastepwn/actions/basicaction.py @@ -6,6 +6,12 @@ class BasicAction(object): name = "BasicAction" def __init__(self): + """ + Initialize the object + + Args: + self: (todo): write your description + """ pass def perform(self, paste, analyzer_name=None, matches=None): diff --git a/pastepwn/actions/databaseaction.py b/pastepwn/actions/databaseaction.py index d9a48463..f23794cd 100644 --- a/pastepwn/actions/databaseaction.py +++ b/pastepwn/actions/databaseaction.py @@ -7,6 +7,13 @@ class DatabaseAction(BasicAction): name = "DatabaseAction" def __init__(self, database): + """ + Initialize database + + Args: + self: (todo): write your description + database: (str): write your description + """ super().__init__() self.database = database diff --git a/pastepwn/actions/emailaction.py b/pastepwn/actions/emailaction.py index 8936e74b..f7c9e6e0 100644 --- a/pastepwn/actions/emailaction.py +++ b/pastepwn/actions/emailaction.py @@ -15,6 +15,18 @@ class EmailAction(BasicAction): name = "EmailAction" def __init__(self, username, password, receiver, hostname, port=465, template=None): + """ + Initialize a new receiver. + + Args: + self: (todo): write your description + username: (str): write your description + password: (str): write your description + receiver: (callable): write your description + hostname: (str): write your description + port: (int): write your description + template: (str): write your description + """ super().__init__() mail_regex = r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)" if username is None or not re.match(mail_regex, username): diff --git a/pastepwn/actions/genericaction.py b/pastepwn/actions/genericaction.py index 5421d84f..473080eb 100644 --- a/pastepwn/actions/genericaction.py +++ b/pastepwn/actions/genericaction.py @@ -7,8 +7,24 @@ class GenericAction(BasicAction): name = "GenericAction" def __init__(self, func): + """ + Initialize a function. + + Args: + self: (todo): write your description + func: (callable): write your description + """ super().__init__() self.func = func def perform(self, paste, analyzer_name=None, matches=None): + """ + Perform the given paste. + + Args: + self: (todo): write your description + paste: (todo): write your description + analyzer_name: (str): write your description + matches: (todo): write your description + """ self.func(paste) diff --git a/pastepwn/actions/ircaction.py b/pastepwn/actions/ircaction.py index be8ac0f1..1a59131a 100644 --- a/pastepwn/actions/ircaction.py +++ b/pastepwn/actions/ircaction.py @@ -16,6 +16,17 @@ class IrcAction(BasicAction): name = "IrcAction" def __init__(self, server=None, channel=None, port=6667, nick="pastepwn", template=None): + """ + Initialize the consumer. + + Args: + self: (todo): write your description + server: (todo): write your description + channel: (todo): write your description + port: (int): write your description + nick: (str): write your description + template: (str): write your description + """ super().__init__() self.logger = logging.getLogger(__name__) self._msg_queue = Queue() @@ -204,6 +215,12 @@ def _send_message(self, msg): self._msg_queue.put(msg) def __del__(self): + """ + Stops the background thread. + + Args: + self: (todo): write your description + """ self._stop_event.set() join_threads([self._thread]) diff --git a/pastepwn/actions/logaction.py b/pastepwn/actions/logaction.py index bf821b8d..01529a31 100644 --- a/pastepwn/actions/logaction.py +++ b/pastepwn/actions/logaction.py @@ -9,8 +9,23 @@ class LogAction(BasicAction): name = "LogAction" def __init__(self): + """ + Initialize the logger. + + Args: + self: (todo): write your description + """ super().__init__() self.logger = logging.getLogger(__name__) def perform(self, paste, analyzer_name=None, matches=None): + """ + Perform the given paste. + + Args: + self: (todo): write your description + paste: (todo): write your description + analyzer_name: (str): write your description + matches: (todo): write your description + """ self.logger.debug("New Paste matched: {0}".format(paste)) diff --git a/pastepwn/actions/mispaction.py b/pastepwn/actions/mispaction.py index b0b0134b..a4c37a8b 100644 --- a/pastepwn/actions/mispaction.py +++ b/pastepwn/actions/mispaction.py @@ -45,6 +45,13 @@ def __init__(self, url, access_key, transformer=None, attributes=None): @staticmethod def default_transformer(paste, analyzer_name=None): + """ + Create a default transformer + + Args: + paste: (str): write your description + analyzer_name: (str): write your description + """ timestamp = time.gmtime(int(paste.date)) attrs = [] # Build event diff --git a/pastepwn/actions/savejsonaction.py b/pastepwn/actions/savejsonaction.py index b574d57a..a023d59c 100644 --- a/pastepwn/actions/savejsonaction.py +++ b/pastepwn/actions/savejsonaction.py @@ -10,6 +10,13 @@ class SaveJSONAction(SaveFileAction): name = "SaveJSONAction" def __init__(self, path): + """ + Initialize the specified path. + + Args: + self: (todo): write your description + path: (str): write your description + """ super().__init__(path) def perform(self, paste, analyzer_name=None, matches=None): diff --git a/pastepwn/actions/twitteraction.py b/pastepwn/actions/twitteraction.py index c51dee62..4563b32c 100644 --- a/pastepwn/actions/twitteraction.py +++ b/pastepwn/actions/twitteraction.py @@ -20,6 +20,17 @@ def __init__( access_token_secret=None, template=None, ): + """ + Initialize a new token. + + Args: + self: (todo): write your description + consumer_key: (str): write your description + consumer_secret: (str): write your description + access_token_key: (str): write your description + access_token_secret: (str): write your description + template: (str): write your description + """ super().__init__() self.logger = logging.getLogger(__name__) diff --git a/pastepwn/analyzers/awsaccesskeyanalyzer.py b/pastepwn/analyzers/awsaccesskeyanalyzer.py index 8878a6c2..45d60dba 100644 --- a/pastepwn/analyzers/awsaccesskeyanalyzer.py +++ b/pastepwn/analyzers/awsaccesskeyanalyzer.py @@ -11,6 +11,13 @@ class AWSAccessKeyAnalyzer(RegexAnalyzer): name = "AWSAccessKeyAnalyzer" def __init__(self, actions): + """ + Initialize actions. + + Args: + self: (todo): write your description + actions: (todo): write your description + """ # https://people.eecs.berkeley.edu/~rohanpadhye/files/key_leaks-msr15.pdf regex = r"\b(?:A3T[A-Z0-9]|AKIA|AGPA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}\b" super().__init__(actions, regex) diff --git a/pastepwn/analyzers/awssecretkeyanalyzer.py b/pastepwn/analyzers/awssecretkeyanalyzer.py index e94f55e3..f620a7e2 100644 --- a/pastepwn/analyzers/awssecretkeyanalyzer.py +++ b/pastepwn/analyzers/awssecretkeyanalyzer.py @@ -11,5 +11,12 @@ class AWSSecretKeyAnalyzer(RegexAnalyzer): name = "AWSSecretKeyAnalyzer" def __init__(self, actions): + """ + Initialize actions. + + Args: + self: (todo): write your description + actions: (todo): write your description + """ regex = r"\b[A-Za-z0-9/+=]{40}\b" super().__init__(actions, regex) diff --git a/pastepwn/analyzers/awssessiontokenanalyzer.py b/pastepwn/analyzers/awssessiontokenanalyzer.py index 4997e8f6..545f9192 100644 --- a/pastepwn/analyzers/awssessiontokenanalyzer.py +++ b/pastepwn/analyzers/awssessiontokenanalyzer.py @@ -9,5 +9,12 @@ class AWSSessionTokenAnalyzer(RegexAnalyzer): name = "AWSSessionTokenAnalyzer" def __init__(self, actions): + """ + Initialize actions. + + Args: + self: (todo): write your description + actions: (todo): write your description + """ regex = r"(?:(?:\\\"|'|`)?(?:i?aws)?_?(?:i?session)?_?(?:i?token)?(?:\\\"|'|`)?\\\\s{0,50}(?::|=>|=)\\\\s{0,50}(?:\\\"|'|`)?[A-Za-z0-9/+=]{16,}(?:\\\"|'|`)?)" super().__init__(actions, regex) diff --git a/pastepwn/analyzers/azuresubscriptionkeyanalyzer.py b/pastepwn/analyzers/azuresubscriptionkeyanalyzer.py index bd8e64e1..42c94a0f 100644 --- a/pastepwn/analyzers/azuresubscriptionkeyanalyzer.py +++ b/pastepwn/analyzers/azuresubscriptionkeyanalyzer.py @@ -11,6 +11,13 @@ class AzureSubscriptionKeyAnalyzer(RegexAnalyzer): name = "AzureSubscriptionKeyAnalyzer" def __init__(self, actions): + """ + Initialize actions. + + Args: + self: (todo): write your description + actions: (todo): write your description + """ # https://docs.microsoft.com/en-us/azure/api-management/api-management-subscriptions regex = r"\b[a-f0-9]{32}\b" super().__init__(actions, regex) diff --git a/pastepwn/analyzers/base64analyzer.py b/pastepwn/analyzers/base64analyzer.py index c12b8c03..c135290b 100644 --- a/pastepwn/analyzers/base64analyzer.py +++ b/pastepwn/analyzers/base64analyzer.py @@ -7,6 +7,14 @@ class Base64Analyzer(RegexAnalyzer): name = "Base64Analyzer" def __init__(self, actions, min_len=1): + """ + Initialize actions. + + Args: + self: (todo): write your description + actions: (todo): write your description + min_len: (int): write your description + """ regex = r"(? None: + """ + Sets the currently running. + + Args: + self: (todo): write your description + """ self.pastebinscraper = PastebinScraper() def test_empty(self): + """ + Check if the test is empty. + + Args: + self: (todo): write your description + """ with self.assertRaises(PasteEmptyException): self.pastebinscraper._check_error("") def test_not_ready(self): + """ + Check if the test is ready. + + Args: + self: (todo): write your description + """ with self.assertRaises(PasteNotReadyException): self.pastebinscraper._check_error("File is not ready for scraping yet. Try again in 1 minute.") def test_deleted(self): + """ + Test if the test was deleted. + + Args: + self: (todo): write your description + """ with self.assertRaises(PasteDeletedException): self.pastebinscraper._check_error("Error, we cannot find this paste.") def _check_ip_not_registered(self, ip_list): + """ + Check ip address is not in ip + + Args: + self: (todo): write your description + ip_list: (list): write your description + """ shell = "YOUR IP: {} DOES NOT HAVE ACCESS. VISIT: https://pastebin.com/doc_scraping_api TO GET ACCESS!" for ip in ip_list: with self.assertRaises(IPNotRegisteredError): @@ -36,6 +67,12 @@ def test_ipv4_not_registered(self): self._check_ip_not_registered(ipv4_test) def test_ipv6_not_registered(self): + """ + All ipv6 addresses + + Args: + self: (todo): write your description + """ ipv6_test = ["fe80::21d8:f50:c295:c4be", "2001:cdba:0000:0000:0000:0000:3257:9652", "2001:cdba:0:0:0:0:3257:9652", "2001:cdba::3257:9652", "2001:cdba::1222", "21DA:D3:0:2F3B:2AA:FF:FE28:9C5A", "2001:cdba::1:2:3:3257:9652", "FE80::8329", "FE80::FFFF:8329", "FE80::B3FF:FFFF:8329", "FE80::0202:B3FF:FFFF:8329", "FE80:0000:0000:0000:0202:B3FF:FFFF:8329"] diff --git a/pastepwn/util/dictwrapper.py b/pastepwn/util/dictwrapper.py index 68ccce41..f4bbf38c 100644 --- a/pastepwn/util/dictwrapper.py +++ b/pastepwn/util/dictwrapper.py @@ -9,4 +9,11 @@ class DictWrapper(dict): """ def __missing__(self, key): + """ + Returns true if key + + Args: + self: (todo): write your description + key: (str): write your description + """ return '${' + key + '}' diff --git a/pastepwn/util/request.py b/pastepwn/util/request.py index 773f94d7..20df0b41 100644 --- a/pastepwn/util/request.py +++ b/pastepwn/util/request.py @@ -12,6 +12,12 @@ class Request(object): _lock = Lock() def __new__(cls, *args, **kwargs): + """ + Return a new instance of this : class : newinstance. + + Args: + cls: (todo): write your description + """ # override method to implement singleton # source: http://alacret.blogspot.com/2015/04/python-thread-safe-singleton-pattern.html if Request._instance is None: @@ -21,6 +27,14 @@ def __new__(cls, *args, **kwargs): return Request._instance def __init__(self, proxies=None, headers=None): + """ + Initialize the http requests. + + Args: + self: (todo): write your description + proxies: (dict): write your description + headers: (list): write your description + """ if not self._initialized: self.logger = logging.getLogger(__name__) self.session = Session() @@ -31,6 +45,14 @@ def __init__(self, proxies=None, headers=None): self._initialized = True def _request_wrapper(self, data, timeout, *args, **kwargs): + """ + Make a http request. + + Args: + self: (todo): write your description + data: (str): write your description + timeout: (float): write your description + """ headers = { "User-Agent": "pastepwn (https://github.com/d-Rickyy-b/pastepwn)" } @@ -48,13 +70,49 @@ def _request_wrapper(self, data, timeout, *args, **kwargs): return response_data def get(self, url, data=None, timeout=5): + """ + Make a get request. + + Args: + self: (todo): write your description + url: (todo): write your description + data: (todo): write your description + timeout: (int): write your description + """ return self._request_wrapper(method="GET", url=url, data=data, timeout=timeout) def post(self, url, data=None, timeout=5): + """ + Make a post request. + + Args: + self: (todo): write your description + url: (todo): write your description + data: (array): write your description + timeout: (float): write your description + """ return self._request_wrapper(method="POST", url=url, data=data, timeout=timeout) def put(self, url, data=None, timeout=5): + """ + Make a put request. + + Args: + self: (todo): write your description + url: (todo): write your description + data: (array): write your description + timeout: (float): write your description + """ return self._request_wrapper(method="PUT", url=url, data=data, timeout=timeout) def delete(self, url, data=None, timeout=5): + """ + Make a delete request. + + Args: + self: (todo): write your description + url: (str): write your description + data: (array): write your description + timeout: (float): write your description + """ return self._request_wrapper(method="DELETE", url=url, data=data, timeout=timeout) diff --git a/pastepwn/util/tests/dictwrapper_test.py b/pastepwn/util/tests/dictwrapper_test.py index 9b50e239..2edeb894 100644 --- a/pastepwn/util/tests/dictwrapper_test.py +++ b/pastepwn/util/tests/dictwrapper_test.py @@ -6,13 +6,31 @@ class TestDictwrapper(unittest.TestCase): def setUp(self): + """ + Set the test :: + + Args: + self: (todo): write your description + """ self.test_dict = {"key1": "value1", "key2": "value2"} def test_existing_key(self): + """ + The test key exists in the test. + + Args: + self: (todo): write your description + """ test_wrapped = DictWrapper(self.test_dict) self.assertEqual(test_wrapped["key1"], "value1") def test_non_existing_key(self): + """ + This function that the test key of the given test. + + Args: + self: (todo): write your description + """ test_wrapped = DictWrapper(self.test_dict) # Make sure that retreiving a valid key works self.assertEqual(test_wrapped["key1"], "value1") diff --git a/pastepwn/util/tests/listify_test.py b/pastepwn/util/tests/listify_test.py index 5e2284bf..622d624d 100644 --- a/pastepwn/util/tests/listify_test.py +++ b/pastepwn/util/tests/listify_test.py @@ -8,9 +8,21 @@ class ListifyTest(unittest.TestCase): def test_None(self): + """ + Assigns the test results. + + Args: + self: (todo): write your description + """ self.assertEqual([], listify(None), "Listify did not return empty list!") def test_list(self): + """ + Get the list of an object. + + Args: + self: (todo): write your description + """ obj = Mock() obj2 = Mock() obj3 = Mock() @@ -19,6 +31,12 @@ def test_list(self): self.assertEqual(obj_list, listify(obj_list), "Listify did not return the given list!") def test_single(self): + """ + Sets the test for the test. + + Args: + self: (todo): write your description + """ obj = Mock() self.assertEqual([obj], listify(obj), "Listify did not return single object as list!")