@@ -815,16 +815,17 @@ def add_password(self, realm, uri, user, passwd):
815815 self .passwd [realm ] = {}
816816 for default_port in True , False :
817817 reduced_uri = tuple (
818- self .reduce_uri (u , default_port ) for u in uri )
818+ self ._reduce_uri_with_scheme (u , default_port ) for u in uri )
819819 self .passwd [realm ][reduced_uri ] = (user , passwd )
820820
821821 def find_user_password (self , realm , authuri ):
822822 domains = self .passwd .get (realm , {})
823823 for default_port in True , False :
824- reduced_authuri = self .reduce_uri (authuri , default_port )
824+ reduced_authuri = self ._reduce_uri_with_scheme (
825+ authuri , default_port )
825826 for uris , authinfo in domains .items ():
826827 for uri in uris :
827- if self .is_suburi (uri , reduced_authuri ):
828+ if self ._is_suburi_with_scheme (uri , reduced_authuri ):
828829 return authinfo
829830 return None , None
830831
@@ -851,6 +852,17 @@ def reduce_uri(self, uri, default_port=True):
851852 authority = "%s:%d" % (host , dport )
852853 return authority , path
853854
855+ def _reduce_uri_with_scheme (self , uri , default_port = True ):
856+ parts = urlsplit (uri )
857+ scheme = parts [0 ] if parts [1 ] else None
858+ return (scheme or None , * self .reduce_uri (uri , default_port ))
859+
860+ def _is_suburi_with_scheme (self , base , test ):
861+ if (base [0 ] is not None and test [0 ] is not None and
862+ base [0 ] != test [0 ]):
863+ return False
864+ return self .is_suburi (base [1 :], test [1 :])
865+
854866 def is_suburi (self , base , test ):
855867 """Check if test is below base in a URI tree
856868
@@ -896,14 +908,15 @@ def update_authenticated(self, uri, is_authenticated=False):
896908
897909 for default_port in True , False :
898910 for u in uri :
899- reduced_uri = self .reduce_uri (u , default_port )
911+ reduced_uri = self ._reduce_uri_with_scheme (u , default_port )
900912 self .authenticated [reduced_uri ] = is_authenticated
901913
902914 def is_authenticated (self , authuri ):
903915 for default_port in True , False :
904- reduced_authuri = self .reduce_uri (authuri , default_port )
916+ reduced_authuri = self ._reduce_uri_with_scheme (
917+ authuri , default_port )
905918 for uri in self .authenticated :
906- if self .is_suburi (uri , reduced_authuri ):
919+ if self ._is_suburi_with_scheme (uri , reduced_authuri ):
907920 return self .authenticated [uri ]
908921
909922
0 commit comments