commit bf3a0362a7cf6d4b22a600a17c7ea906b3ec48b8
Author: Isis Lovecruft <isis(a)patternsinthevoid.net>
Date: Wed Mar 14 23:26:24 2012 -0700
Moved parsing logic for top-1m asset to Top1MAsset class in DNS test
---
assets/fix-top-1m.py | 34 ----------------------------------
tests/dnstamper.py | 12 +++++++++++-
2 files changed, 11 insertions(+), 35 deletions(-)
diff --git a/assets/fix-top-1m.py b/assets/fix-top-1m.py
deleted file mode 100755
index 9e6b681..0000000
--- a/assets/fix-top-1m.py
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/usr/bin/env python
-###############
-# fix-top-1m.py
-###############
-# Removes the 'N,' from the default top-1m.txt.
-# ::author:: Isis Lovecruft
-
-from __future__ import with_statement
-from contextlib import nested
-import os
-import re
-import tempfile
-
-def remove_cruft():
- print 'Opening list of top webservers for parsing...'
- in_file = os.path.abspath('top-1m.txt')
- print 'Creating temporary file for parsing purposes...'
- outfile = os.path.abspath('top-1m.txt~')
- tempfile.NamedTemporaryFile('w+b', 1000, '.txt~', 'top-1m',
- os.getcwd())
- with open(in_file, 'r+') as in_, open('top-1m.txt~', 'w+') as out_:
- lines = in_.readlines()
- print 'Replacing cruft with nothingness...'
- for line in lines:
- out_.write(re.sub('^(\d+),', '', line))
- print 'Removing write access to temp file...'
- out_.close()
- in_.close()
- print 'Renaming parsed temp file as orginal file...'
- os.rename('top-1m.txt~', 'top-1m.txt')
- print 'List of webservers now ready for use!'
-
-if __name__=="__main__":
- remove_cruft()
diff --git a/tests/dnstamper.py b/tests/dnstamper.py
index 23318b6..1e59d26 100644
--- a/tests/dnstamper.py
+++ b/tests/dnstamper.py
@@ -7,11 +7,21 @@ import os
import plugoo
from plugoo.assets import Asset
from plugoo.tests import Test
-
+from __future__ import with_statement
__plugoo__ = "DNST"
__desc__ = "DNS censorship detection test"
+class Top1MAsset(Asset):
+ def __init__(self, file=None):
+ self = Asset.__init__(self, file)
+
+ def next_asset(self):
+ with self.fh as asset:
+ lines = asset.readlines()
+ for line in lines:
+ yield line.split(',')[1]
+
class DNSTAsset(Asset):
def __init__(self, file=None):
self = Asset.__init__(self, file)