Various mods

This commit is contained in:
Paul 2016-02-20 14:59:34 +01:00
parent 58945f0fa4
commit acaa217314
2 changed files with 14 additions and 17 deletions

View File

@ -34,7 +34,6 @@ def make_db(blacklist_files, config):
if (bl[0] in config.blacklists): if (bl[0] in config.blacklists):
if not os.path.isfile(bl_cdb_file): if not os.path.isfile(bl_cdb_file):
cdb_file = cdb.cdbmake(bl_cdb_file, bl_cdb_file_tmp) cdb_file = cdb.cdbmake(bl_cdb_file, bl_cdb_file_tmp)
cache = dict()
f = open(bl[1], "r") f = open(bl[1], "r")
for line in f: for line in f:
cdb_file.add(line.strip("\n"), "True") cdb_file.add(line.strip("\n"), "True")

View File

@ -20,11 +20,12 @@ except ImportError:
class PySquidBlacklists: class PySquidBlacklists:
def __init__(self, config): def __init__(self, config):
self.db_backend = config.db_backend self.db_backend = config.db_backend
self.blacklist_categories = config.categories self.categories = config.categories
self.domain_files = [os.path.join(dp, f) for dp, dn, fn in os.walk(os.path.expanduser(config.base_dir)) for f in self.base_dir = config.base_dir
self.domain_files = [os.path.join(dp, f) for dp, dn, fn in os.walk(os.path.expanduser(self.base_dir)) for f in
fn if re.match(r"domains*", f)] fn if re.match(r"domains*", f)]
self.blacklist_files = self.make_list() self.blacklist_files = self.make_list()
self.blacklist_cache = self.make_db() self.cache = self.make_db()
def make_list(self): def make_list(self):
blacklists = [] blacklists = []
@ -37,26 +38,23 @@ class PySquidBlacklists:
def make_db(self): def make_db(self):
lib = dict() lib = dict()
for bls in self.blacklist_files: for bls in self.blacklist_files:
if bls[0] in self.blacklist_categories: if self.db_backend == "ram":
cache = dict() if bls[0] in self.categories:
f = open(bls[1], "r") cache = dict()
for l in f: f = open(bls[1], "r")
cache[l.strip("\n")] = True for l in f:
lib[bls[0]] = cache cache[l.strip("\n")] = True
del cache lib[bls[0]] = cache
del cache
return lib return lib
@property
def initialize():
return True
def compare(self, outline): def compare(self, outline):
result = False result = False
for blacklist in self.blacklist_cache: for blacklist in self.cache:
tmpline = outline tmpline = outline
while not result and tmpline != "": while not result and tmpline != "":
try: try:
result = self.blacklist_cache[blacklist][tmpline] result = self.cache[blacklist][tmpline]
pass pass
except KeyError: except KeyError:
pass pass