def resolve( self, line, # type: LogicalLine origin, # type: str is_constraints=False, # type: bool fetcher=None, # type: Optional[URLFetcher] ): # type: (...) -> Iterator[Source] def create_parse_error(msg): # type: (str) -> ParseError return ParseError( line, "Problem resolving {} file: {}".format( "constraints" if is_constraints else "requirements", msg), ) url = urlparse.urlparse(urlparse.urljoin(self.origin, origin)) if url.scheme and url.netloc: if fetcher is None: raise create_parse_error( "The source is a url but no fetcher was supplied to resolve its contents with." ) try: with self.from_url(fetcher, origin) as source: yield source except OSError as e: raise create_parse_error(str(e)) return path = url.path if url.scheme == "file" else origin try: with self.from_file(path, is_constraints=is_constraints) as source: yield source except (IOError, OSError) as e: raise create_parse_error(str(e))
def join(self, href): """Given a href relative to this link, return the :class:`Link` of the absolute url. :param href: A string-like path relative to this link. """ return self.wrap(urlparse.urljoin(self.url, href))
def _normalize(cls, filename): return urlparse.urljoin('file:', pathname2url( os.path.realpath(os.path.expanduser(filename))))
def _normalize(cls, filename): return urlparse.urljoin( 'file:', pathname2url(os.path.realpath(os.path.expanduser(filename))))