U
    “öhˆ  ã                   @   sh   d Z ddlmZmZ dZG dd„ deƒZG dd„ deƒZee ee edœd	d
„Z	eee
dœdd„ZdS )zHelpers for universe domain.é    )ÚAnyÚOptionalzgoogleapis.comc                       s   e Zd Z‡ fdd„Z‡  ZS )ÚEmptyUniverseErrorc                    s   d}t ƒ  |¡ d S )Nz*Universe Domain cannot be an empty string.)ÚsuperÚ__init__)ÚselfÚmessage©Ú	__class__© ú</tmp/pip-unpacked-wheel-eraazoov/google/api_core/universe.pyr      s    zEmptyUniverseError.__init__©Ú__name__Ú
__module__Ú__qualname__r   Ú__classcell__r   r   r	   r   r      s   r   c                       s   e Zd Z‡ fdd„Z‡  ZS )ÚUniverseMismatchErrorc                    s(   d|› d|› dt › d}tƒ  |¡ d S )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	   r   r   r      s    ÿzUniverseMismatchError.__init__r   r   r   r	   r   r      s   r   )Úclient_universe_domainÚuniverse_domain_envÚreturnc                 C   s6   t }| dk	r| }n|dk	r|}t| ¡ ƒdkr2t‚|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.
    Nr   )r   ÚlenÚstripr   )r   r   Úuniverse_domainr   r   r   Údetermine_domain'   s    r   )r   Úcredentialsr   c                 C   s"   t |dtƒ}| |krt| |ƒ‚dS )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.
    r   T)Úgetattrr   r   )r   r   r   r   r   r   Úcompare_domainsA   s    
r   N)Ú__doc__Útypingr   r   r   Ú
ValueErrorr   r   Ústrr   Úboolr   r   r   r   r   Ú<module>   s    þ