當前位置: 首頁>>代碼示例>>Python>>正文


Python XmlImport.documentFromText方法代碼示例

本文整理匯總了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"
開發者ID:avorio,項目名稱:Neon.js,代碼行數:28,代碼來源:interface.py

示例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"
開發者ID:DDMAL,項目名稱:Neon.js,代碼行數:34,代碼來源:interface.py

示例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()
開發者ID:srviest,項目名稱:astar-guitar,代碼行數:10,代碼來源:score.py

示例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)
開發者ID:gburlet,項目名稱:robotaba,代碼行數:10,代碼來源:guitarify.py

示例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)
開發者ID:lpugin,項目名稱:libmei,代碼行數:24,代碼來源:xmlimport_test.py


注:本文中的pymei.XmlImport.documentFromText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。