diff options
| author | Barry Warsaw | 2017-01-01 22:43:16 -0500 |
|---|---|---|
| committer | Barry Warsaw | 2017-01-01 22:43:16 -0500 |
| commit | 54c9cf97ece230753b6b65597f5009a0c727e830 (patch) | |
| tree | 6bd66871932a208ae54ed82561a1921b970abe09 | |
| parent | e3d6c34b7d02b925cb8c59fa9e1df24741fc46ee (diff) | |
| download | mailman-54c9cf97ece230753b6b65597f5009a0c727e830.tar.gz mailman-54c9cf97ece230753b6b65597f5009a0c727e830.tar.zst mailman-54c9cf97ece230753b6b65597f5009a0c727e830.zip | |
| -rw-r--r-- | src/mailman/rules/dmarc.py | 11 | ||||
| -rw-r--r-- | src/mailman/rules/tests/data/org_domain.txt | 2 | ||||
| -rw-r--r-- | src/mailman/rules/tests/test_dmarc.py | 12 |
3 files changed, 19 insertions, 6 deletions
diff --git a/src/mailman/rules/dmarc.py b/src/mailman/rules/dmarc.py index 122aefe7b..8180211bc 100644 --- a/src/mailman/rules/dmarc.py +++ b/src/mailman/rules/dmarc.py @@ -102,12 +102,13 @@ def ensure_current_suffix_list(): return cached_copy_path -def parse_suffix_list(): +def parse_suffix_list(filename=None): # Parse the suffix list into a per process cache. - cached_copy_path = ensure_current_suffix_list() + if filename is None: + filename = ensure_current_suffix_list() # At this point the cached copy must exist and is as valid as possible. # Read and return the contents as a UTF-8 string. - with open(cached_copy_path, 'r', encoding='utf-8') as fp: + with open(filename, 'r', encoding='utf-8') as fp: for line in fp: if not line.strip() or line.startswith('//'): continue @@ -121,8 +122,8 @@ def parse_suffix_list(): else: exception = False parts.reverse() - k = DOT.join(parts) - suffix_cache[k] = exception + key = DOT.join(parts) + suffix_cache[key] = exception def _get_dom(d, l): diff --git a/src/mailman/rules/tests/data/org_domain.txt b/src/mailman/rules/tests/data/org_domain.txt index 4e6f7816e..e10db8a32 100644 --- a/src/mailman/rules/tests/data/org_domain.txt +++ b/src/mailman/rules/tests/data/org_domain.txt @@ -17,7 +17,7 @@ org !city.kobe.jp // A line with a trailing comment for testing -co.uk some nonesence +co.uk some nonsense // A line with leading white space (ignored) example.biz diff --git a/src/mailman/rules/tests/test_dmarc.py b/src/mailman/rules/tests/test_dmarc.py index df5127895..7748343eb 100644 --- a/src/mailman/rules/tests/test_dmarc.py +++ b/src/mailman/rules/tests/test_dmarc.py @@ -173,6 +173,18 @@ To: ant@example.com 'anne@example.info (_dmarc.example.info). ' 'Abstract base class shared by all dnspython exceptions.\n') + def test_parser(self): + data_file = resource_filename( + 'mailman.rules.tests.data', 'org_domain.txt') + dmarc.parse_suffix_list(data_file) + # There is no entry for example.biz because that line starts with + # whitespace. + self.assertNotIn('biz.example', self.cache) + # The file had !city.kobe.jp so the flag says there's an exception. + self.assertTrue(self.cache['jp.kobe.city']) + # The file had *.kobe.jp so there's no exception. + self.assertFalse(self.cache['jp.kobe.*']) + # New in Python 3.5. try: |
