示例#1
0
def main(filename):

	with open(filename, 'r') as f:
		data = f.readlines()[0].strip() # only interested in one line

	op_codes = data.split(",")
	op_codes[1] = "12"
	op_codes[2] = "2"

	new_state = Parser().parse_string(",".join(op_codes))
	print(f"Answer for part 1: {new_state.split(',')[0]}")

	# part 2
	answer = None
	for i in range(99):
		for j in range(99):
			op_codes = data.split(",")
			op_codes[1] = str(i)
			op_codes[2] = str(j)
			new_state = Parser().parse_string(",".join(op_codes))
			result, noun, verb = new_state.split(",")[:3]
			if int(result) == 19690720:
				answer = str(100 * int(noun) + int(verb))
				break
		else:
			continue
		break 
	if answer is not None:
		print(f"Answer for part 2: {answer}")
	else:
		print("Failed to find an answer for part 2.")
示例#2
0
def main():
    parser = Parser()
    paren_tree = ParenTree()

    arg = ''.join(sys.argv[1:])

    if arg == 'test':
        result = test()
        demo('Test results:', result)
    else:
        input_expr = test_strings[arg] if test_strings.get(arg) else arg

        demo('RAW INPUT', input_expr)

        char_list = parser.parse_expression(input_expr)

        python_result = round(eval(''.join(char_list)), RESULT_ROUND_TO)

        # demo('PARSED INPUT', char_list)

        paren_tree.parse_char_list(char_list)

        # demo('PARSED PAREN TREE', paren_tree)

        result = round(paren_tree.evaluate(), RESULT_ROUND_TO)

        demo('RESULT', result)
    def test_run(self):
        program = Program()
        inputFileName = os.path.join(
            os.getcwd(), 'integration/example_data/input_test_data.csv')
        outputFileName = os.path.join(
            os.getcwd(), 'integration/example_data/interpolated_data.csv')
        expectedFileName = os.path.join(
            os.getcwd(), 'integration/example_data/interpolated_test_data.csv')
        program.transport = FileTransport(inputFileName, outputFileName)
        program.parser = Parser()
        program.interpolator = Interpolator()

        program.run()

        self.assertTrue(filecmp.cmp(expectedFileName, outputFileName))
示例#4
0
def test():
    successes = []
    failures = []
    for key in test_strings:
        parser = Parser()
        paren_tree = ParenTree()

        char_list = parser.parse_expression(test_strings[key])
        # print(char_list)

        # print(round(eval(''.join(char_list)), ))
        python_result = round(eval(''.join(char_list)), RESULT_ROUND_TO)
        print(python_result)

        paren_tree.parse_char_list(char_list)

        test_result = round(paren_tree.evaluate(), RESULT_ROUND_TO)

        if test_result == python_result:
            successes.append(test_strings[key] + ' = ' + str(test_result))
        else:
            failures.append({
                'key': key,
                'expression': test_strings[key],
                'test_result': test_result,
                'python_result': python_result
            })

    message = ''

    if len(failures):
        message += f'{len(failures)} FAILURES:\n\n'
        for fail in failures:
            print(fail)
            message += f"key:           {fail['key']}\n"
            message += f"expression:    {fail['expression']}\n"
            message += f"test result:   {fail['test_result']}\n"
            message += f"python result: {fail['python_result']}\n\n"

    if len(successes):
        message += f'{len(successes)} SUCCESSES:\n\n'
        for s in successes:
            message += s + '\n\n'

    return message
示例#5
0
    def test_read_with_nan_values(self):
        input = [['37.454012', '95.071431', '73.199394', '59.865848', 'nan'],
                 [
                     '15.599452', '5.808361', '86.617615', '60.111501',
                     '70.807258'
                 ], ['2.058449', '96.990985', 'nan', '21.233911', '18.182497'],
                 ['nan', '30.424224', '52.475643', '43.194502', '29.122914'],
                 ['61.185289', '13.949386', '29.214465', 'nan', '45.606998']]
        expected = [[37.454012, 95.071431, 73.199394, 59.865848, 'nan'],
                    [15.599452, 5.808361, 86.617615, 60.111501, 70.807258],
                    [2.058449, 96.990985, 'nan', 21.233911, 18.182497],
                    ['nan', 30.424224, 52.475643, 43.194502, 29.122914],
                    [61.185289, 13.949386, 29.214465, 'nan', 45.606998]]
        parser = Parser()

        actual = parser.parse(input)

        self.assertEqual(expected, actual)
