Exemple #1
0
def main():
    args_parser = argparse.ArgumentParser(
        description="Updates 'Chrome Browser Network Traffic Annotations' doc."
    )
    args_parser.add_argument("--config-file", help="Configurations file.")
    args_parser.add_argument(
        "--annotations-file",
        help="TSV annotations file exported from auditor.")
    args_parser.add_argument("--verbose",
                             action="store_true",
                             help="Reports all updates. "
                             " Also creates a scripts/template.json file "
                             " outlining the document's current structure.")
    args_parser.add_argument("--config-help",
                             action="store_true",
                             help="Shows the configurations help.")
    args = args_parser.parse_args()

    if args.config_help:
        print_config_help()
        return 0

    # Load and parse config file.
    with open(os.path.join(SRC_DIR, args.config_file)) as config_file:
        config = json.load(config_file)

    tsv_contents = load_tsv_file(os.path.join(SRC_DIR, args.annotations_file),
                                 False)
    if not tsv_contents:
        print("Could not read annotations file.")
        return -1

    xml_parser = XMLParser(
        os.path.join(SRC_DIR, "tools/traffic_annotation/summary/grouping.xml"),
        map_annotations(tsv_contents))
    placeholders = xml_parser.build_placeholders()
    print("#" * 40)
    print("There are:", len(placeholders), "placeholders")
    if args.verbose:
        print(placeholders)
    print("#" * 40)

    network_traffic_doc = NetworkTrafficAnnotationsDoc(
        doc_id=config["doc_id"],
        doc_name=config["doc_name"],
        credentials_file_path=config["credentials_file_path"],
        client_token_file_path=config["client_token_file_path"],
        verbose=args.verbose)

    if not network_traffic_doc.update_doc(placeholders):
        return -1

    return 0
Exemple #2
0
def xml_to_text(stream):
    if type(stream) is str:
        stream = XMLParser(stream)

    encoding = 'utf-8'
    text = []
    for event, value, line in stream:
        # TODO Extract some attribute values
        if event == TEXT:
            text.append(value)
        elif event == XML_DECL:
            encoding = value[1]
    return unicode(' '.join(text), encoding)
Exemple #3
0
def runtests(filename):
    f = open(filename)
    tests = f.read().split("#data\n")
    errorAmount = index = 0
    errorLog = []
    for index, test in enumerate(tests):
        if test == "": continue
        test = "#data\n" + test
        input, expected, errors = parseTestcase(test)
        parser = XMLParser()
        result = parser.parse(input).printTree()
        if result != "#document\n" + expected:
            errorAmount += 1
            errorLog.append("For:\n" + input + "\nExpected:\n" + expected +
                            "\nGot:\n" + result + "\n\n")
    if errorAmount == 0:
        print "All Good!"
    else:
        print "\n" + "".join(errorLog)
Exemple #4
0
 def __init__(self, xml, polly_xml=None, symsubs=None, namesubs=None):
     self.functions = XMLParser(xml, symsubs, namesubs).functions
     if polly_xml:
         self.scops = PollyXMLParser(polly_xml).scops
     else:
         self.scops = []
Exemple #5
0
# -*- coding: utf-8 -*-
from parser import XMLParser
from html_generator import HTMLGenerator

import sys

if __name__ == "__main__":

    if len(sys.argv) != 3:
        print "python " + __file__ + " <xml_file> <n_day>"
        print "e.g.:"
        print "> python " + __file__ + " input/schedule.xml 0"
        print "for printing the schedule of the first day."
        sys.exit(1)

    parser = XMLParser(sys.argv[1])
    conference = parser.parse()
    dumper = HTMLGenerator(conference)
    dumper.dump(int(sys.argv[2]))
Exemple #6
0
from parser import XMLParser

parser = XMLParser()

for x in range(1, 7):
    print(f"Test case {x}: ", end="")
    doc = str(open(f'sample{x}/ccd.xml').read()).strip()
    query = str(open(f'sample{x}/query.txt').read()).strip().replace('\n', ' ')
    output = str(open(f'sample{x}/output.txt').read()).strip()

    document = parser.parse(doc).find('ClinicalDocument')

    if document.execute_query(query) == output:
        print('Correct. Found', output)
    else:
        print("Incorrect. Did not find", output)
Exemple #7
0
	def _initialize_xml_parser(self, restrictions, required_fields):
		self._xml_parser = XMLParser(MagicMock(), MagicMock(),
									 restrictions, required_fields)
Exemple #8
0
def test(string):
    x = XMLParser()
    tree = x.parse(string)
    print tree.printTree()