1919from musicbrainzngs import mbxml
2020from musicbrainzngs import util
2121from musicbrainzngs import compat
22+ from http .client import BadStatusLine , HTTPException
23+ from urllib .error import HTTPError , URLError
24+ from urllib .parse import urlencode , urlunparse
25+ from urllib .request import HTTPDigestAuthHandler , HTTPHandler , HTTPPasswordMgr , Request
2226
2327_version = "0.7.1"
2428_log = logging .getLogger ("musicbrainzngs" )
@@ -421,7 +425,7 @@ def __call__(self, *args, **kwargs):
421425 return self .fun (* args , ** kwargs )
422426
423427# From pymb2
424- class _RedirectPasswordMgr (compat . HTTPPasswordMgr ):
428+ class _RedirectPasswordMgr (HTTPPasswordMgr ):
425429 def __init__ (self ):
426430 self ._realms = { }
427431
@@ -436,13 +440,13 @@ def add_password(self, realm, uri, username, password):
436440 # ignoring the uri parameter intentionally
437441 self ._realms [realm ] = (username , password )
438442
439- class _DigestAuthHandler (compat . HTTPDigestAuthHandler ):
443+ class _DigestAuthHandler (HTTPDigestAuthHandler ):
440444 def get_authorization (self , req , chal ):
441445 qop = chal .get ('qop' , None )
442446 if qop and ',' in qop and 'auth' in qop .split (',' ):
443447 chal ['qop' ] = 'auth'
444448
445- return compat . HTTPDigestAuthHandler .get_authorization (self , req , chal )
449+ return HTTPDigestAuthHandler .get_authorization (self , req , chal )
446450
447451 def _encode_utf8 (self , msg ):
448452 """The MusicBrainz server also accepts UTF-8 encoded passwords."""
@@ -467,10 +471,10 @@ def get_algorithm_impls(self, algorithm):
467471 KD = lambda s , d : H ("%s:%s" % (s , d ))
468472 return H , KD
469473
470- class _MusicbrainzHttpRequest (compat . Request ):
474+ class _MusicbrainzHttpRequest (Request ):
471475 """ A custom request handler that allows DELETE and PUT"""
472476 def __init__ (self , method , url , data = None ):
473- compat . Request .__init__ (self , url , data )
477+ Request .__init__ (self , url , data )
474478 allowed_m = ["GET" , "POST" , "DELETE" , "PUT" ]
475479 if method not in allowed_m :
476480 raise ValueError ("invalid method: %s" % method )
@@ -501,7 +505,7 @@ def _safe_read(opener, req, body=None, max_retries=_max_retries, retry_delay_del
501505 f = opener .open (req )
502506 return f .read ()
503507
504- except compat . HTTPError as exc :
508+ except HTTPError as exc :
505509 if exc .code in (400 , 404 , 411 ):
506510 # Bad request, not found, etc.
507511 raise ResponseError (cause = exc )
@@ -515,13 +519,13 @@ def _safe_read(opener, req, body=None, max_retries=_max_retries, retry_delay_del
515519 # retrying for now.
516520 _log .info ("unknown HTTP error %i" % exc .code )
517521 last_exc = exc
518- except compat . BadStatusLine as exc :
522+ except BadStatusLine as exc :
519523 _log .info ("bad status line" )
520524 last_exc = exc
521- except compat . HTTPException as exc :
525+ except HTTPException as exc :
522526 _log .info ("miscellaneous HTTP exception: %s" % str (exc ))
523527 last_exc = exc
524- except compat . URLError as exc :
528+ except URLError as exc :
525529 if isinstance (exc .reason , socket .error ):
526530 code = exc .reason .errno
527531 if code == 104 : # "Connection reset by peer."
@@ -646,18 +650,18 @@ def _mb_request(path, method='GET', auth_required=AUTH_NO,
646650
647651 # Construct the full URL for the request, including hostname and
648652 # query string.
649- url = compat . urlunparse ((
653+ url = urlunparse ((
650654 'https' if https else 'http' ,
651655 hostname ,
652656 '/ws/2/%s' % path ,
653657 '' ,
654- compat . urlencode (newargs ),
658+ urlencode (newargs ),
655659 ''
656660 ))
657661 _log .debug ("%s request for %s" % (method , url ))
658662
659663 # Set up HTTP request handler and URL opener.
660- httpHandler = compat . HTTPHandler (debuglevel = 0 )
664+ httpHandler = HTTPHandler (debuglevel = 0 )
661665 handlers = [httpHandler ]
662666
663667 # Add credentials if required.
0 commit comments