当前位置: 首页>>代码示例>>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;未经允许,请勿转载。