Comparison on flavors
Code cleaning ...
This commit is contained in:
parent
080505a032
commit
43c6164e10
@ -5,6 +5,7 @@ import os
|
||||
import re
|
||||
import urllib
|
||||
from urlparse import urlparse
|
||||
|
||||
try:
|
||||
import config
|
||||
except ImportError:
|
||||
@ -16,6 +17,7 @@ except ImportError:
|
||||
print("Please install python-cdb from pypi or via package manager")
|
||||
exit()
|
||||
|
||||
|
||||
def make_list(files):
|
||||
blacklists = []
|
||||
for l in files:
|
||||
@ -24,6 +26,7 @@ def make_list(files):
|
||||
blacklists.append([list_type, l])
|
||||
return blacklists
|
||||
|
||||
|
||||
def make_db(blacklist_files, config):
|
||||
lib = []
|
||||
for bl in blacklist_files:
|
||||
@ -40,6 +43,7 @@ def make_db(blacklist_files,config):
|
||||
lib.append(bl_cdb_file)
|
||||
return lib
|
||||
|
||||
|
||||
def compare(outline, blacklist_cache):
|
||||
result = False
|
||||
for blacklist in blacklist_cache:
|
||||
@ -54,16 +58,19 @@ def compare(outline,blacklist_cache):
|
||||
tmpline = tmpline.partition('.')[2]
|
||||
return result
|
||||
|
||||
|
||||
def squid_response(response):
|
||||
sys.stdout.write("%s\n" % response)
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
domain_files = [os.path.join(dp, f) for dp, dn, fn in os.walk(os.path.expanduser(config.blacklists_dir)) for f in fn if re.match(r"domains*", f)]
|
||||
|
||||
blacklist_files = make_list(domain_files)
|
||||
blacklist_cache = make_db(blacklist_files, config)
|
||||
|
||||
while True:
|
||||
try:
|
||||
line = sys.stdin.readline().strip()
|
||||
outline = urlparse(line).netloc
|
||||
if line:
|
||||
@ -71,3 +78,5 @@ while True:
|
||||
squid_response("OK")
|
||||
else:
|
||||
squid_response("ERR")
|
||||
except KeyboardInterrupt:
|
||||
break
|
@ -5,12 +5,14 @@ import os
|
||||
import re
|
||||
import urllib
|
||||
from urlparse import urlparse
|
||||
|
||||
try:
|
||||
import config
|
||||
except ImportError:
|
||||
print("Please create config.py using config.py.sample")
|
||||
exit()
|
||||
|
||||
|
||||
def make_list(files):
|
||||
blacklists = []
|
||||
for l in files:
|
||||
@ -19,10 +21,11 @@ def make_list(files):
|
||||
blacklists.append([list_type, l])
|
||||
return blacklists
|
||||
|
||||
def make_db(blacklist_files,blacklists):
|
||||
|
||||
def make_db(blacklist_files, config):
|
||||
lib = dict()
|
||||
for bl in blacklist_files:
|
||||
if(bl[0] in blacklists):
|
||||
if (bl[0] in config.blacklists):
|
||||
cache = dict()
|
||||
f = open(bl[1], "r")
|
||||
for line in f:
|
||||
@ -31,6 +34,7 @@ def make_db(blacklist_files,blacklists):
|
||||
del cache
|
||||
return lib
|
||||
|
||||
|
||||
def compare(outline, blacklist_cache):
|
||||
result = False
|
||||
for blacklist in blacklist_cache:
|
||||
@ -44,16 +48,19 @@ def compare(outline,blacklist_cache):
|
||||
tmpline = tmpline.partition('.')[2]
|
||||
return result
|
||||
|
||||
|
||||
def squid_response(response):
|
||||
sys.stdout.write("%s\n" % response)
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
domain_files = [os.path.join(dp, f) for dp, dn, fn in os.walk(os.path.expanduser(config.blacklists_dir)) for f in fn if re.match(r"domains*", f)]
|
||||
|
||||
blacklist_files = make_list(domain_files)
|
||||
blacklist_cache = make_db(blacklist_files,config.blacklists)
|
||||
blacklist_cache = make_db(blacklist_files, config)
|
||||
|
||||
while True:
|
||||
try:
|
||||
line = sys.stdin.readline().strip()
|
||||
outline = urlparse(line).netloc
|
||||
if line:
|
||||
@ -61,3 +68,5 @@ while True:
|
||||
squid_response("OK")
|
||||
else:
|
||||
squid_response("ERR")
|
||||
except KeyboardInterrupt:
|
||||
break
|
||||
|
Loading…
Reference in New Issue
Block a user