Пример #1
0
    def __call__(self, command, options):
        from django.utils import translation
        translation.activate('en-us')

        testutil.unmonkeypatch_databases()

        with open(options["src"], 'r') as src:
            source = src.read()
            prepared, _ = prepare_article_data(source)
            with open(options["dst"], 'w') as dst:
                data = util.run_xsltproc("utils/xsl/strip.xsl", prepared)
                dst.write(data)
            with open(options["bibl"], 'w') as bibl:
                bibl.write(json.dumps(get_bibliographical_data(source)[1]))
Пример #2
0
def as_editable(filepath):
    editable = as_editable_table.get(filepath, None)
    if editable is not None:
        return editable

    data = open(filepath).read()

    # We ask xsltproc not to put out a declaration and add our own.
    tidy = b'<?xml version="1.0" encoding="UTF-8"?>' + \
        util.run_xsltproc(os.path.join(xml.xsl_dirname, "strip.xsl"),
                          data).encode("utf8")

    as_editable_table[filepath] = tidy
    return tidy
Пример #3
0
def as_editable(filepath):
    editable = as_editable_table.get(filepath, None)
    if editable is not None:
        return editable

    data = open(filepath).read().decode('utf-8')

    # We ask xsltproc not to put out a declaration and add our own.
    tidy = '<?xml version="1.0" encoding="UTF-8"?>' + \
        util.run_xsltproc(os.path.join(xml.xsl_dirname, "strip.xsl"),
                          data).encode("utf-8")

    as_editable_table[filepath] = tidy
    return tidy
Пример #4
0
def fetch():
    with open("utils/schemas/prasada.xml") as f:
        data = f.read()

    # Clean it for raw edit.
    data = util.run_xsltproc("utils/xsl/strip.xsl", data)

    tree = xml.XMLTree(data)
    version = tree.extract_version()

    if not util.validate_with_rng(xml.schema_for_version(version), data):
        raise ValueError("the file is not actually valid!")

    sch = xml.schematron_for_version(version)
    if sch and not util.schematron(sch, data):
        raise ValueError("the file does not pass schematron validation!")

    return data
Пример #5
0
def fetch():
    with open("utils/schemas/prasada.xml") as f:
        data = f.read().decode("utf-8")

    # Clean it for raw edit.
    data = util.run_xsltproc("utils/xsl/strip.xsl", data)

    tree = xml.XMLTree(data)
    version = tree.extract_version()

    if not util.validate_with_rng(xml.schema_for_version(version), data):
        raise ValueError("the file is not actually valid!")

    sch = xml.schematron_for_version(version)
    if sch and not util.schematron(sch, data):
        raise ValueError("the file does not pass schematron validation!")

    return data
Пример #6
0
    def test_roundtrip(self):
        # We don't use as_editable() here because we need the tidy
        # intermediary state.
        data = open(os.path.join(xml.schemas_dirname, "prasada.xml")) \
            .read().decode('utf-8')

        # We ask xsltproc not to put out a declaration and add our own.
        tidy = '<?xml version="1.0" encoding="UTF-8"?>' + \
            util.run_xsltproc(os.path.join(xml.xsl_dirname, "strip.xsl"),
                              data)
        editable = xml.storage_to_editable(tidy)
        final = xml.editable_to_storage(editable)

        # There's no way to test whether a generator is empty.
        failed = False
        for line in difflib.unified_diff(tidy.split('\n'), final.split('\n')):
            print line.encode('utf-8')
            failed = True

        self.assertFalse(failed)