diff options
-rw-r--r-- | setup.py | 3 | ||||
-rwxr-xr-x | test/test_pyg.py | 2 | ||||
-rwxr-xr-x | test/test_wlp.py | 5 | ||||
-rw-r--r-- | whitelist.py | 9 | ||||
-rw-r--r-- | wlp.py | 20 |
5 files changed, 7 insertions, 32 deletions
@@ -1,6 +1,5 @@ -#!/usr/bin/python +#!/usr/bin/python3 # -*- coding: utf-8 -*- -from __future__ import print_function from mail2news import VERSION, DESC import os.path diff --git a/test/test_pyg.py b/test/test_pyg.py index 4076fc3..ddf8146 100755 --- a/test/test_pyg.py +++ b/test/test_pyg.py @@ -1,6 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- - import re import subprocess import unittest diff --git a/test/test_wlp.py b/test/test_wlp.py index 430c235..929fb1c 100755 --- a/test/test_wlp.py +++ b/test/test_wlp.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import unittest import wlp_parser @@ -97,8 +96,8 @@ class TestWLP(unittest.TestCase): self.assertEqual(tree, expected_tree) def test_wlp(self): - wlp.setfilebyname('examples/whitelist.example') - wl_dict = wlp.mkdict() + with open('examples/whitelist.example') as inf: + wl_dict = wlp.mkdict(inf) self.assertEqual(wl_dict, EXPECTED_WL) diff --git a/whitelist.py b/whitelist.py index 7eb111e..d12aea3 100644 --- a/whitelist.py +++ b/whitelist.py @@ -40,14 +40,9 @@ class whitelist(object): log_fh.setFormatter(log_fmt) self.logger.addHandler(log_fh) - try: - wlp.setfilebyname(wlfile) - except Exception as ex: - self.logger.exception('Opening %s: %s', wlfile, ex) - sys.exit(1) - # dict is a { ownername : {variable: value}} dictionary of dictionaries - self.wl = wlp.mkdict() + with open(wlfile) as inf: + self.wl = wlp.mkdict(inf) def checkfrom(self, fromhead): """have you permission to be here, sir?""" @@ -1,27 +1,11 @@ -# -*- coding: utf-8 -*- import wlp_parser -__current_file = None - - -def setfilebyname(name): - global __current_file - __current_file = open(name, 'r') - - -def setfilebyfd(fd): - global __current_file - __current_file = fd - - -def mkdict(): +def mkdict(infile): dict = {} - if __current_file is None: - raise ValueError('current file has not been set.') tree = wlp_parser.parser.parse( - wlp_parser.lexer.lex(__current_file.read())) + wlp_parser.lexer.lex(infile.read())) for subtree in tree: current_key = subtree[0].getstr().strip('<>') |