
    AwjG                         d Z ddlmZmZ ddlmZmZ ddlmZ dZ	 G d de
      Z G d d	e
      Zd
ee   dedefdZdee   dee   defdZdededefdZdee   dee   fdZdee   dededee   dededefdZy)zHelpers for universe domain.    )AnyOptional)urlparse
urlunparse)MutualTLSChannelErrorzgoogleapis.comc                        e Zd Z fdZ xZS )EmptyUniverseErrorc                 (    d}t         |   |       y )Nz*Universe Domain cannot be an empty string.)super__init__)selfmessage	__class__s     V/root/dashboard-youtube/.venv/lib/python3.12/site-packages/google/api_core/universe.pyr   zEmptyUniverseError.__init__   s    >!    __name__
__module____qualname__r   __classcell__r   s   @r   r	   r	      s    " "r   r	   c                        e Zd Z fdZ xZS )UniverseMismatchErrorc                 D    d| d| dt          d}t        | 	  |       y )Nz The configured universe domain (z?) does not match the universe domain found in the credentials (z>). If you haven't configured the universe domain explicitly, `z` is the default.)DEFAULT_UNIVERSEr   r   )r   client_universecredentials_universer   r   s       r   r   zUniverseMismatchError.__init__    s>    ..? @))=(> ? !!24 	 	!r   r   r   s   @r   r   r      s    " "r   r   potential_universesdefault_universereturnc                 D    t        d |D        |       }|s
t               |S )a  Return the universe domain used by the client.

    Args:
        *potential_universes (Optional[str]): Potential universe domains in order of preference.
        default_universe (str): The default universe domain.

    Returns:
        str: The universe domain to be used by the client.

    Raises:
        EmptyUniverseError: If the resolved universe domain is an empty string.
    c              3   B   K   | ]  }||j                           y w)N)strip).0xs     r   	<genexpr>z&get_universe_domain.<locals>.<genexpr>;   s     Aq1=As   )nextr	   )r   r   resolveds      r   get_universe_domainr)   *   s-      A/AH
  ""Or   client_universe_domainuniverse_domain_envc                 &    t        | |t              S )a  Return the universe domain used by the client.

    Args:
        client_universe_domain (Optional[str]): The universe domain configured via the client options.
        universe_domain_env (Optional[str]): The universe domain configured via the
        "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable.

    Returns:
        str: The universe domain to be used by the client.

    Raises:
        ValueError: If the universe domain is an empty string.
    )r   )r)   r   )r*   r+   s     r   determine_domainr-   D   s      ) r   r   credentialsc                 H    t        |dt              }| |k7  rt        | |      y)a  Returns True iff the universe domains used by the client and credentials match.

    Args:
        client_universe (str): The universe domain configured via the client options.
        credentials Any: The credentials being used in the client.

    Returns:
        bool: True iff client_universe matches the universe in credentials.

    Raises:
        ValueError: when client_universe does not match the universe in credentials.
    universe_domainT)getattrr   r   )r   r.   r   s      r   compare_domainsr2   [   s/     #;0ACST..#O5IJJr   api_endpointc                    | rd| j                         v r| S d| v }|st        d| z         }nt        |       }|j                  }|s| S |j                  rd|j                   nd}|j                         }d}d}|j	                  |      r|dt        |        d	z   }n&|j	                  |      r|dt        |        d
z   }n| S ||z   }	|j                  |	      }
|st        |
      dd S t        |
      S )a  Converts api endpoint to mTLS endpoint.

    Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to
    "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively.
    Other URLs (including those that do not match these domain suffixes or
    already contain '.mtls.') are passed through as-is.

    Args:
        api_endpoint (Optional[str]): the api endpoint to convert.

    Returns:
        Optional[str]: converted mTLS api endpoint.
    z.mtls.z://z//: z.sandbox.googleapis.comz.googleapis.comNz.mtls.sandbox.googleapis.comz.mtls.googleapis.com)netloc   )lowerr   hostnameportendswithlen_replacer   )r3   
has_schemeparsedhostr;   lowered_hostsuffix_sandboxsuffix_googlenew_hostr7   
new_parseds              r   get_default_mtls_endpointrG   o   s    8|'9'9';;,&J$-.,'??D &Qv{{mD::<L.N%M^,.3~../2PP			}	--3}--.1GG_F/J*%ab))*%%r   api_overrider0   default_mtls_endpointdefault_endpoint_templateuse_mtlsc                     | | S |r?|j                         |j                         k7  rt        d| d      |st        d      |S |j                  |      S )ad  Return the API endpoint used by the client.

    Args:
        api_override (Optional[str]): The API endpoint override. If specified,
            this is always returned.
        universe_domain (str): The universe domain used by the client.
        default_universe (str): The default universe domain.
        default_mtls_endpoint (Optional[str]): The default mTLS endpoint.
        default_endpoint_template (str): The default endpoint template containing
            a placeholder `{UNIVERSE_DOMAIN}`.
        use_mtls (bool): Whether to use the mTLS endpoint.

    Returns:
        str: The API endpoint to be used by the client.

    Raises:
        google.auth.exceptions.MutualTLSChannelError: If mTLS is requested but
            not supported in the configured universe domain.
        ValueError: If mTLS is requested but no mTLS endpoint is available.
    z1mTLS is not supported in any universe other than .zmTLS endpoint is not available.)UNIVERSE_DOMAIN)r9   r   
ValueErrorformat)rH   r0   r   rI   rJ   rK   s         r   get_api_endpointrQ      su    8   "&6&<&<&>>'CDTCUUVW  %>??$$(///PPr   N)__doc__typingr   r   urllib.parser   r   google.auth.exceptionsr   r   rO   r	   r   strr)   r-   boolr2   rG   rQ    r   r   <module>rY      s   #   - 8# " ""J ""3- 	4$SM@H.S s t (-&HSM -&hsm -&`(Q3-(Q(Q (Q $C=	(Q
  #(Q (Q 	(Qr   