• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python mbxml.parse_message函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中musicbrainzngs.mbxml.parse_message函数的典型用法代码示例。如果您正苦于以下问题:Python parse_message函数的具体用法?Python parse_message怎么用?Python parse_message使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了parse_message函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: testTrackLength

    def testTrackLength(self):
        """
        Test that if there is a track length, then `track_or_recording_length` has
        that, but if not then fill the value from the recording length
        """
        fn = os.path.join(self.datadir, "b66ebe6d-a577-4af8-9a2e-a029b2147716-recordings.xml")
        res = mbxml.parse_message(open(fn))
        tracks = res["release"]["medium-list"][0]["track-list"]

        # No track length and recording length
        t1 = tracks[0]
        self.assertTrue("length" not in t1)
        self.assertEqual("180000", t1["recording"]["length"])
        self.assertEqual("180000", t1["track_or_recording_length"])

        # Track length and recording length same
        t2 = tracks[1]
        self.assertEqual("279000", t2["length"])
        self.assertEqual("279000", t2["recording"]["length"])
        self.assertEqual("279000", t2["track_or_recording_length"])

        # Track length and recording length different
        t3 = tracks[2]
        self.assertEqual("60000", t3["length"])
        self.assertEqual("80000", t3["recording"]["length"])
        self.assertEqual("60000", t3["track_or_recording_length"])

        # No track lengths
        t4 = tracks[3]
        self.assertTrue("length" not in t4["recording"])
        self.assertTrue("length" not in t4)
        self.assertTrue("track_or_recording_length" not in t4)
开发者ID:TestingCI,项目名称:python-musicbrainzngs,代码行数:32,代码来源:test_mbxml_release.py


示例2: testTypesExist

 def testTypesExist(self):
     fn = os.path.join(self.datadir,
                       "f52bc6a1-c848-49e6-85de-f8f53459a624.xml")
     res = mbxml.parse_message(open(fn))["release-group"]
     self.assertTrue("type" in res)
     self.assertTrue("primary-type" in res)
     self.assertTrue("secondary-type-list" in res)
开发者ID:TestingCI,项目名称:python-musicbrainzngs,代码行数:7,代码来源:test_mbxml_release_group.py


示例3: testFields

 def testFields(self):
     fn = os.path.join(os.path.dirname(__file__), "data", "search-recording.xml")
     res = mbxml.parse_message(open(fn))
     self.assertEqual(25, len(res["recording-list"]))
     self.assertEqual(1258, res["recording-count"])
     one = res["recording-list"][0]
     self.assertEqual("100", one["ext:score"])
开发者ID:ChrisNolan1992,项目名称:python-musicbrainzngs,代码行数:7,代码来源:test_mbxml_search.py


示例4: testTypesResult

 def testTypesResult(self):
     fn = os.path.join(self.datadir,
                       "f52bc6a1-c848-49e6-85de-f8f53459a624.xml")
     res = mbxml.parse_message(open(fn))["release-group"]
     self.assertEqual("Soundtrack", res["type"])
     self.assertEqual("Album", res["primary-type"])
     self.assertEqual(["Soundtrack"], res["secondary-type-list"])
开发者ID:TestingCI,项目名称:python-musicbrainzngs,代码行数:7,代码来源:test_mbxml_release_group.py


示例5: testFields

 def testFields(self):
     fn = os.path.join(os.path.dirname(__file__), "data", "search-label.xml")
     with open(fn) as msg:
         res = mbxml.parse_message(msg)
     self.assertEqual(1, len(res["label-list"]))
     self.assertEqual(1, res["label-count"])
     one = res["label-list"][0]
     self.assertEqual("100", one["ext:score"])
开发者ID:JonnyJD,项目名称:python-musicbrainzngs,代码行数:8,代码来源:test_mbxml_search.py


示例6: testFields

 def testFields(self):
     fn = os.path.join(DATA_DIR, "search-recording.xml")
     with open(fn, 'rb') as msg:
         res = mbxml.parse_message(msg)
     self.assertEqual(25, len(res["recording-list"]))
     self.assertEqual(1258, res["recording-count"])
     one = res["recording-list"][0]
     self.assertEqual("100", one["ext:score"])
