我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用pip.download.PipSession()。
def _build_session(self, options): session = PipSession() # Handle custom ca-bundles from the user if options.cert: session.verify = options.cert # Handle timeouts if options.timeout: session.timeout = options.timeout # Handle configured proxies if options.proxy: session.proxies = { "http": options.proxy, "https": options.proxy, } # Determine if we can prompt the user for authentication or not session.auth.prompting = not options.no_input return session
def _build_session(self, options, retries=None, timeout=None): session = PipSession( cache=( normalize_path(os.path.join(options.cache_dir, "http")) if options.cache_dir else None ), retries=retries if retries is not None else options.retries, insecure_hosts=options.trusted_hosts, ) # Handle custom ca-bundles from the user if options.cert: session.verify = options.cert # Handle SSL client certificate if options.client_cert: session.cert = options.client_cert # Handle timeouts if options.timeout or timeout: session.timeout = ( timeout if timeout is not None else options.timeout ) # Handle configured proxies if options.proxy: session.proxies = { "http": options.proxy, "https": options.proxy, } # Determine if we can prompt the user for authentication or not session.auth.prompting = not options.no_input return session
def reqs(path): return [str(r.req) for r in parse_requirements(path, session=PipSession())]
def _get_content_type(url, session=None): """Get the Content-Type of the given url, using a HEAD request""" if session is None: session = PipSession() scheme, netloc, path, query, fragment = urlparse.urlsplit(url) if not scheme in ('http', 'https', 'ftp', 'ftps'): ## FIXME: some warning or something? ## assertion error? return '' resp = session.head(url, allow_redirects=True) resp.raise_for_status() return resp.headers.get("Content-Type", "")
def read_requirements(): # parses requirements from requirements.txt reqs_path = os.path.join(__location__, 'requirements.txt') install_reqs = parse_requirements(reqs_path, session=PipSession()) reqs = [str(ir.req) for ir in install_reqs] return reqs
def parse_requirements(f): return [str(r.req) for r in requirements(f, session=PipSession())] # Read requirements
def extract_requirements(filename): return [str(r.req) for r in parse_requirements(filename, session=PipSession)]