
                         d    S r SSKJr  SSKJr  SSKJr  SSKJr   " S S\5      r " S S	\5      r	g
)a  Defines a registry for storing per-runtime information.

A registry is essentially a wrapper around a Python dict that stores a mapping
from (runtime, environment) to arbitrary data. Its main feature is that it
supports lookups by matching both the runtime and the environment.
    )absolute_import)division)unicode_literals)mapc                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)RegistryEntry   zAn entry in the Registry.

Attributes:
  runtime: str or re.RegexObject, the runtime to be staged
  envs: set(env.Environment), the environments to be staged
c                     Xl         X l        g Nruntimeenvs)selfr   r   s      2lib/googlecloudsdk/api_lib/app/runtime_registry.py__init__RegistryEntry.__init__&   s    LI    c                 x     U R                   R                  U5      $ ! [         a    U R                   U:H  s $ f = fr   )r   matchAttributeError)r   r   s     r   _RuntimeMatchesRegistryEntry._RuntimeMatches*   s:    %\\(( %\\W$$%s    99c                     XR                   ;   $ r   )r   )r   envs     r   _EnvMatchesRegistryEntry._EnvMatches0   s    ))r   c                 T    U R                  U5      =(       a    U R                  U5      $ )a  Returns True iff the given runtime and environment match this entry.

The runtime matches if it is an exact string match.

The environment matches if it is an exact Enum match or if this entry has a
"wildcard" (that is, None) for the environment.

Args:
  runtime: str, the runtime to match
  env: env.Environment, the environment to match

Returns:
  bool, whether the given runtime and environment match.
)r   r   )r   r   r   s      r   MatchesRegistryEntry.Matches3   s%     (BT-=-=c-BBr   c                     [        U R                  [        [        [	        [         U R
                  5      5      5      45      $ r   )hashr   sumsortedr   r   )r   s    r   __hash__RegistryEntry.__hash__D   s+    s6#dDII*>#?@ABBr   c                 t    U R                   UR                   :H  =(       a    U R                  UR                  :H  $ r   r   r   others     r   __eq__RegistryEntry.__eq__H   s'    <<5==(DTYY%**-DDr   c                 .    U R                  U5      (       + $ r   )r)   r'   s     r   __ne__RegistryEntry.__ne__K   s    {{5!!!r   )r   r   N)__name__
__module____qualname____firstlineno____doc__r   r   r   r   r$   r)   r,   __static_attributes__ r   r   r   r      s-    %C"CE"r   r   c                   (    \ rS rSrSrSS jrS rSrg)RegistryO   a  A registry to store values for various runtimes and environments.

The registry is a map from (runtime, app-engine-environment) to
user-specified values. As an example, storing Booleans for different
runtimes/environments would look like:

REGISTRY = {
  RegistryEntry('php72', {env.STANDARD}): True,
  RegistryEntry('php55', {env.STANDARD}): False,
  RegistryEntry('nodejs8', {env.FLEX}): False,
}

Attributes:
  mappings: dict, where keys are RegistryEntry objects and values can be
    of any type
  override: object or None; if specified, this value will always be returned
    by Get()
  default: object or None; if specified, will be returned if Get() could not
    find a matching registry entry
Nc                 <    U=(       d    0 U l         X l        X0l        g r   )mappingsoverridedefault)r   r9   r:   r;   s       r   r   Registry.__init__e   s    NDMMLr   c                     U R                   (       a  U R                   $ U R                  R                  5        H  u  p4UR                  X5      (       d  M  Us  $    U R                  b  U R                  $ g)a>  Return the associated value for the given runtime/environment.

Args:
  runtime: str, the runtime to get a stager for
  env: env, the environment to get a stager for

Returns:
  object, the matching entry, or override if one was specified. If no
    match is found, will return default if specified or None otherwise.
N)r:   r9   itemsr   r;   )r   r   r   entryvalues        r   GetRegistry.Getj   s[     }}]]++-	w	$	$ . ||\\r   )r;   r9   r:   )NNN)r.   r/   r0   r1   r2   r   rA   r3   r4   r   r   r6   r6   O   s    *
r   r6   N)
r2   
__future__r   r   r   	six.movesr   objectr   r6   r4   r   r   <module>rF      s1    '  ' ."F ."b0v 0r   