Beispiel #1
0
def read_MEI(meitext):
    """Parse MEI file from text content using pymei / libmei."""
    try:
        parsed_mei = documentFromText(meitext)
    except ElementNotRegisteredException as ex:
        raise CannotReadMEIException(
            "The MEI File could not be read with this version of libmei. {0}".format(ex.message)
        )
    except FileReadFailureException as ex:
        raise CannotReadMEIException("The MEI File was malformed and could not be read. {0}".format(ex.message))
    except NoVersionFoundException as ex:
        raise CannotReadMEIException("The MEI File could not be read: MEI version not specified.")
    except:
        raise CannotReadMEIException("The MEI File could not be read for unknown reasons.")

    return parsed_mei
Beispiel #2
0
def read_MEI(meitext):
    """Parse MEI file from text content using pymei / libmei."""
    try:
        parsed_mei = documentFromText(meitext)
    except ElementNotRegisteredException as ex:
        raise CannotReadMEIException(
            "The MEI File could not be read with this version of libmei. {0}".
            format(ex.message))
    except FileReadFailureException as ex:
        raise CannotReadMEIException(
            "The MEI File was malformed and could not be read. {0}".format(
                ex.message))
    except NoVersionFoundException as ex:
        raise CannotReadMEIException(
            "The MEI File could not be read: MEI version not specified.")
    except:
        raise CannotReadMEIException(
            "The MEI File could not be read for unknown reasons.")

    return parsed_mei
Beispiel #3
0
    def test_setvalueandtail(self):
        xinput = "<mei xmlns=\"http://www.music-encoding.org/ns/mei\" xml:id=\"i\" meiversion=\"2012\"><note>noteinner</note>notetail<tie><p>pinner</p></tie>tietail</mei>"

        res = documentFromText(xinput)
        rootel = res.getMeiDocument().root

        self.assertEqual("mei", rootel.name)
        self.assertEqual(2, len(rootel.children))
        ch = rootel.children

        self.assertEqual("note", ch[0].name)
        self.assertEqual("noteinner", ch[0].value)
        self.assertEqual("notetail", ch[0].tail)

        self.assertEqual("tie", ch[1].name)
        self.assertEqual("", ch[1].value)
        self.assertEqual("tietail", ch[1].tail)

        self.assertEqual(1, len(ch[1].children))
        self.assertEqual("p", ch[1].children[0].name)
        self.assertEqual("pinner", ch[1].children[0].value)
        self.assertEqual("", ch[1].children[0].tail)
Beispiel #4
0
    def test_setvalueandtail(self):
        xinput = "<mei xmlns=\"http://www.music-encoding.org/ns/mei\" xml:id=\"i\" meiversion=\"2012\"><note>noteinner</note>notetail<tie><p>pinner</p></tie>tietail</mei>"

        res = documentFromText(xinput)
        rootel = res.getMeiDocument().root

        self.assertEqual("mei", rootel.name)
        self.assertEqual(2, len(rootel.children))
        ch = rootel.children

        self.assertEqual("note", ch[0].name)
        self.assertEqual("noteinner", ch[0].value)
        self.assertEqual("notetail", ch[0].tail)

        self.assertEqual("tie", ch[1].name)
        self.assertEqual("", ch[1].value)
        self.assertEqual("tietail", ch[1].tail)

        self.assertEqual(1, len(ch[1].children))
        self.assertEqual("p", ch[1].children[0].name)
        self.assertEqual("pinner", ch[1].children[0].value)
        self.assertEqual("", ch[1].children[0].tail)