1818
1919from musicbrainzngs import mbxml
2020from musicbrainzngs import util
21- from musicbrainzngs import compat
21+ from urllib .parse import urlencode , urlunparse
22+ from urllib .request import HTTPDigestAuthHandler , HTTPHandler , HTTPPasswordMgr , Request , build_opener
2223
2324_version = "0.7.1"
2425_log = logging .getLogger ("musicbrainzngs" )
@@ -421,7 +422,7 @@ def __call__(self, *args, **kwargs):
421422 return self .fun (* args , ** kwargs )
422423
423424# From pymb2
424- class _RedirectPasswordMgr (compat . HTTPPasswordMgr ):
425+ class _RedirectPasswordMgr (HTTPPasswordMgr ):
425426 def __init__ (self ):
426427 self ._realms = { }
427428
@@ -436,13 +437,13 @@ def add_password(self, realm, uri, username, password):
436437 # ignoring the uri parameter intentionally
437438 self ._realms [realm ] = (username , password )
438439
439- class _DigestAuthHandler (compat . HTTPDigestAuthHandler ):
440+ class _DigestAuthHandler (HTTPDigestAuthHandler ):
440441 def get_authorization (self , req , chal ):
441442 qop = chal .get ('qop' , None )
442443 if qop and ',' in qop and 'auth' in qop .split (',' ):
443444 chal ['qop' ] = 'auth'
444445
445- return compat . HTTPDigestAuthHandler .get_authorization (self , req , chal )
446+ return HTTPDigestAuthHandler .get_authorization (self , req , chal )
446447
447448 def _encode_utf8 (self , msg ):
448449 """The MusicBrainz server also accepts UTF-8 encoded passwords."""
@@ -467,10 +468,10 @@ def get_algorithm_impls(self, algorithm):
467468 KD = lambda s , d : H ("%s:%s" % (s , d ))
468469 return H , KD
469470
470- class _MusicbrainzHttpRequest (compat . Request ):
471+ class _MusicbrainzHttpRequest (Request ):
471472 """ A custom request handler that allows DELETE and PUT"""
472473 def __init__ (self , method , url , data = None ):
473- compat . Request .__init__ (self , url , data )
474+ Request .__init__ (self , url , data )
474475 allowed_m = ["GET" , "POST" , "DELETE" , "PUT" ]
475476 if method not in allowed_m :
476477 raise ValueError ("invalid method: %s" % method )
@@ -501,7 +502,7 @@ def _safe_read(opener, req, body=None, max_retries=_max_retries, retry_delay_del
501502 f = opener .open (req )
502503 return f .read ()
503504
504- except compat . HTTPError as exc :
505+ except HTTPError as exc :
505506 if exc .code in (400 , 404 , 411 ):
506507 # Bad request, not found, etc.
507508 raise ResponseError (cause = exc )
@@ -515,13 +516,13 @@ def _safe_read(opener, req, body=None, max_retries=_max_retries, retry_delay_del
515516 # retrying for now.
516517 _log .info ("unknown HTTP error %i" % exc .code )
517518 last_exc = exc
518- except compat . BadStatusLine as exc :
519+ except BadStatusLine as exc :
519520 _log .info ("bad status line" )
520521 last_exc = exc
521- except compat . HTTPException as exc :
522+ except HTTPException as exc :
522523 _log .info ("miscellaneous HTTP exception: %s" % str (exc ))
523524 last_exc = exc
524- except compat . URLError as exc :
525+ except URLError as exc :
525526 if isinstance (exc .reason , socket .error ):
526527 code = exc .reason .errno
527528 if code == 104 : # "Connection reset by peer."
@@ -646,18 +647,18 @@ def _mb_request(path, method='GET', auth_required=AUTH_NO,
646647
647648 # Construct the full URL for the request, including hostname and
648649 # query string.
649- url = compat . urlunparse ((
650+ url = urlunparse ((
650651 'https' if https else 'http' ,
651652 hostname ,
652653 '/ws/2/%s' % path ,
653654 '' ,
654- compat . urlencode (newargs ),
655+ urlencode (newargs ),
655656 ''
656657 ))
657658 _log .debug ("%s request for %s" % (method , url ))
658659
659660 # Set up HTTP request handler and URL opener.
660- httpHandler = compat . HTTPHandler (debuglevel = 0 )
661+ httpHandler = HTTPHandler (debuglevel = 0 )
661662 handlers = [httpHandler ]
662663
663664 # Add credentials if required.
@@ -679,7 +680,7 @@ def _mb_request(path, method='GET', auth_required=AUTH_NO,
679680 authHandler .add_password ("musicbrainz.org" , (), user , password )
680681 handlers .append (authHandler )
681682
682- opener = compat . build_opener (* handlers )
683+ opener = build_opener (* handlers )
683684
684685 # Make request.
685686 req = _MusicbrainzHttpRequest (method , url , data )
0 commit comments