code: def test_url_samples():
      _check_ri(
          "http://example.com",
          URL,
          scheme="http",
          hostname="example.com",
          netloc="example.com",
      )
      # "complete" one for classical http
      _check_ri(
          "http://user:pw@example.com:8080/p/sp?p1=v1&p2=v2#frag",
          URL,
          scheme="http",
          netloc="user:pw@example.com:8080",
          hostname="example.com",
          port=8080,
          username="user",
          password="pw",
          path="/p/sp",
          query="p1=v1&p2=v2",
          fragment="frag",
      )
  
      # sample one for ssh with specifying the scheme
      # XXX? might be useful?  https://github.com/FriendCode/giturlparse.py
      _check_ri(
          "ssh://host/path/sp1",
          URL,
          scheme="ssh",
          hostname="host",
          netloc="host",
          path="/path/sp1",
      )
      _check_ri(
          "user@host:path/sp1",
          SSHRI,
          hostname="host",
          path="path/sp1",
          username="user",
      )
      _check_ri(
          "host:path/sp1", SSHRI, hostname="host", path="path/sp1"
      )
      _check_ri("host:path", SSHRI, hostname="host", path="path")
      _check_ri("host:/path", SSHRI, hostname="host", path="/path")
      _check_ri("user@host", SSHRI, hostname="host", username="user")
      # TODO!!!  should this be a legit URL like this?
      # _check_ri("host", SSHRI, hostname='host'))
      eq_(repr(RI("host:path")), "SSHRI(hostname='host', path='path')")
  
      # And now perspective 'datalad', implicit=True urls pointing to the canonical center location
      _check_ri("///", DataLadRI)
      _check_ri("///p/s1", DataLadRI, path="p/s1")
      # could be considered by someone as "URI reference" relative to scheme
      _check_ri("//a/", DataLadRI, remote="a")
      _check_ri("//a/data", DataLadRI, path="data", remote="a")
  
      # here we will do custom magic allowing only schemes with + in them, such as dl+archive
      # or not so custom as
      _check_ri(
          "hg+https://host/user/proj",
          URL,
          scheme="hg+https",
          netloc="host",
          hostname="host",
          path="/user/proj",
      )
      # "old" style
      _check_ri(
          "dl+archive:KEY/path/sp1#size=123",
          URL,
          scheme="dl+archive",
          path="KEY/path/sp1",
          fragment="size=123",
      )
      # "new" style
      _check_ri(
          "dl+archive:KEY#path=path/sp1&size=123",
          URL,
          scheme="dl+archive",
          path="KEY",
          fragment="path=path/sp1&size=123",
      )
      # actually above one is probably wrong since we need to encode the path
      _check_ri(
          "dl+archive:KEY#path=path%2Fbsp1&size=123",
          URL,
          scheme="dl+archive",
          path="KEY",
          fragment="path=path%2Fbsp1&size=123",
      )
  
      # https://en.wikipedia.org/wiki/File_URI_scheme
      _check_ri(
          "file://host",
          URL,
          scheme="file",
          netloc="host",
          hostname="host",
      )
      _check_ri(
          "file://host/path/sp1",
          URL,
          scheme="file",
          netloc="host",
          hostname="host",
          path="/path/sp1",
      )
      # stock libraries of Python aren't quite ready for ipv6
      ipv6address = "2001:db8:85a3::8a2e:370:7334"
      _check_ri(
          "file://%s/path/sp1" % ipv6address,
          URL,
          scheme="file",
          netloc=ipv6address,
          hostname=ipv6address,
          path="/path/sp1",
      )
      for lh in ("localhost", "::1", "", "127.3.4.155"):
          if on_windows:
              url = RI(f"file://{lh}/path/sp1")
              assert (
                  url.localpath == f"\\\\{lh}\\path\\sp1"
                  if lh
                  else "\\path\\sp1"
              )
          else:
              _check_ri(
                  "file://%s/path/sp1" % lh,
                  URL,
                  localpath="/path/sp1",
                  scheme="file",
                  netloc=lh,
                  hostname=lh,
                  path="/path/sp1",
              )
  
      _check_ri(
          "http://[1fff:0:a88:85a3::ac1f]:8001/index.html",
          URL,
          scheme="http",
          netloc="[1fff:0:a88:85a3::ac1f]:8001",
          hostname="1fff:0:a88:85a3::ac1f",
          port=8001,
          path="/index.html",
      )
      _check_ri(
          "file:///path/sp1",
          URL,
          localpath="/path/sp1",
          scheme="file",
          path="/path/sp1",
      )
      # we don't do any magical comprehension for home paths/drives for windows
      # of file:// urls, thus leaving /~ and /c: for now:
      _check_ri(
          "file:///~/path/sp1",
          URL,
          localpath="/~/path/sp1",
          scheme="file",
          path="/~/path/sp1",
      )
      _check_ri(
          "file:///%7E/path/sp1",
          URL,
          localpath="/~/path/sp1",
          scheme="file",
          path="/~/path/sp1",
          exact_str=False,
      )
      # not sure but let's check
      if on_windows:
          _check_ri(
              "file:///C:/path/sp1",
              URL,
              localpath="C:/path/sp1",
              scheme="file",
              path="/C:/path/sp1",
              exact_str=False,
          )
          _check_ri(
              "file:/C:/path/sp1",
              URL,
              localpath="C:/path/sp1",
              scheme="file",
              path="/C:/path/sp1",
              exact_str=False,
          )
          # git-annex style drive-letter encoding
          _check_ri(
              "file://C:/path/sp1",
              URL,
              netloc="C:",
              hostname="c",
              localpath="C:/path/sp1",
              scheme="file",
              path="/path/sp1",
              exact_str=False,
          )
      else:
          _check_ri(
              "file:///C:/path/sp1",
              URL,
              localpath="/C:/path/sp1",
              scheme="file",
              path="/C:/path/sp1",
              exact_str=False,
          )
          _check_ri(
              "file:/C:/path/sp1",
              URL,
              localpath="/C:/path/sp1",
              scheme="file",
              path="/C:/path/sp1",
              exact_str=False,
          )
  
      # and now implicit paths or actually they are also "URI references"
      _check_ri("f", PathRI, localpath="f", path="f")
      _check_ri("f/s1", PathRI, localpath="f/s1", path="f/s1")
      _check_ri(PurePosixPath("f"), PathRI, localpath="f", path="f")
      _check_ri(
          PurePosixPath("f/s1"), PathRI, localpath="f/s1", path="f/s1"
      )
      # colons are problematic and might cause confusion into SSHRI
      _check_ri("f/s:1", PathRI, localpath="f/s:1", path="f/s:1")
      _check_ri("f/s:", PathRI, localpath="f/s:", path="f/s:")
      _check_ri("/f", PathRI, localpath="/f", path="/f")
      _check_ri("/f/s1", PathRI, localpath="/f/s1", path="/f/s1")
  
      # some github ones, just to make sure
      _check_ri(
          "git://host/user/proj",
          URL,
          scheme="git",
          netloc="host",
          hostname="host",
          path="/user/proj",
      )
      _check_ri(
          "git@host:user/proj",
          SSHRI,
          hostname="host",
          path="user/proj",
          username="git",
      )
  
      _check_ri("weird:/", SSHRI, hostname="weird", path="/")
      # since schema is not allowing some symbols so we need to add additional check
      _check_ri("weird_url:/", SSHRI, hostname="weird_url", path="/")
      _check_ri(
          "example.com:/", SSHRI, hostname="example.com", path="/"
      )
      _check_ri(
          "example.com:path/sp1",
          SSHRI,
          hostname="example.com",
          path="path/sp1",
      )
      _check_ri(
          "example.com/path/sp1\\:fname",
          PathRI,
          localpath="example.com/path/sp1\\:fname",
          path="example.com/path/sp1\\:fname",
      )
      # ssh is as stupid as us, so we will stay "Consistently" dumb
      """
      $> ssh example.com/path/sp1:fname
      ssh: Could not resolve hostname example.com/path/sp1:fname: Name or service not known
  
      edit 20190516 yoh: but this looks like a perfectly valid path.
      SSH knows that it is not a path but its SSHRI so it can stay dumb.
      We are trying to be smart and choose between RIs (even when we know that
      it is e.g. a file).
      """
      _check_ri(
          "e.com/p/sp:f",
          PathRI,
          localpath="e.com/p/sp:f",
          path="e.com/p/sp:f",
      )
      _check_ri(
          "user@someho.st/mydir",
          PathRI,
          localpath="user@someho.st/mydir",
          path="user@someho.st/mydir",
      )
  
      # SSHRIs have .port, but it is empty
      eq_(SSHRI(hostname="example.com").port, "")
  
      # check that we are getting a warning logged when url can't be reconstructed
      # precisely
      # actually failed to come up with one -- becomes late here
      # _check_ri("http://host///..//p", scheme='http', path='/..//p')
  
      # actually this one is good enough to trigger a warning and I still don't know
      # what it should exactly be!?
      with swallow_logs(new_level=logging.DEBUG) as cml:
          weird_str = "weird://"
          weird_url = RI(weird_str)
          repr(weird_url)
          cml.assert_logged(
              "Parsed version of SSHRI .weird:/. "
              "differs from original .weird://."
          )
          # but we store original str
          eq_(str(weird_url), weird_str)
          neq_(weird_url.as_str(), weird_str)
  
      raise SkipTest(
          "TODO: file://::1/some does complain about parsed version dropping ::1"
      )
  
imports: import logging
  import os
  import tempfile
  from os.path import isabs
  from os.path import join
  import pytest
  import datalad.support.network
  from datalad.distribution.dataset import Dataset
  from datalad.support.network import RI, SSHRI, URL, DataLadRI, GitTransportRI, PathRI, _split_colon, dlurljoin, get_local_file_url, get_response_disposition_filename, get_tld, get_url_straight_filename, is_datalad_compat_ri, is_ssh, is_url, iso8601_to_epoch, local_path_representation, local_path2url_path, local_url_path_representation, parse_url_opts, quote_path, same_website, urlquote, url_path2local_path
  from datalad.tests.utils_pytest import OBSCURE_FILENAME, SkipTest, assert_in, assert_raises, assert_status, eq_, get_most_obscure_supported_name, known_failure_githubci_win, neq_, nok_, ok_, skip_if, swallow_logs, with_tempfile
  from datalad.utils import Path, PurePosixPath, on_windows
  from ..network import rfc2822_to_epoch
label_desc: Use image node_id 14 for calling a global function with example usage: test_url_samples() without return types