示例#6
0
 def test_part1_2(self):
     new_state = Parser().parse_string("2,3,0,3,99")
     self.assertEqual(new_state, "2,3,0,6,99")
示例#7
0
 def test_part1_1(self):
     new_state = Parser().parse_string("1,0,0,0,99")
     self.assertEqual(new_state, "2,0,0,0,99")
示例#8
0
 def test_part1_5(self):
     new_state = Parser().parse_string("1,9,10,3,2,3,11,0,99,30,40,50")
     self.assertEqual(new_state, "3500,9,10,70,2,3,11,0,99,30,40,50")
示例#9
0
 def test_part1_4(self):
     new_state = Parser().parse_string("1,1,1,4,99,5,6,0,99")
     self.assertEqual(new_state, "30,1,1,4,2,5,6,0,99")
示例#10
0
 def test_part1_3(self):
     new_state = Parser().parse_string("2,4,4,5,99,0")
     self.assertEqual(new_state, "2,4,4,5,99,9801")
示例#11
0
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:cwmp="urn:dslforum-org:cwmp-1-1">
<soap:Header>
</soap:Header>
<soap:Body>
<cwmp:GetParameterNames>
<ParameterPath>InternetGatewayDevice.DeviceInfo.Hello</ParameterPath>
<NextLevel>false</NextLevel>
</cwmp:GetParameterNames>
</soap:Body>
</soap:Envelope>
"""

parse=Parser.Parser()
commands_server=parse.parse_struct(xml)

for command in commands_server.keys():
  if re.search(r'getparameternames',command.lower()):
        print (command)
        params=commands_server[command]

        print (params['ParameterPath'])


    
    


示例#12
0
 def get_command(self):
     ret = self.http.response()
     parse = Parser.Parser()
     data = parse.parse_struct(ret)
     return data
示例#13
0
 def test_construct(self):
     parser = Parser()
     self.assertIsNotNone(parser)
示例#14
0
#! /usr/bin/env python

import io
import json
from jinja2 import Template
from lib import Parser
from config import template_vars

src_html = ["src/en/index.html", "src/ch/index.html", "src/faq/index.html"]
strings = dict()
for fname in src_html:
    with io.open(fname, encoding="utf-8") as f:
        p = Parser(strings)
        p.feed(Template(f.read()).render(template_vars))
        p.close()

with io.open("lang/en_US.json", "w", encoding="utf-8") as f:
    f.write(
        unicode(
            json.dumps(strings,
                       ensure_ascii=False,
                       sort_keys=True,
                       indent=0,
                       separators=(',', ': '))))
示例#15
0
 def __init__(self):
     self.transport = InputTransport()
     self.parser = Parser()
     self.interpolator = Interpolator()
示例#16
0
文件: main.py 项目: duominds/nibras
if __name__ == "__main__":

    start = time.time()
    resultpath = dirinit()
    config_files = InputParser()
    config_files.check_input_files()
    config_files.input_parser()
    run()
    coll = str(len("Collecting Information from the switches"))
    with tqdm(
        total=1,
        file=sys.stdout,
        desc="Parsing switches Information",
        ascii=True,
        bar_format="{desc:37}: {percentage:3.0f}%|{bar}|",
    ) as pbar:
        parser = Parser()
        data = parser.file_parse()
        pbar.update()
    with tqdm(
        total=1,
        file=sys.stdout,
        desc="Genrating report",
        ascii=True,
        bar_format="{desc:37}: {percentage:3.0f}%|{bar}|",
    ) as pbar:
        parser.reporter(data)
        pbar.update()
    dirend()
    print("Reports have been generated in the following path : %s" % resultpath)
示例#17
0
def gis(arg):
    parse_GIS = Parser(args.input)
    dict_gis = parse_GIS.load_json()

    obj = GIS(dict_gis)
    obj.init()