本文整理匯總了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)