def __parse(self): print "Parsing file..." parser = FileParser() self.lines = parser.parse(file) # contains distinct flows, opened with a SYN self.flows = {} for line in self.lines: line = line.strip() tokens = line.split(' ') tokens = self.__clean(tokens) if '.' not in tokens[1]: continue key = self.__get_key(tokens) if "SYN" in line: self.flows[key] = [] continue if "Len=0" in line: continue time = float(tokens[1]) length = 0 for token in tokens: if "Len=" in token: length = int(token.split('=')[1]) break self.flows[key].append((time, length))
def main(): for filename in os.listdir('files'): filename = f'files/{filename}' if 'txt' in filename: p = FileParser(filename, '\n' * 3) p.start() else: raise ValueError('Unknown file type')
def main(): inputfile = FileParser() T = inputfile.read_int() for test in range(1, T + 1): C, J = inputfile.read_strings() result = solve(C, J) print "Case #{}: {} {}".format(test, result[0], result[1])
def main(): inputfile = FileParser() T = inputfile.read_int() for test in range(1, T + 1): S = inputfile.read_string() result = solve(S) print "Case #{}: {}".format(test, result)
def main(): inputfile = FileParser() T = inputfile.read_int() for test in range(1, T + 1): N = inputfile.read_int() senators = inputfile.read_integers() result = solve(senators) print "Case #{}: {}".format(test, " ".join(result))
def load_std(self): """ Adds the core libraries to the environment """ for i in env.standard_env: libs = env.include_lib(i) for lib in libs: if lib[0] == "py": self.vm.env.update(lib[1]) elif lib[0] == "pyl": file_parse = FileParser(lib[1], self.vm) file_parse.run()
def __init__(self, app, spec, driver='gl'): self.app = app self.spec = spec self.widgets = [] self.focus_order = None self.parser = FileParser(self.app) self.widgets = self.parser.parse(self.spec["widgets"]) self.canvas = Canvas(self.spec["app"]["width"], self.spec["app"]["height"]) self.display = Display(self.canvas) self.display.set_driver(driver) if len(self.widgets) > 0: self.focused_widget = self.widgets[0] self.build_focus_order()
def main(): inputfile = FileParser() T = inputfile.read_int() for test in range(1, T + 1): B, M = inputfile.read_integers() solution = solve(B, M) if solution is None: print "Case #{}: IMPOSSIBLE".format(test) else: print "Case #{}: POSSIBLE".format(test) for row in solution: print "".join(["1" if x else "0" for x in row]) pass
def main(): inputfile = FileParser() T = inputfile.read_int() for test in range(1, T + 1): J, P, S, K = inputfile.read_integers() solution = solve(J, P, S, K) assert len(solution) <= 1000 assert len(solution) <= J * P * S assert len(solution) >= 1 print "Case #{}: {}".format(test, len(solution)) for j, p, s in solution: print "{} {} {}".format(j+1, p+1, s+1)
def __init__(self, trgt, path=None, matchdegree=10, change=1, remove=1, insert=1): if not path: path = os.getcwd() print(path) self.matchdegree = matchdegree self.trgt = trgt self.path = path self.fpob = FileParser() self.edob = EditDis(change, remove, insert) self.caob = Cache() self.res = Heap(max=False) self.walker()
def main(): """ The main function called when the program is run. Will either start the interpreter or run a file if a filename is provided """ if len(sys.argv) == 1: from interpreter import Interpreter # Main loop which prompts user for input and print the response of the input handed to the rep function interpreter = Interpreter() interpreter.load_std() interpreter.cmdloop() else: from fileparser import FileParser from virtualmachine import VirtualMachine parser = FileParser(sys.argv[1], VirtualMachine({})) parser.load_std() parser.run()
def __parse__(self): parser = FileParser() packets = False acks = False drops = False do_nothing = False for line in parser.parse(self.input): if len(line) == 0: continue if "skip" in line: do_nothing = True if line.startswith("\"packets"): packets = True do_nothing = False continue if line.startswith("\"acks"): acks = True drops = False do_nothing = False continue if line.startswith("\"drops"): drops = True do_nothing = False continue if do_nothing: continue if packets and not acks: if drops: self.packet_drops.append(line) else: self.packets.append(line) if acks: if drops: self.ack_drops.append(line) else: self.acks.append(line)
def test_create_instance(self): try: p = FileParser() p.go() except Exception as e: self.assertEqual(type(e), TypeError)
def __parse(self): parser = FileParser() s = set() packet_numbers = {} sequence_numbers = {} start = False for line in parser.parse(self.input): array = line.split() if len(array) == 6: # header continue if "Len=0" not in line: start = True if not start: continue if "FIN" in line: break is_ack = ("ACK" in line) and ("Len=0" in line) is_data = ("Len=0" not in line) or ("SYN" in line) or ("FIN" in line) packet_number = -1 time = float(array[1]) + 1 # add one to be like ns-2 sequence_number = -1 length = -1 ack_number = -1 for item in array: if is_data and "Seq=" in item: sequence_number = int(item.split("=")[1]) packet_number = self.__get_packet_number(sequence_number) elif is_ack and "Ack=" in item: ack_number = int(item.split("=")[1]) elif "Len=" in item: length = int(item.split("=")[1]) if "SYN" in line or "FIN" in line: length = 1 temp = "" if packet_number < 10: temp = "0" tsvl = array[-2] tser = array[-1] ts = tsvl + tser if is_data: data = str(time) + " " + "1." + temp + str(packet_number) self.packets.append(data) packet_key = sequence_number + length # print "Packet key: ", packet_key # print "Packet number: ", packet_number if packet_key not in packet_numbers.keys(): packet_numbers[sequence_number + length] = packet_number else: assert is_ack if ts in s: # print "Ack number: ", ack_number # # print "Ack packet number: ", packet_numbers[ack_number] temp = "" if packet_numbers[ack_number] < 10: temp = "0" data = str(time) + " " + "1." + temp + str( packet_numbers[ack_number]) # print data self.acks.append(data) if length > 1 and sequence_numbers.has_key( sequence_number ) and sequence_numbers[sequence_number] != ts: # duplicate for item in self.packets: num = item.split()[1] num = int(num.split(".")[1]) if num == self.__get_packet_number(sequence_number): self.packets.remove(item) self.packet_drops.append(item) break s.add(ts) if length > 1 and sequence_numbers.has_key( sequence_number ) and sequence_numbers[sequence_number] == ts: del sequence_numbers[sequence_number] else: sequence_numbers[sequence_number] = ts
from fileparser import FileParser if __name__ == "__main__": FileParser('lorem.txt', 'ipsum') FileParser('lorem.txt', 'IPS', 'ipsum')
def __init__(self): super(EasySub, self).__init__() self._file_parser = FileParser() self._subscene = Subscene()
def __init__(self): super(EasySubConsole, self).__init__() self._file_parser = FileParser() self._easysub = EasySub()
# -*- coding: UTF-8 -*- from __future__ import division from fileparser import FileParser def solve(n): if n == 0: return False digits = set("0123456789") i = 0 while len(digits) > 0: i += 1 digits -= set(str(n * i)) #print "{} {} {} --> {}".format(i, n * i, set(str(n * i)), digits) return n * i inputfile = FileParser() T = inputfile.read_int() for test in range(1, T+1): N = inputfile.read_int() result = solve(N) if result: print "Case #{}: {}".format(test, result) else: print "Case #{}: INSOMNIA".format(test)