
                             S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKrSSKrSSK	J
r
  SSKr " S S\
R                  5      r " S	 S
\5      rS rS rS rS rg)zBUtilities for accessing modules by installation independent paths.    )absolute_import)division)unicode_literalsN)
exceptionsc                       \ rS rSrSrSrg)Error   zExceptions for this module. N__name__
__module____qualname____firstlineno____doc____static_attributes__r
       &lib/googlecloudsdk/core/module_util.pyr   r      s    #r   r   c                       \ rS rSrSrSrg)ImportModuleError#   zImportModule failed.r
   Nr   r
   r   r   r   r   #   s    r   r   c                    U R                  S5      n[        U5      S:  a  [        SR                  U 5      5      e [        R
                  " US   5      n[        U5      S:X  a  U$ UnUS   R                  S5      nU H  n [        XF5      nM     U$ ! [         a  n[        SR                  X5      5      eSnAff = f! [         a  n[        SR                  X5      5      eSnAff = f)	a|  Imports a module object given its ModulePath and returns it.

A module_path from GetModulePath() from any valid installation is importable
by ImportModule() in another installation of same release.

Args:
  module_path: The module path to import.

Raises:
  ImportModuleError: Malformed module path or any failure to import.

Returns:
  The Cloud SDK object named by module_path.
:   zQModule path [{}] must be in the form: package(.module)+(:attribute(.attribute)*)?r   zModule path [{}] not found: {}.N   .)	splitlenr   format	importlibimport_moduleImportErrorgetattrAttributeError)module_pathpartsmoduleeobj
attributesattrs          r   ImportModuler+   '   s   " 

C
 %Z!^
	66<f[6IK KB$$U1X.F 	Z1_M 	#Qx~~c"*dDCc  
* 
 B
)00@B BB  D
+
2
2;
BD DDs/   B B?
B<B77B<?
C(	C##C(c                     A g)zHMock hook that returns the module path for module that starts with '__'.Nr
   )r$   s    r   _GetPrivateModulePathr-   Q   s    	r   c                     U R                   n[        R                  (       a  US:X  a  gUR                  S5      (       a  [        U5      nU(       d  g US-   U R                  -   $ ! [         a    U R                  n U R                   n N|f = f! [         a1     US-   U R                  R                  -   s $ ! [         a      gf = ff = f)a#  Returns the module path string for obj, None if it's builtin.

The module path is relative and importable by ImportModule() from any
installation of the current release.

Args:
  obj: The object to get the module path from.

Returns:
  The module path name for obj if not builtin else None.
builtinsN__r   )r   r#   	__class__sixPY3
startswithr-   r   )r(   r&   s     r   GetModulePathr5   W   s    ^^F
 	WW:%t"6*FC<#,,&& 
 
--C^^F 
 c\CMM2222 sA   A& B &"B
B
C	B74C	7
CC	CC	c                    [         R                  R                  [         R                  R                  U 5      5      S   n[        R
                  R                  X5      nU(       d  [        SR                  U 5      5      e[        R
                  R                  U5      nU[        R                  U'    UR                  R                  U5        U$ ! [         a  n[        SR                  X5      5      eSnAff = f)z?Imports and returns the module given a python source file path.r   zModule file [{}] not found.zModule file [{}] not found: {}.N)ospathsplitextbasenamer   utilspec_from_file_locationr   r   module_from_specsysmodulesloaderexec_moduleFileNotFoundError)r8   module_namespecr&   r'   s        r   
ImportPathrE   z   s      !1!1$!78;+		/	/	B$	
%,,T24 4>>**40&##++k;KKF# 
- 
 ;
)009; ;;s   3C 
C9C44C9)r   
__future__r   r   r   r   importlib.utilr7   r>   googlecloudsdk.corer   r2   r   r   r+   r-   r5   rE   r
   r   r   <module>rI      sZ     I &  '   	 
 * 
$J $ 'T Fr   