开发者ID:alastair,项目名称:python-musicbrainzngs,代码行数:8,代码来源:test_mbxml_search.py


示例7: testFields

 def testFields(self):
     fn = os.path.join(DATA_DIR, "search-work.xml")
     with open(fn) as msg:
         res = mbxml.parse_message(msg)
     self.assertEqual(25, len(res["work-list"]))
     self.assertEqual(174, res["work-count"])
     one = res["work-list"][0]
     self.assertEqual("100", one["ext:score"])
开发者ID:EliotBerriot,项目名称:python-musicbrainzngs,代码行数:8,代码来源:test_mbxml_search.py


示例8: testTrackNumber

    def testTrackNumber(self):
        """
        Test that track number (number or text) and track position (always an increasing number)
        are both read properly
        """
        fn = os.path.join(self.datadir, "212895ca-ee36-439a-a824-d2620cd10461-recordings.xml")
        res = mbxml.parse_message(open(fn))
        tracks = res["release"]["medium-list"][0]["track-list"]
        # This release doesn't number intro tracks as numbered tracks,
        # so position and number get 'out of sync'
        self.assertEqual(['1', '2', '3'], [t["position"] for t in tracks[:3]])
        self.assertEqual(['', '1', '2'], [t["number"] for t in tracks[:3]])

        fn = os.path.join(self.datadir, "a81f3c15-2f36-47c7-9b0f-f684a8b0530f-recordings.xml")
        res = mbxml.parse_message(open(fn))
        tracks = res["release"]["medium-list"][0]["track-list"]
        self.assertEqual(['1', '2'], [t["position"] for t in tracks])
        self.assertEqual(['A', 'B'], [t["number"] for t in tracks])
开发者ID:TestingCI,项目名称:python-musicbrainzngs,代码行数:18,代码来源:test_mbxml_release.py


示例9: testFields

 def testFields(self):
     fn = os.path.join(os.path.dirname(__file__), "data", "search-artist.xml")
     res = mbxml.parse_message(open(fn))
     self.assertEqual(25, len(res["artist-list"]))
     one = res["artist-list"][0]
     self.assertEqual(9, len(one.keys()))
     # Score is a key that is only in search results -
     # so check for it here
     self.assertEqual("100", one["ext:score"])
开发者ID:krbaker,项目名称:python-musicbrainz-ngs,代码行数:9,代码来源:test_mbxml_search.py


示例10: testArtistAliases

    def testArtistAliases(self):
        fn = os.path.join(self.datadir, "0e43fe9d-c472-4b62-be9e-55f971a023e1-aliases.xml")
        res = mbxml.parse_message(open(fn))
        aliases = res["artist"]["alias-list"]
        self.assertEqual(len(aliases), 28)

        a0 = aliases[0]
        self.assertEqual(a0["alias"], "Prokofief")
        self.assertEqual(a0["sort-name"], "Prokofief")

        a17 = aliases[17]
        self.assertEqual(a17["alias"], "Sergei Sergeyevich Prokofiev")
        self.assertEqual(a17["sort-name"], "Prokofiev, Sergei Sergeyevich")
        self.assertEqual(a17["locale"], "en")
        self.assertEqual(a17["primary"], "primary")

        fn = os.path.join(self.datadir, "2736bad5-6280-4c8f-92c8-27a5e63bbab2-aliases.xml")
        res = mbxml.parse_message(open(fn))
        self.assertFalse("alias-list" in res["artist"])
开发者ID:sampsyo,项目名称:python-musicbrainz-ngs,代码行数:19,代码来源:test_mbxml_artist.py


示例11: mb_parser_xml

def mb_parser_xml(resp):
    """Return a Python dict representing the XML response"""
    # Parse the response.
    try:
        return mbxml.parse_message(resp)
    except UnicodeError as exc:
        raise ResponseError(cause=exc)
    except Exception as exc:
        if isinstance(exc, ETREE_EXCEPTIONS):
            raise ResponseError(cause=exc)
        else:
            raise
