
    0h/                        S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	J
r
  SqS rS r\ R                  " S5      r\ R                  " S5      r\ R                  " S5      rS rS	 r\ R                  " S
5      rS r\ R                  " S5      rS rS rS rS rS rS rS rSS jrS rS r S r! " S S\"5      r# " S S\#S9r$S r%S SK&r'\'RP                  RR                  r*\%\'RP                  l)        g)    N)Dictc                     [         cN  [        R                  R                  SS5      R	                  S5      q S[         ;   a  [         R                  S5        U [         ;   $ )a(  Check for whether a specific debugging feature is enabled.
Well-known flags:
 * start: Drop into debugger just after processing arguments
 * exception: Drop into debugger on fatalexception
 * warning: Drop into debugger on warning
 * posttrans: Drop into debugger just before introspectable pass
GI_SCANNER_DEBUG ,)_debugflagsosenvirongetsplitremove)flags    -/lib/gobject-introspection/giscanner/utils.pyhave_debug_flagr   #   sK     jjnn%7<BB3Gr";    c                 N    [        U 5      (       a  SS KnUR                  5         g g )Nr   )r   pdb	set_trace)r   r   s     r   break_on_debug_flagr   3   s    t r   z([^A-Z])([A-Z])z([A-Z][A-Z])([A-Z][0-9a-z])z^([A-Z])([A-Z])c                     [         R                  SU 5      n [        R                  SU 5      n [        R                  SU SS9n U $ )a6  Converts a typename to the equivalent underscores name.
This is used to form the type conversion macros and enum/flag
name variables.
In particular, and differently from to_underscores_noprefix(),
this function treats the first character differently if it is
uppercase and followed by another uppercase letter.\1_\2   )count)_upperstr_pat1sub_upperstr_pat2_upperstr_pat3names    r   to_underscoresr    ?   sD     h-Dh-DhA6DKr   c                 ^    [         R                  SU 5      n [        R                  SU 5      n U $ )zoLike to_underscores, but designed for "unprefixed" names.
to_underscores("DBusFoo") => dbus_foo, not d_bus_foo.r   )r   r   r   r   s    r   to_underscores_noprefixr"   L   s-     h-Dh-DKr   zdlname='([A-z0-9\.\-\+]+)'
c                     [        U SS9 nUR                  5       nS S S 5        [        R                  W5      nU(       a  UR	                  5       S   $ g ! , (       d  f       N>= fNzutf-8)encodingr   )openread_libtool_patsearchgroupsla_filefdatams       r   _extract_dlname_fieldr0   W   sM    	g	(Avvx 
)D!Axxz!} 
)	(   A
A"zlibdir='([^']+)'c                     [        U SS9 nUR                  5       nS S S 5        [        R                  W5      nU(       a  UR	                  5       S   $ g ! , (       d  f       N>= fr$   )r&   r'   _libtool_libdir_patr)   r*   r+   s       r   _extract_libdir_fieldr4   d   sM    	g	(Avvx 
)""4(Axxz!} 
)	(r1   c                     [        U 5      nUc  g [        R                  " 5       S:X  a7  [        R                  R                  U5      n[        U 5      nUc  U$ US-   U-   $ [        R                  R                  U5      $ )NDarwin/)r0   platformsystemr	   pathbasenamer4   )r,   dlname
dlbasenamelibdirs       r   extract_libtool_shlibr?   p   sr    "7+F~ H$WW%%f-
&w/>|j((77F##r   c                 \   U R                   (       + nU(       d  g U R                  nU(       a  UR                  S5      $ Sn[        R                  " 5       S:X  a  Sn [
        R                  " US/[        [        R                  S5      S9  U/$ ! [
        R                  [        4 a     g f = f)N libtoolr6   glibtoolz	--versionw)stdout)	nolibtoollibtool_pathr   r8   r9   
subprocess
check_callr&   r	   devnullCalledProcessErrorOSError)optionslibtool_infectionrG   libtool_cmds       r   get_libtool_commandrP      s    #---''L
 !!#&&KH$ {K8%)"**c%:	< =	 ))73 s   /B B+*B+c                 p   [        U S5       n[        US5       nUR                  S5      nUR                  S5      nXE:X  a5  US:w  a/  UR                  S5      nUR                  S5      nXE:X  a  US:w  a  M/  XE:H  sS S S 5        sS S S 5        $ ! , (       d  f       O= fS S S 5        g ! , (       d  f       g = f)Nrbi    r   )r&   r'   )path1path2f1f2buf1buf2s         r   files_are_identicalrY      s    	eT	b$ud"3rwwt}wwt}lts{774=D774=D lts{ | #4"3		"3"3			s)   B'AB7B:	B'
B	B''
B5c                 |    U R                  S5      (       d  U $ S[        R                  R                  U SS  5      -   $ )Nz-I   )
startswithr	   r:   realpath)cflags    r   cflag_real_include_pathr_      s8    D!!"''""59---r   c                  ^    [         R                  R                  S[         R                  5      $ )N
GI_HOST_OS)r	   r
   r   r    r   r   host_osrc      s    ::>>,00r   c                    S nS n[         R                  R                  U 5      u  p4U(       a6  U" U 5      (       a  U $ [         R                  S:X  a  U" U 5      (       a  U S-   $ g [         R                  S   R                  [         R
                  5       Hn  nUR                  S5      n[         R                  R                  XP5      nU" U5      (       a  Us  $ [         R                  S:X  d  MZ  U" U5      (       d  Mi  US-   s  $    g )Nc                     [         R                  R                  U 5      =(       a%    [         R                  " U [         R                  5      $ N)r	   r:   isfileaccessX_OKfpaths    r   is_exewhich.<locals>.is_exe   s)    ww~~e$B5"'')BBr   c                     U R                  5       R                  S5      (       + =(       aQ    [        R                  R	                  U S-   5      =(       a(    [        R
                  " U S-   [        R                  5      $ )N.exe)lowerendswithr	   r:   rg   rh   ri   rj   s    r   	is_nt_exewhich.<locals>.is_nt_exe   sR    ;;=))&11 /GGNN56>*/IIefnbgg.	/r   ntro   PATH")r	   r:   r   r   r
   pathsepstripjoin)programrl   rr   rk   fnamer:   exe_files          r   whichr}      s    C/
 77==)LE'??N77d?y11V##  JJv&,,RZZ8D::c?Dww||D2Hhww$9X#6#6&(( 9 r   c                    [         R                  R                  S5      nUb;  U b  [         R                  R	                  X5      n [         R
                  " USSS9  U$ [         R                  R                  S5      nUb[  [         R                  R	                  US5      nU b  [         R                  R	                  X05      n [         R
                  " USSS9  U$ g! [         a     Nf = f! [         a     gf = f)z
This is a Python reimplemention of `g_get_user_cache_dir()` because we don't want to
rely on the python-xdg package and we can't depend on GLib via introspection.
If any changes are made to that function they'll need to be copied here.
XDG_CACHE_HOMENi  Tmodeexist_ok~z.cache)r	   r
   r   r:   ry   makedirsEnvironmentError
expanduser)dirxdg_cache_homehomedircachedirs       r   get_user_cache_dirr      s     ZZ^^$45N!?WW\\.>N	"KKUTB
 "!gg  %G77<<2?ww||H2H	KKut< O%   		   		s$   C C, 
C)(C),
C98C9c                  r   [         R                  R                  S5      n U b   [         R                  " U SSS9  U $ [         R
                  R                  S5      nUb:  [         R
                  R                  USS5      n [         R                  " USSS9  U$ g! [         a     Nif = f! [         a     gf = f)	z
This is a Python reimplemention of `g_get_user_data_dir()` because we don't want to
rely on the python-xdg package and we can't depend on GLib via introspection.
If any changes are made to that function they'll need to be copied here.
XDG_DATA_HOMENi  Tr   r   z.localshare)r	   r
   r   r   r   r:   r   ry   )xdg_data_homer   datadirs      r   get_user_data_dirr      s     JJNN?3M 	!KKEDA
 ! gg  %G'',,w':	KKed; N!   		   		s#   B  B) 
B&%B&)
B65B6c                  4   [         R                  R                  SS5      R                  [         R                  5       V s/ s H  o PM     nn [        U5      (       d6  [         R                  S:w  a"  UR                  S5        UR                  S5        U$ s  sn f )z
This is a Python reimplemention of `g_get_system_data_dirs()` because we don't want to
rely on the python-xdg package and we can't depend on GLib via introspection.
If any changes are made to that function they'll need to be copied here.
XDG_DATA_DIRSr   rt   z/usr/local/sharez
/usr/share)r	   r
   r   r   rw   anyr   append)xxdg_data_dirss     r   get_system_data_dirsr     sv     !#

 C I I"** UV U1Q UMV}"''T//0\* Ws    Bc                      Sn[        SUS-   5       H  n [        R                  " U 0 UD6    g   g! [         a     X2:X  a  e [        R
                  " U5         MH  f = f)a  
A variant of shutil.rmtree() which waits and tries again in case one of
the files in the directory tree can't be deleted.

This can be the case if a file is still in use by some process,
for example a Virus scanner on Windows scanning .exe files when they are
created.
   r   N)rangeshutilrmtreerL   timesleep)argskwargstriesis       r   r   r     s`     E1eai 	MM4*6*  !  	zJJqM		s   1&AAc                   F   ^  \ rS rSr% Sr0 r\\\4   \	S'   U 4S jr
SrU =r$ )	Singletoni2  zB
A helper class to be used as metaclass to implement a singleton.

_instancesc                    > X R                   ;  a!  [        [        U ]  " U0 UD6U R                   U '   U R                   U    $ rf   )r   superr   __call__)clsr   r   	__class__s      r   r   Singleton.__call__8  s;    nn$"'	3"@$"Q&"QCNN3~~c""r   rb   )__name__
__module____qualname____firstlineno____doc__r   r   typeobject__annotations__r   __static_attributes____classcell__)r   s   @r   r   r   2  s'     &(JT6\"'# #r   r   c                   4    \ rS rSrSrSrS rS rS rS r	Sr
g)dll_dirsiE  Nc                 v    [         R                  S:X  a%  [        [         S5      (       a  / U l        / U l        g g g )Nrt   add_dll_directory)r	   r   hasattr_cached_dll_dirs_cached_added_dll_dirs)selfs    r   __init__dll_dirs.__init__I  s2    77d?wr+>??$&D!*,D'  @?r   c                 .   [         R                  S:X  Ga   [        [         S5      (       a  S[         R                  ;   aT  [         R                  R	                  S5      R                  [         R                  5       H  nU R                  U5        M     [        R                  R                  US5       H&  nUR                  SS5      nU R                  U5        M(     [        R                  R                  U5       H  nU R                  U5        M     g g g )Nrt   r   GI_EXTRA_BASE_DLL_DIRSTz-Lr   )r	   r   r   r
   r   r   rw   _add_dll_dir	giscanner	pkgconfiglibs_only_Lreplacebindir)r   pkgsr:   libpaths       r   add_dll_dirsdll_dirs.add_dll_dirsN  s    77d?wr+>??'2::5JJNN+CDJJ2::VD%%d+ W "++77dC,,tR0!!'* D "++2248!!$' 9  @?r   c                     U R                   b=  U R                    H  nUR                  5         M     U R                   R                  5         U R                  b  U R                  R                  5         g g rf   )r   closeclearr   )r   added_dll_dirs     r   cleanup_dll_dirsdll_dirs.cleanup_dll_dirs[  s_    &&2!%!<!<##% "=''--/  ,!!'') -r   c                     XR                   ;  aK  U R                   R                  U5        U R                  R                  [        R                  " U5      5        g g rf   )r   r   r   r	   r   )r   r:   s     r   r   dll_dirs._add_dll_dirc  sF    ,,,!!((.''..r/C/CD/IJ -r   )r   r   )r   r   r   r   r   r   r   r   r   r   r   rb   r   r   r   r   E  s#    !-
(*Kr   r   )	metaclassc                       [        5       $ ! [         a     Of = f[        R                  R	                  S5      n U S:w  a5  [        R                  U S-   U S-    nUS:X  a  S/$ US:X  a  S/$ US	:  a  S
/$ g g )NzMSC v.   
   1700msvcr1101800msvcr1201900vcruntime140)orig_get_msvcr
ValueErrorsysversionfind)msc_posmsc_vers     r   get_msvcr_overwriter   l  s      kkx(G"}++gk'B,7f<<"##  s   	 
rf   )+rer	   rH   r8   r   r   r   giscanner.pkgconfigr   typingr   r   r   r   compiler   r   r   r    r"   r(   r0   r3   r4   r?   rP   rY   r_   rc   r}   r   r   r   r   r   r   r   r   distutils.cygwinccompiler	distutilscygwinccompiler	get_msvcrr   rb   r   r   <module>r      s  * 
 	    
      ./:;./
 zz;< jj!34 $$6.16D<.	# 	#&!K !KN$* !**44&9	   #r   