Ejemplo n.º 1
0
 def test_iter_file(self):
     expected = ["Hola, esta\n", "es una cadena\n", "de texto\n"]
     with FileReader(textfile) as reader:
         assert reader.encoding == "utf-8"
         assert reader.filename == textfile
         for line, expected_line in zip(reader, expected):
             assert line == expected_line
Ejemplo n.º 2
0
def initialize_scanner(source_path):
    reader = FileReader(source_path)
    machine = Scanner(reader)

    machine.add_state('start', start_state_transition)
    machine.add_state('a', a_state_transition)
    machine.add_state('b', b_state_transition)
    machine.add_state('c', c_state_transition)
    machine.add_state('d', d_state_transition)
    machine.add_state('id', None, end_state=True)
    machine.add_state('digit', None, end_state=True)
    machine.add_state('operator', None, end_state=True)

    machine.set_start('start')

    return machine
Ejemplo n.º 3
0
    def setUp(self):
        """
        manitest file location: ../manifests/opencart.txt
        with following contents
        -----------------------------------
        basepath=/home/vineet/public_html/
        basedir=opencart_v1.4.9.4

        index.php
        catalog/controller/account/account.php
        catalog/controller/account/create.php
        catalog/controller/feed/*
        catalog/model/**
        -----------------------------------
        """
        self.file = '../manifests/opencart.txt'
        self.reader = FileReader(self.file)
Ejemplo n.º 4
0
def get_reader(cmd_argv):
    """
    function to get the correct reader object as per the command
    """
    if cmd_argv[1] == '--file':
        reader = FileReader(cmd_argv[2])
    elif cmd_argv[1] == '--git':
        args = cmd_argv[2:]
        wd = args.pop(0)
        hash1 = args.pop(0)
        try:
            hash2 = args.pop(0)
        except IndexError:
            hash2 = None
        reader = GitReader(wd, hash1, hash2)
    else:
        raise UnsupportedReaderError(cmd_argv[1])
    return reader
Ejemplo n.º 5
0
def init():
    # Setup DAQ Readers
    DAQreader['micreader'] = {'reader': MicReader.MicReader(), 'name': "Mic"}
    DAQreader['randomreader'] = {
        'reader': RandomReader.RandomReader(),
        'name': 'Random'
    }
    try:
        DAQreader['delsysreader'] = {
            'reader': DelsysReader.DelsysReader(),
            'name': 'Delsys'
        }
    except Exception as e:
        print("ERROR With Delsys")

    # Setup File Reader
    filereader['reader'] = FileReader.FileReader()

    return jsonify(1)
Ejemplo n.º 6
0
 def test_whole_file(self):
     expected = "Hola, esta\nes una cadena\nde texto\n"
     result = FileReader(textfile).read()
     assert result == expected
Ejemplo n.º 7
0
 def test__enter__(self):
     with FileReader(textfile) as reader:
         assert reader.is_open
     assert not reader.is_open
Ejemplo n.º 8
0
 def test_open_fails(self):
     f = FileReader('wrong file that does not exist')
     with raises(FileNotFoundError):
         f.open()
Ejemplo n.º 9
0
 def test_open_closed_ok(self):
     f = FileReader(textfile)
     f.open()
     assert f.is_open
     f.close()
     assert not f.is_open
Ejemplo n.º 10
0
 def test__init__(self):
     f = FileReader(textfile)
     assert f.filename == textfile
     assert f.encoding == "utf-8"
     assert not f.is_open
     assert f.file is None
Ejemplo n.º 11
0
# TODO see if there are different ASNs for both the one we queried and the one who queries our servers
# example of how to call: python PlotMain.py C:/Users/tyler/PycharmProjects/PlottingPractice/datalib

################################################################################################################
# This program reads all data files that are created from the data gathered by running a fullscan of ipv4 space
# This includes maxudp data, p0f, ASN, and geolocation. In essence this program gathers all the data into one
# point for ease of use. All data is put into two dictionaries. One, variable_dict, has each possible variable
# as a key for
################################################################################################################
# READ IN THE DATA FROM OUR FILES

if len(sys.argv) != 2:
    print("Invalid, Usage: python PlotMain.py {}\n".format("<DataFilesPath>"))
    exit(1)
directory = sys.argv[1]
fileReader = File_Reader.FileReader(directory)

# All files we are reading should be in one directory given as an argument
# Read in all the files
print("Reading all files...\n")
data_holders = fileReader.read_all_files()
d = data_holders.get_value_dict("country")

######################################################################################################
# BEGIN PROCESSING THE DATA
print("All possible keys are as follows: ")
for key in data_holders.all_possible_keys:
    print("%s " % key)

######################################################################################################
# Write data out to files