text
stringlengths
0
828
self.__timer.start(timeout)"
4164,"def __flush(self):
""""""If there is a signal queued up, send it now.""""""
if self.__args is None or self.__disconnecting:
return False
#self.emit(self.signal, *self.args)
self.__sigDelayed.emit(self.__args)
self.__args = None
self.__timer.stop()
self.__lastFlushTime = time.time()
return True"
4165,"def clean_indicators(indicators):
""""""Remove any extra details from indicators.""""""
output = list()
for indicator in indicators:
strip = ['http://', 'https://']
for item in strip:
indicator = indicator.replace(item, '')
indicator = indicator.strip('.').strip()
parts = indicator.split('/')
if len(parts) > 0:
indicator = parts.pop(0)
output.append(indicator)
output = list(set(output))
return output"
4166,"def hash_values(values, alg=""md5""):
""""""Hash a list of values.""""""
import hashlib
if alg not in ['md5', 'sha1', 'sha256']:
raise Exception(""Invalid hashing algorithm!"")
hasher = getattr(hashlib, alg)
if type(values) == str:
output = hasher(values).hexdigest()
elif type(values) == list:
output = list()
for item in values:
output.append(hasher(item).hexdigest())
return output"
4167,"def check_whitelist(values):
""""""Check the indicators against known whitelists.""""""
import os
import tldextract
whitelisted = list()
for name in ['alexa.txt', 'cisco.txt']:
config_path = os.path.expanduser('~/.config/blockade')
file_path = os.path.join(config_path, name)
whitelisted += [x.strip() for x in open(file_path, 'r').readlines()]
output = list()
for item in values:
ext = tldextract.extract(item)
if ext.registered_domain in whitelisted:
continue
output.append(item)
return output"
4168,"def cache_items(values):
""""""Cache indicators that were successfully sent to avoid dups.""""""
import os
config_path = os.path.expanduser('~/.config/blockade')
file_path = os.path.join(config_path, 'cache.txt')
if not os.path.isfile(file_path):
file(file_path, 'w').close()
written = [x.strip() for x in open(file_path, 'r').readlines()]
handle = open(file_path, 'a')
for item in values:
# Because of the option to submit in clear or hashed, we need to make
# sure we're not re-hashing before adding.
if is_hashed(item):
hashed = item
else:
hashed = hash_values(item)
if hashed in written:
continue
handle.write(hashed + ""\n"")
handle.close()
return True"
4169,"def prune_cached(values):
""""""Remove the items that have already been cached.""""""
import os
config_path = os.path.expanduser('~/.config/blockade')
file_path = os.path.join(config_path, 'cache.txt')
if not os.path.isfile(file_path):
return values
cached = [x.strip() for x in open(file_path, 'r').readlines()]
output = list()
for item in values:
hashed = hash_values(item)
if hashed in cached:
continue
output.append(item)
return output"
4170,"def get_logger(name):
""""""Get a logging instance we can use.""""""
import logging
import sys
logger = logging.getLogger(name)
logger.setLevel(logging.DEBUG)
shandler = logging.StreamHandler(sys.stdout)
fmt = """"