예제 #1
0
 def _url_to_network_file(self, url_string: str) -> NetworkFile:
     url = urlparse(url_string)
     if url.scheme == "":
         return DiskTextFile(url.path)
     elif url.scheme == "file":
         return DiskTextFile(url.path)
     elif url.scheme == "http" or url.scheme == "https":
         return UrlTextFile(url.geturl(), StreamLogger.stdout_logger())
     elif url.scheme.startswith("git+"):
         return self._handle_git_override_url(url, url_string)
     else:
         raise UnsupportedUrlError("Cannot handle common overrides url %s" %
                                   url_string)
예제 #2
0
 def _handle_git_override_url(self, url: urllib.parse.ParseResult,
                              url_string: str) -> GitTextFile:
     if not url.fragment:
         raise UnsupportedUrlError((
             "Cannot handle overrides with no path given, offending url was"
             " {url}.").format(url=url_string))
     fragments: Dict[str, str] = dict()
     for fragment_item in url.fragment.split("&"):
         try:
             fragment_name, fragment_value = fragment_item.split()
         except ValueError:
             raise UnsupportedUrlError(
                 f"Encountered deformed URL fragment `{fragment_item}` "
                 f"in url `{url_string}`")
         else:
             fragments[fragment_name] = fragment_value
     return GitTextFile(
         repository_url=urldefrag(url.geturl()[4:])[0],
         path=fragments["path"],
         revision_name=fragments.get("rev", "master"),
         logger=StreamLogger.stdout_logger(),
     )