开发者ID:mojie126,项目名称:mythtv,代码行数:12,代码来源:musicbrainz.py


示例12: testWorkAliases

    def testWorkAliases(self):
        fn = os.path.join(self.datadir, "80737426-8ef3-3a9c-a3a6-9507afb93e93-aliases.xml")
        res = mbxml.parse_message(open(fn))
        aliases = res["work"]["alias-list"]
        self.assertEqual(len(aliases), 2)

        a0 = aliases[0]
        self.assertEqual(a0["alias"], 'Symphonie Nr. 3 Es-Dur, Op. 55 "Eroica"')
        self.assertEqual(a0["sort-name"], 'Symphonie Nr. 3 Es-Dur, Op. 55 "Eroica"')

        a1 = aliases[1]
        self.assertEqual(a1["alias"], 'Symphony No. 3, Op. 55 "Eroica"')
        self.assertEqual(a1["sort-name"], 'Symphony No. 3, Op. 55 "Eroica"')

        fn = os.path.join(self.datadir, "3d7c7cd2-da79-37f4-98b8-ccfb1a4ac6c4-aliases.xml")
        res = mbxml.parse_message(open(fn))
        aliases = res["work"]["alias-list"]
        self.assertEqual(len(aliases), 10)

        a0 = aliases[0]
        self.assertEqual(a0["alias"], "Adagio from Symphony No. 2 in E minor, Op. 27")
        self.assertEqual(a0["sort-name"], "Adagio from Symphony No. 2 in E minor, Op. 27")
开发者ID:TestingCI,项目名称:python-musicbrainzngs,代码行数:22,代码来源:test_mbxml_work.py


示例13: testArtistCredit

    def testArtistCredit(self):
        """
        If the artist credit is the same in the track and recording, make sure that
        the information is replicated in both objects, otherwise have distinct ones.
        """

        # If no artist-credit in the track, copy in the recording one
        fn = os.path.join(self.datadir, "833d4c3a-2635-4b7a-83c4-4e560588f23a-recordings+artist-credits.xml")
        res = mbxml.parse_message(open(fn))
        tracks = res["release"]["medium-list"][0]["track-list"]
        t1 = tracks[1]
        self.assertEqual(t1["artist-credit"], t1["recording"]["artist-credit"])
        self.assertEqual("JT Bruce", t1["artist-credit-phrase"])
        self.assertEqual(t1["recording"]["artist-credit-phrase"], t1["artist-credit-phrase"])

        # Recording AC is different to track AC
        fn = os.path.join(self.datadir, "fbe4490e-e366-4da2-a37a-82162d2f41a9-recordings+artist-credits.xml")
        res = mbxml.parse_message(open(fn))
        tracks = res["release"]["medium-list"][0]["track-list"]
        t1 = tracks[1]
        self.assertNotEqual(t1["artist-credit"], t1["recording"]["artist-credit"])
        self.assertEqual("H. Lichner", t1["artist-credit-phrase"])
        self.assertNotEqual(t1["recording"]["artist-credit-phrase"], t1["artist-credit-phrase"])
开发者ID:TestingCI,项目名称:python-musicbrainzngs,代码行数:23,代码来源:test_mbxml_release.py


示例14: testLabelAliases

    def testLabelAliases(self):
        fn = os.path.join(self.datadir, "022fe361-596c-43a0-8e22-bad712bb9548-aliases.xml")
        res = mbxml.parse_message(open(fn))
        aliases = res["label"]["alias-list"]
        self.assertEqual(len(aliases), 4)

        a0 = aliases[0]
        self.assertEqual(a0["alias"], "EMI")
        self.assertEqual(a0["sort-name"], "EMI")

        a1 = aliases[1]
        self.assertEqual(a1["alias"], "EMI Records (UK)")
        self.assertEqual(a1["sort-name"], "EMI Records (UK)")

        fn = os.path.join(self.datadir, "e72fabf2-74a3-4444-a9a5-316296cbfc8d-aliases.xml")
        res = mbxml.parse_message(open(fn))
        aliases = res["label"]["alias-list"]
        self.assertEqual(len(aliases), 1)

        a0 = aliases[0]
        self.assertEqual(a0["alias"], "Ki/oon Records Inc.")
        self.assertEqual(a0["sort-name"], "Ki/oon Records Inc.")
        self.assertEqual(a0["begin-date"], "2001-10")
        self.assertEqual(a0["end-date"], "2012-04")
