code: def get_key_url(e, schema="http", versioned=True):
      """Generate an s3:// or http:// url given a key
  
      if versioned url is requested but version_id is None, no versionId suffix
      will be added
      """
      # TODO: here we would need to encode the name since urlquote actually
      # can't do that on its own... but then we should get a copy of the thing
      # so we could still do the .format....
      # ... = e.name.encode('utf-8')  # unicode isn't advised in URLs
      e.name_urlquoted = urlquote(e.name)
      if schema == "http":
          fmt = "http://{e.bucket.name}.s3.amazonaws.com/{e.name_urlquoted}"
      elif schema == "s3":
          fmt = "s3://{e.bucket.name}/{e.name_urlquoted}"
      else:
          raise ValueError(schema)
      if versioned and e.version_id is not None:
          fmt += "?versionId={e.version_id}"
      return fmt.format(e=e)
  
imports: import mimetypes
  from os.path import splitext
  import re
  from datalad.support.network import urlquote, URL
  import logging
  import datalad.log
  from datalad.support.exceptions import CapturedException, DownloadError, AccessDeniedError, AccessPermissionExpiredError, AnonymousAccessDeniedError
  from datalad.utils import try_multiple_dec
  from urllib.request import urlopen, Request
label_desc: Use image node_id 6 for calling a global function with example usage: get_key_url(e, schema, versioned) and returns: fmt