1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
###############################################################################
# #
# Peekaboo Extended Email Attachment Behavior Observation Owl #
# #
# __init__.py #
###############################################################################
# #
# Copyright (C) 2016-2018 science + computing ag #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or (at #
# your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
# General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
###############################################################################
import re
VERSION = (1, 6)
AUTHORS = ['Felix Bauer', 'Sebastian Deiss']
__version__ = '.'.join(map(str, VERSION))
__author__ = ', '.join(AUTHORS)
__description__ = 'Peekaboo Extended Email Attachment Behavior Observation Owl'
__copyright__ = 'Copyright (C) 2016-2018 science + computing ag. All rights reserved.'
__license__ = 'GPLv3'
_owl = """
PEEKABOO {0}
Peekaboo Extended Email Attachment Behavior Observation Owl
_a_aa a_aa,
'*U4UUUULa_aa_aa_aajUUU4XU7'
aX''''''UUXU4XUU'''''!Ua
_U' -U4UU' _ 'U,
?i jLd1 ?#Wi 4L01 Ui
-U, 4#000P _U'
-*Xa_a_a_WUW##KUL_a_a_aX7'
_aXUXUUU4UUX4XX444UUUUUUXLa,
_UXXUXUXU47'!'!'!'!*X444U4UXX,
?XU4U4'' _ __ -'UUXUUi
?4U4' / | / /_ 'UUXi
*Xi | || '_ \ ?X7
*L | || (_) | j7
*a |_(_)___/ jY
-L, _/'
'l, _/'
j7_a_; aaa/4
_aaaaaa#0000#00000##0##00000000aaaaaa,
aaad0P!!!!!! '!!!!!!Laaa
_aa!!!! !! _,
(never mind the K)
""".format(__version__)
#
# Helpers
#
class MultiRegexMatcher(object):
"""
Validate multiple regular expressions for the same string.
@author: Sebastian Deiss
"""
def __init__(self, patterns, flags=0):
self.__patterns = [(re.compile(pattern, flags)) for pattern in patterns]
self.matched_pattern = -1 # No pattern matched (default value)
def match(self, str):
"""
Try to apply the patterns at the start of the string.
When the first pattern that matches, processing is stopped
and a match object is returned.
:param str: The string to apply the pattern to.
:return: a match object, or None if no match was found.
"""
iter_count = 0
for pattern in self.__patterns:
_match = re.match(pattern, str)
if _match:
self.matched_pattern = iter_count
return _match
iter_count += 1
return None
class Singleton(type):
"""
A Singleton in Python.
@see: https://stackoverflow.com/questions/6760685/creating-a-singleton-in-python
"""
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]
|