Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_distribution_names(self):
return json.loads(
http_retrieve(self.opener,
compat.urljoin(self.url, 'api'))[0].data)
raise TooManyRedirects('Too many redirects')
# Params to be passed to request. The `preload_content` must be set to
# False, otherwise `read()` wont honor `decode_content`.
params = {
'headers': util.get_auth_info_from_url(url),
'preload_content': False,
'redirect': False,
}
# Request the url and ensure we've reached the final location
response = pool.request('GET', url, **params)
if 'location' in response.headers:
location = response.headers['location']
if location.startswith('/'):
url = compat.urljoin(url, location)
else:
url = location
return http_retrieve(pool, url, attempt=attempt + 1)
return response, url
def _get_project(self, name):
# It sounds lame, but we're trying to match requirements with more than
# one word separated with either `_` or `-`. Notice that we prefer
# hyphens cause there is currently way more packages using hyphens than
# underscores in pypi.p.o. Let's wait for the best here.
options = [name]
if '-' in name or '_' in name:
options = (name.replace('_', '-'), name.replace('-', '_'))
# Iterate over all the possible names a package can have.
for package_name in options:
url = compat.urljoin(self.base_url, '{0}/'.format(
compat.quote(package_name)))
found = self._fetch(url, package_name)
if found:
return found
def _get_project(self, name):
# Retrieve the info
url = compat.urljoin(self.url, 'api/' + name)
try:
response, _ = http_retrieve(self.opener, url)
except urllib3.exceptions.MaxRetryError:
return None
if response.status == 200:
data = json.loads(response.data)
return dict((v['version'], self._get_distribution(v)) for v in data)
else:
self.requirements_not_found.append(name)