本文整理汇总了Python中pymei.XmlImport.documentFromText方法的典型用法代码示例。如果您正苦于以下问题:Python XmlImport.documentFromText方法的具体用法?Python XmlImport.documentFromText怎么用?Python XmlImport.documentFromText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymei.XmlImport
的用法示例。
在下文中一共展示了XmlImport.documentFromText方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from pymei import XmlImport [as 别名]
# 或者: from pymei.XmlImport import documentFromText [as 别名]
def post(self):
mei = self.request.files.get("mei", [])
mei_img = self.request.files.get("mei_img", [])
document_type = self.get_argument("document_type")
mei_root_directory = os.path.abspath(conf.MEI_DIRECTORY)
mei_directory = os.path.join(mei_root_directory, document_type)
mei_directory_backup = os.path.join(mei_directory, "backup")
errors = ""
mei_fn = ""
if len(mei):
mei_fn = mei[0]["filename"]
contents = mei[0]["body"]
try:
mei = XmlImport.documentFromText(contents)
if os.path.exists(os.path.join(mei_directory, mei_fn)):
errors = "mei file already exists"
else:
# write to working directory and backup
fp = open(os.path.join(mei_directory, mei_fn), "w")
fp.write(contents)
fp.close()
fp = open(os.path.join(mei_directory_backup, mei_fn), "w")
fp.write(contents)
fp.close()
except Exception, e:
errors = "invalid mei file"
示例2: post
# 需要导入模块: from pymei import XmlImport [as 别名]
# 或者: from pymei.XmlImport import documentFromText [as 别名]
def post(self, request):
mei = self.request.files.get("mei", [])
mei_img = self.request.files.get("mei_img", [])
document_type = "squarenote"
mei_root_directory = os.path.abspath(conf.MEI_DIRECTORY)
mei_directory = os.path.join(mei_root_directory, document_type)
mei_directory_backup = os.path.join(mei_root_directory, "backup")
errors = ""
mei_fn = ""
if len(mei):
mei_fn = mei[0]["filename"]
mei_fn_split = os.path.splitext(mei_fn)
mei_zero, mei_ext = mei_fn_split
contents = mei[0]["body"]
# TODO: Figure out how to validate MEI files properly using pymei
try:
mei = XmlImport.documentFromText(contents)
# if not mei_fn.endswith('.mei'):
# errors = "not in mei file format"
if os.path.exists(os.path.join(mei_directory, mei_fn)):
errors = "mei file already exists"
else:
# write to working directory and backup
fp = open(os.path.join(mei_directory, mei_fn), "w")
fp.write(contents)
fp.close()
fp = open(os.path.join(mei_directory_backup, mei_fn), "w")
fp.write(contents)
fp.close()
except Exception, e:
errors = "invalid mei file"
示例3: parse_str
# 需要导入模块: from pymei import XmlImport [as 别名]
# 或者: from pymei.XmlImport import documentFromText [as 别名]
def parse_str(self, mei_str):
'''
Read an mei file from string and fill the score model
'''
from pymei import XmlImport
self.doc = XmlImport.documentFromText(mei_str)
self.parse_input()
示例4: sanitize_mei_str
# 需要导入模块: from pymei import XmlImport [as 别名]
# 或者: from pymei.XmlImport import documentFromText [as 别名]
def sanitize_mei_str(self, mei_str, output_mei_path=None, prune=True):
self.mei_doc = XmlImport.documentFromText(mei_str)
self._sanitize_mei(prune)
if output_mei_path:
XmlExport.meiDocumentToFile(self.mei_doc, str(output_mei_path))
else:
return XmlExport.meiDocumentToText(self.mei_doc)
示例5: test_setvalueandtail
# 需要导入模块: from pymei import XmlImport [as 别名]
# 或者: from pymei.XmlImport import documentFromText [as 别名]
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>"
doc = XmlImport.documentFromText(xinput)
rootel = doc.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)