parameters: (arg)
return_statement: return "{0}://{1}:{2}".format(origin.scheme, origin.hostname, port)
docstring: Constructs the origin for the token from a command line argument.
  
    Returns None if this is not possible (neither a valid hostname nor a
    valid origin URL was provided.)
docstring_summary: Constructs the origin for the token from a command line argument.
docstring_tokens: Constructs the origin for the token from a command line argument .
function: def OriginFromArg(arg):
    """Constructs the origin for the token from a command line argument.
  
    Returns None if this is not possible (neither a valid hostname nor a
    valid origin URL was provided.)
    """
    # Does it look like a hostname?
    hostname = HostnameFromArg(arg)
    if hostname:
      return "https://" + hostname + ":443"
    # If not, try to construct an origin URL from the argument
    origin = urlparse.urlparse(arg)
    if not origin or not origin.scheme or not origin.netloc:
      raise argparse.ArgumentTypeError("%s is not a hostname or a URL" % arg)
    # HTTPS or HTTP only
    if origin.scheme not in ('https','http'):
      raise argparse.ArgumentTypeError("%s does not use a recognized URL scheme" %
                                       arg)
    # Add default port if it is not specified
    try:
      port = origin.port
    except ValueError:
      raise argparse.ArgumentTypeError("%s is not a hostname or a URL" % arg)
    if not port:
      port = {"https": 443, "http": 80}[origin.scheme]
    # Strip any extra components and return the origin URL:
    return "{0}://{1}:{2}".format(origin.scheme, origin.hostname, port)
function_tokens: def OriginFromArg ( arg ) : # Does it look like a hostname? hostname = HostnameFromArg ( arg ) if hostname : return "https://" + hostname + ":443" # If not, try to construct an origin URL from the argument origin = urlparse . urlparse ( arg ) if not origin or not origin . scheme or not origin . netloc : raise argparse . ArgumentTypeError ( "%s is not a hostname or a URL" % arg ) # HTTPS or HTTP only if origin . scheme not in ( 'https' , 'http' ) : raise argparse . ArgumentTypeError ( "%s does not use a recognized URL scheme" % arg ) # Add default port if it is not specified try : port = origin . port except ValueError : raise argparse . ArgumentTypeError ( "%s is not a hostname or a URL" % arg ) if not port : port = { "https" : 443 , "http" : 80 } [ origin . scheme ] # Strip any extra components and return the origin URL: return "{0}://{1}:{2}" . format ( origin . scheme , origin . hostname , port )