text
stringlengths
0
828
msg = ""Wrote {} indicators"".format(len(indicators))
return {'success': True, 'message': msg, 'writeCount': len(indicators)}"
4654,"def parse_email_url(url):
""""""Parses an email URL.""""""
conf = {}
url = urlparse.urlparse(url)
# Remove query strings
path = url.path[1:]
path = path.split('?', 2)[0]
# Update with environment configuration
conf.update({
'EMAIL_FILE_PATH': path,
'EMAIL_HOST_USER': url.username,
'EMAIL_HOST_PASSWORD': url.password,
'EMAIL_HOST': url.hostname,
'EMAIL_PORT': url.port,
})
if url.scheme in EMAIL_SCHEMES:
conf['EMAIL_BACKEND'] = EMAIL_SCHEMES[url.scheme]
if url.scheme == 'smtps':
conf['EMAIL_USE_TLS'] = True
else:
conf['EMAIL_USE_TLS'] = False
return conf"
4655,"def config(name='EMAIL_URL', default='console://'):
""""""Returns a dictionary with EMAIL_* settings from EMAIL_URL.""""""
conf = {}
s = env(name, default)
if s:
conf = parse_email_url(s)
return conf"
4656,"def replace(html, replacements=None):
""""""Performs replacements on given HTML string.""""""
if not replacements:
return html # no replacements
html = HTMLFragment(html)
for r in replacements:
r.replace(html)
return unicode(html)"
4657,"def _is_replacement_allowed(self, s):
""""""Tests whether replacement is allowed on given piece of HTML text.""""""
if any(tag in s.parent_tags for tag in self.skipped_tags):
return False
if any(tag not in self.textflow_tags for tag in s.involved_tags):
return False
return True"
4658,"def replace(self, html):
""""""Perform replacements on given HTML fragment.""""""
self.html = html
text = html.text()
positions = []
def perform_replacement(match):
offset = sum(positions)
start, stop = match.start() + offset, match.end() + offset
s = self.html[start:stop]
if self._is_replacement_allowed(s):
repl = match.expand(self.replacement)
self.html[start:stop] = repl
else:
repl = match.group() # no replacement takes place
positions.append(match.end())
return repl
while True:
if positions:
text = text[positions[-1]:]
text, n = self.pattern.subn(perform_replacement, text, count=1)
if not n: # all is already replaced
break"
4659,"def read_relative_file(filename, relative_to=None):
""""""Returns contents of the given file, which path is supposed relative
to this package.""""""
if relative_to is None:
relative_to = os.path.dirname(__file__)
with open(os.path.join(os.path.dirname(relative_to), filename)) as f:
return f.read()"
4660,"def get_events(self):
""""""Get events from the cloud node.""""""
to_send = {'limit': 50}
response = self._send_data('POST', 'admin', 'get-events', to_send)
output = {'message': """"}
for event in response['events']:
desc = ""Source IP: {ip}\n""
desc += ""Datetime: {time}\n""
desc += ""Indicator: {match}\n""
desc += ""Method: {method}\n""