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 not os.path.isfile(bl_cdb_file):
cdb_file = cdb.cdbmake(bl_cdb_file, bl_cdb_file_tmp)
cache = dict()
f = open(bl[1], "r")
for line in f:
cdb_file.add(line.strip("\n"), "True")

View File

@ -20,11 +20,12 @@ except ImportError:
class PySquidBlacklists:
def __init__(self, config):
self.db_backend = config.db_backend
self.blacklist_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.categories = config.categories
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)]
self.blacklist_files = self.make_list()
self.blacklist_cache = self.make_db()
self.cache = self.make_db()
def make_list(self):
blacklists = []
@ -37,7 +38,8 @@ class PySquidBlacklists:
def make_db(self):
lib = dict()
for bls in self.blacklist_files:
if bls[0] in self.blacklist_categories:
if self.db_backend == "ram":
if bls[0] in self.categories:
cache = dict()
f = open(bls[1], "r")
for l in f:
@ -46,17 +48,13 @@ class PySquidBlacklists:
del cache
return lib
@property
def initialize():
return True
def compare(self, outline):
result = False
for blacklist in self.blacklist_cache:
for blacklist in self.cache:
tmpline = outline
while not result and tmpline != "":
try:
result = self.blacklist_cache[blacklist][tmpline]
result = self.cache[blacklist][tmpline]
pass
except KeyError:
pass