Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def check_credentials(self):
"""
Check that ``username`` and ``password`` have been set, and raise an
exception if not.
"""
if self.username is None or self.password is None:
raise DistlibException('username and password must be set')
pm = HTTPPasswordMgr()
_, netloc, _, _, _, _ = urlparse(self.url)
pm.add_password(self.realm, netloc, self.username, self.password)
self.password_handler = HTTPBasicAuthHandler(pm)
def check_credentials(self):
"""
Check that ``username`` and ``password`` have been set, and raise an
exception if not.
"""
if self.username is None or self.password is None:
raise DistlibException('username and password must be set')
pm = HTTPPasswordMgr()
_, netloc, _, _, _, _ = urlparse(self.url)
pm.add_password(self.realm, netloc, self.username, self.password)
self.password_handler = HTTPBasicAuthHandler(pm)
def get_page(self, url):
# http://peak.telecommunity.com/DevCenter/EasyInstall#package-index-api
scheme, netloc, path, _, _, _ = compat.urlparse(url)
if scheme == 'file' and os.path.isdir(url2pathname(path)):
url = compat.urljoin(ensure_slash(url), 'index.html')
# The `retrieve()` method follows any eventual redirects, so the
# initial url might be different from the final one
try:
response, final_url = http_retrieve(self.opener, url)
except urllib3.exceptions.MaxRetryError:
return
content_type = response.headers.get('content-type', '')
if locators.HTML_CONTENT_TYPE.match(content_type):
data = response.data
encoding = response.headers.get('content-encoding')
if encoding:
decoder = self.decoders[encoding] # fail if not found
def update_url_credentials(self, base_url, other_url):
base = compat.urlparse(base_url)
other = compat.urlparse(other_url)
# If they're not from the same server, we return right away without
# trying to update anything
if base.hostname != other.hostname or base.password != other.password:
return other.geturl()
# Updating credentials only if the target URL doesn't have the data
# that we want to set
if base.username and not other.username:
other.username = base.username
if base.password and not other.password:
other.password = base.password
return other.geturl()
def update_url_credentials(self, base_url, other_url):
base = compat.urlparse(base_url)
other = compat.urlparse(other_url)
# If they're not from the same server, we return right away without
# trying to update anything
if base.hostname != other.hostname or base.password != other.password:
return other.geturl()
# Updating credentials only if the target URL doesn't have the data
# that we want to set
if base.username and not other.username:
other.username = base.username
if base.password and not other.password:
other.password = base.password
return other.geturl()