开发者ID:sampsyo,项目名称:python-musicbrainz-ngs,代码行数:24,代码来源:test_mbxml_label.py


示例15: getMetaData

    def getMetaData(self, releaseId):
        """Load metadata from disk"""
        xmlPath = self._get_xml_path(releaseId)
        if (not os.path.isfile(xmlPath)):
            logging.error("No XML metadata for %s", releaseId)
            return None
        with open(xmlPath, 'r') as xmlf:
            metaxml = xmlf.read()

        try:
            metadata = mbxml.parse_message(metaxml)
        except UnicodeError as exc:
            raise ResponseError(cause=exc)
        except Exception as exc:
            if isinstance(exc, ETREE_EXCEPTIONS):
                logging.error("Got some bad XML for %s!", releaseId)
                return 
            else:
                raise

        return metadata
开发者ID:JonnyJD,项目名称:musicbrainz-catalog,代码行数:21,代码来源:catalog.py


示例16: _mb_request

def _mb_request(path, method='GET', auth_required=False, client_required=False,
				args=None, data=None, body=None):
	"""Makes a request for the specified `path` (endpoint) on /ws/2 on
	the globally-specified hostname. Parses the responses and returns
	the resulting object.  `auth_required` and `client_required` control
	whether exceptions should be raised if the client and
	username/password are left unspecified, respectively.
	"""
	if args is None:
		args = {}
	else:
		args = dict(args) or {}

	if _useragent == "":
		raise UsageError("set a proper user-agent with "
						 "set_useragent(\"application name\", \"application version\", \"contact info (preferably URL or email for your application)\")")

	if client_required:
		args["client"] = _client

	# Encode Unicode arguments using UTF-8.
	for key, value in args.items():
		if isinstance(value, compat.unicode):
			args[key] = value.encode('utf8')

	# Construct the full URL for the request, including hostname and
	# query string.
	url = compat.urlunparse((
		'http',
		hostname,
		'/ws/2/%s' % path,
		'',
		compat.urlencode(args),
		''
	))
	_log.debug("%s request for %s" % (method, url))

	# Set up HTTP request handler and URL opener.
	httpHandler = compat.HTTPHandler(debuglevel=0)
	handlers = [httpHandler]

	# Add credentials if required.
	if auth_required:
		_log.debug("Auth required for %s" % url)
		if not user:
			raise UsageError("authorization required; "
							 "use auth(user, pass) first")
		passwordMgr = _RedirectPasswordMgr()
		authHandler = _DigestAuthHandler(passwordMgr)
		authHandler.add_password("musicbrainz.org", (), user, password)
		handlers.append(authHandler)

	opener = compat.build_opener(*handlers)

	# Make request.
	req = _MusicbrainzHttpRequest(method, url, data)
	req.add_header('User-Agent', _useragent)
	_log.debug("requesting with UA %s" % _useragent)
	if body:
		req.add_header('Content-Type', 'application/xml; charset=UTF-8')
	elif not data and not req.has_header('Content-Length'):
		# Explicitly indicate zero content length if no request data
		# will be sent (avoids HTTP 411 error).
		req.add_header('Content-Length', '0')
	resp = _safe_read(opener, req, body)

	# Parse the response.
	try:
		return mbxml.parse_message(resp)
	except UnicodeError as exc:
		raise ResponseError(cause=exc)
	except Exception as exc:
		if isinstance(exc, ETREE_EXCEPTIONS):
			raise ResponseError(cause=exc)
		else:
			raise
开发者ID:phw,项目名称:python-musicbrainz-ngs,代码行数:76,代码来源:musicbrainz.py


