code: def uri2fsn(uri):
      
  
      if PY2:
          if isinstance(uri, text_type):
              uri = uri.encode("utf-8")
          if not isinstance(uri, bytes):
              raise TypeError("uri needs to be ascii str or unicode")
      else:
          if not isinstance(uri, str):
              raise TypeError("uri needs to be str")
  
      parsed = urlparse(uri)
      scheme = parsed.scheme
      netloc = parsed.netloc
      path = parsed.path
  
      if scheme != "file":
          raise ValueError("Not a file URI: %r" % uri)
  
      if not path:
          raise ValueError("Invalid file URI: %r" % uri)
  
      uri = urlunparse(parsed)[7:]
  
      if is_win:
          try:
              drive, rest = uri.split(":", 1)
          except ValueError:
              path = ""
              rest = uri.replace("/", "\\")
          else:
              path = drive[-1] + ":"
              rest = rest.replace("/", "\\")
          if PY2:
              path += unquote(rest)
          else:
              path += unquote(rest, encoding="utf-8", errors="surrogatepass")
          if netloc:
              path = "\\\\" + path
          if PY2:
              path = path.decode("utf-8")
          if u"\x00" in path:
              raise ValueError("embedded null")
          return path
      else:
          if PY2:
              path = unquote(uri)
          else:
              path = unquote(uri, encoding=_encoding, errors="surrogateescape")
          if "\x00" in path:
              raise ValueError("embedded null")
          return path
docs: Args:
          uri (`text` or :obj:`python:str`): A file URI
      Returns:
          `fsnative`
      Raises:
          TypeError: In case an invalid type is passed
          ValueError: In case the URI isn't a valid file URI
  
      Takes a file URI and returns a `fsnative` path