def ParseUrl(url):
  """Parses a URL string according to RFC 1738.
  Note: We allow '/' character in 'user', so we can specify workgroup of smb
  user.

  Args:
    url: An URL string.

  Returns:
    A dict with optional keys 'scheme', 'user', 'password', 'host', 'port', and
    'urlpath'.
  """
  result = {}

  scheme, delimiter, schemepart = url.partition('://')
  if not delimiter:
    return {}
  result['scheme'] = scheme

  userpass, unused_delimiter, hostpath = schemepart.rpartition('@')
  if userpass:
    user, delimiter, password = userpass.partition(':')
    result['user'] = user
    if delimiter:
      result['password'] = password

  hostport, delimiter, path = hostpath.partition('/')
  if delimiter:
    result['path'] = '/' + path

  host, unused_delimiter, port = hostport.partition(':')
  if host:
    result['host'] = host
  else:
    return {}
  if port:
    result['port'] = port

  return result