示例17: len

            'releases list)')

    con.commit()

    fileList = os.listdir(rootPath)
    widgets = ["Releases: ", progressbar.Bar(marker="=", left="[", right="]"), " ", progressbar.Percentage() ]
    if len(fileList):
        pbar = progressbar.ProgressBar(widgets=widgets, maxval=len(fileList)).start()
    for relId in fileList:
        metaPath = os.path.join(rootPath, relId, 'metadata.xml')
        #with codecs.open(metaPath, encoding='utf-8') as f:
        with open(metaPath, 'r') as f:
            metaXml = f.read()

        try:
            metadata = mbxml.parse_message(metaXml)['release']
        except UnicodeError as exc:
            raise mb.ResponseError(cause=exc)
        except Exception as exc:
            if isinstance(exc, ETREE_EXCEPTIONS):
                logging.error("Got some bad XML for %s!", releaseId)
            else:
                raise

        ed = mbcat.extradata.ExtraData(relId)
        try:
            ed.load()
        except IOError as e:
            ed = None

        cur.execute('insert into releases(id, meta, sortstring, metatime, purchases, added, lent, listened, digital, count, comment, rating) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
开发者ID:rlhelinski,项目名称:musicbrainz-catalog,代码行数:31,代码来源:mbcat-sql-upgrade.py


示例18: parse_response_body

 def parse_response_body(self, body):
     return mbxml.parse_message(BytesIO(body))
开发者ID:0xcd03,项目名称:cloudtunes,代码行数:2,代码来源:client.py


示例19: _mb_request

def _mb_request(path, method='GET', auth_required=False, client_required=False,
				args=None, data=None, body=None):
	"""Makes a request for the specified `path` (endpoint) on /ws/2 on
	the globally-specified hostname. Parses the responses and returns
	the resulting object.  `auth_required` and `client_required` control
	whether exceptions should be raised if the client and
	username/password are left unspecified, respectively.
	"""
	if args is None:
		args = {}
	else:
		args = dict(args) or {}

	if _useragent == "":
		raise UsageError("set a proper user-agent with "
						 "set_useragent(\"application name\", \"application version\", \"contact info (preferably URL or email for your application)\")")

	if client_required:
		args["client"] = _client

	headers = {}
	if body:
		headers['Content-Type'] = 'application/xml; charset=UTF-8'
	else:
		# Explicitly indicate zero content length if no request data
		# will be sent (avoids HTTP 411 error).
		headers['Content-Length'] = '0'

	req = requests.Request(
		method,
		'http://{0}/ws/2/{1}'.format(hostname, path),
		params=args,
		auth=HTTPDigestAuth(user, password) if auth_required else None,
		headers=headers,
		data=body,
	)

	# Make request (with retries).
	session = requests.Session()
	adapter = requests.adapters.HTTPAdapter(max_retries=8)
	session.mount('http://', adapter)
	session.mount('https://', adapter)
	try:
		resp = session.send(req.prepare(), allow_redirects=True)
	except requests.RequestException as exc:
		raise NetworkError(cause=exc)
	if resp.status_code != 200:
		raise ResponseError(
			'API responded with code {0}'.format(resp.status_code)
		)

	# Parse the response.
	try:
		return mbxml.parse_message(resp.content)
	except UnicodeError as exc:
		raise ResponseError(cause=exc)
	except Exception as exc:
		if isinstance(exc, ETREE_EXCEPTIONS):
			raise ResponseError(cause=exc)
		else:
			raise
开发者ID:sampsyo,项目名称:python-musicbrainz-ngs,代码行数:61,代码来源:musicbrainz.py


示例20: digestXml

 def digestXml(self, releaseId, meta_xml):
     self.digestMetaDict(releaseId, mbxml.parse_message(meta_xml))
开发者ID:JonnyJD,项目名称:musicbrainz-catalog,代码行数:2,代码来源:catalog.py



注:本文中的musicbrainzngs.mbxml.parse_message函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python locks.authority_of函数代码示例发布时间:2022-05-27
下一篇:
Python musicbrainzngs.set_useragent函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap