def url(self): 're-assemble the git-url suitable for passing to git-clone' if self.scheme in ('http', 'https'): return hyperlink.URL(scheme=self.scheme, host=self.host, userinfo=self.userinfo, path=self.path).to_text() base = hyperlink.URL(scheme=self.scheme, host=self.host, userinfo=self.userinfo).to_text() if base.startswith('//'): # if scheme is '' base = base[2:] return base + u':' + u'/'.join(self.path)
def save_sdist(project, version, directory): project_url = hyperlink.URL( scheme='https', host='pypi.org', path=('pypi', project, version, 'json'), ) response = requests.get(project_url) response.raise_for_status() urls = response.json()['urls'] [record] = ( url for url in urls if url.get('packagetype') == 'sdist' ) url = hyperlink.URL.from_text(record['url']) directory.mkdir(parents=True, exist_ok=True) path = directory / url.path[-1] with path.open('wb') as file: get_down(file=file, url=url) return path
def __init__(self, host, port, url_defaults=None, session=None): """ :param host: The address for the host to connect to. :param port: The port for the host to connect to. :param dict url_defaults: Parameters to default to in the generated URLs, see `~hyperlink.URL`. :param session: A Requests' Session object (or something like it). """ if session is None: session = requests.Session() self._session = session _url_defaults = self.URL_DEFAULTS.copy() if url_defaults is not None: _url_defaults.update(url_defaults) self._base_url = hyperlink.URL( host=host, port=int(port), **_url_defaults)