def address(meipath, measures, staves, beats, completeness=None): mei_as_text = get_external_mei(meipath) # If an MEI file is request in full (all/all/@all), just return it if measures == "all" and staves == "all" and beats == "@all": # this will write it to a temporary directory automatically tdir = tempfile.mkdtemp() fname = "full.mei" filename = os.path.join(tdir, fname) try: file = open(filename, 'w') file.write(mei_as_text) file.close() except CannotWriteMEIException as ex: return ( {"message": ex.message}, status.HTTP_500_INTERNAL_SERVER_ERROR ) return send_file(filename, as_attachment=True, mimetype="application/xml") try: parsed_mei = meiinfo.read_MEI(mei_as_text).getMeiDocument() except CannotReadMEIException as ex: return {"message": ex.message}, status.HTTP_500_INTERNAL_SERVER_ERROR try: mei_slicer = meislicer.MeiSlicer( parsed_mei, measures, staves, beats, completeness ) mei_slice = mei_slicer.slice() except BadApiRequest as ex: return {"message": ex.message}, status.HTTP_400_BAD_REQUEST except UnsupportedEncoding as ex: return {"message": ex.message}, status.HTTP_500_INTERNAL_SERVER_ERROR if completeness == "compile": return mei_slicer.compiled_exp else: # this will write it to a temporary directory automatically try: filename = meiinfo.write_MEI(mei_slice) except CannotWriteMEIException as ex: return ( {"message": ex.message}, status.HTTP_500_INTERNAL_SERVER_ERROR ) return send_file(filename, as_attachment=True, mimetype="application/xml")
def information(meipath): try: mei_as_text = get_external_mei(meipath) except CannotAccessRemoteMEIException as ex: return {"message": ex.message}, status.HTTP_400_BAD_REQUEST except UnknownMEIReadException as ex: return {"message": ex.message}, status.HTTP_500_INTERNAL_SERVER_ERROR try: parsed_mei = meiinfo.read_MEI(mei_as_text).getMeiDocument() except CannotReadMEIException as ex: # return a 500 server error with the exception message return {"message": ex.message}, status.HTTP_500_INTERNAL_SERVER_ERROR # it's possible that this will raise some exceptions too, so break it out. try: mus_doc_info = meiinfo.MusDocInfo(parsed_mei).get() except BadApiRequest as ex: return {"message": ex.message}, status.HTTP_500_INTERNAL_SERVER_ERROR return mus_doc_info
def setUp(self): url = "http://music-encoding.org/sampleCollection/encodings/attribute_syl.xml" r = requests.get(unquote(url), timeout=15) self.meidoc = meiinfo.read_MEI(r.content).getMeiDocument()
def setUp(self): r = requests.get(unquote(TEST_MEI_URL), timeout=15) self.meidoc = meiinfo.read_MEI(r.content).getMeiDocument()