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dd1l{m’Z’ ee‘ ZZ‘e’Z’G d2d3„ d3e“ƒZ”G d4d5„ d5e“ƒZ•G d6d7„ d7e“ƒZ–dd8l;m—Z˜ dd9l™mšZš d^d<d=„Z—dZ›dZœd>d?„ Zd@dA„ ZžddBlmŸZŸm Z m¡Z¡m¢Z¢ eŸe  ZŸZ e¡e¢ Z¡Z¢ddClm£Z¤ d_dEdF„Z£dd,lˆm‰Z‰ ddGl¥m¦Z¦m§Z¨m©Zª e¦Z¦d`dIdJ„Z©dadKdL„Z§dMdN„ Z«dbdOdP„Z¬dQdR„ Z­e(rÒdSdT„ Z®dcdUdV„Z¯dddWdX„Z°dYdZ„ Z±ded\d]„Z6dS )fé    )Úabsolute_importÚdivisionÚprint_functionÚunicode_literals)ÚHashableNé   )Ú
CondaError)Úreset_context)Úplan)ÚSolver)Úspecs_from_argsÚspec_from_lineÚspecs_from_url)Úadd_parser_prefixÚadd_parser_channels)ÚArgumentParser)Úcompat)ÚPY3ÚStringIOÚinputÚ	iteritemsÚon_winÚstring_typesÚ	text_typeÚ
itervalues)ÚCondaSession)ÚTemporaryDirectory)Ú	_toposort)Úlchmod)ÚTmpDownloadÚdownloadc             C   s
   t  d¡S )Nz<handle_proxy_407 is deprecated. Now handled by CondaSession.)Ú	_warningsÚwarn)ÚxÚy© r%   ú,lib/python3.7/site-packages/conda/exports.pyÚ<lambda>:   ó    r'   )Ú
rm_fetched)Údelete_trashÚmove_to_trash)Ú	untrackedÚwalk_prefix)Ú	MatchSpecÚResolvePackageNotFoundÚResolveÚUnsatisfiable)Úhashsum_fileÚhuman_bytesÚunix_path_to_winÚurl_path)Úwin_path_to_unix)Úcompute_md5sum)ÚVersionOrderÚnormalized_version)ÚChannel)Ú
get_prefixÚnon_x86_linux_machinesr	   Úsys_rc_path)ÚEntityEncoder)ÚDEFAULT_CHANNELSÚDEFAULT_CHANNELS_WINÚDEFAULT_CHANNELS_UNIXc               C   s   t S )N)r?   r%   r%   r%   r&   r'   c   r(   )ÚPREFIX_PLACEHOLDER)Úget_conda_build_local_urlc               C   s   t tjjjjƒS )N)ÚlistÚcondaÚbaseÚcontextZchannelsr%   r%   r%   r&   r'   u   r(   c               C   s   t tƒ ƒpg S )N)rD   rC   r%   r%   r%   r&   r'   v   r(   c             C   s   t jj | g¡S )N)rE   rF   rG   r	   )Úfnr%   r%   r&   r'   w   r(   )ÚPaddingErrorÚ	LinkErrorÚCondaOSErrorÚPathNotFoundError)ÚCrossPlatformStLink)ÚFileMode)ÚPathType)ÚPackageRecord)ÚDist)ÚACTIVE_SUBPROCESSESÚsubprocess_call)Úcache_fn_url)ÚProgressiveFetchExtract)ÚCondaHTTPErrorÚ	LockError)ÚUnsatisfiableErrorc               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )Ú	Completerc             C   s   |   ¡ S )N)Z
_get_items)Úselfr%   r%   r&   Ú	get_items   s    zCompleter.get_itemsc             C   s   dS )NTr%   )rZ   Úitemr%   r%   r&   Ú__contains__    s    zCompleter.__contains__c             C   s   t |  ¡ ƒS )N)Úiterr[   )rZ   r%   r%   r&   Ú__iter__£   s    zCompleter.__iter__N)Ú__name__Ú
__module__Ú__qualname__r[   r]   r_   r%   r%   r%   r&   rY   œ   s   rY   c               @   s   e Zd ZdS )ÚInstalledPackagesN)r`   ra   rb   r%   r%   r%   r&   rc   §   s   rc   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )Úmemoizedz©Decorator. Caches a function's return value each time it is called.
    If called later with the same arguments, the cached value is returned
    (not reevaluated).
    c             C   s   || _ i | _t ¡ | _d S )N)ÚfuncÚcacheÚ	threadingZLockÚlock)rZ   re   r%   r%   r&   Ú__init__°   s    zmemoized.__init__c          	   O   s¬   g }xF|D ]>}t |tƒr(| t|ƒ¡ q
t |tƒs>| j||ŽS | |¡ q
W t|ƒ}|tt| ¡ ƒƒf}| j	4 || j
kr„| j
| S | j||Ž}|| j
|< |S W d Q R X d S )N)Ú
isinstancerD   ÚappendÚtupleÚ	_Hashablere   Ú	frozensetÚsortedÚitemsrh   rf   )rZ   ÚargsÚkwZnewargsÚargÚkeyÚvaluer%   r%   r&   Ú__call__µ   s    





zmemoized.__call__N)r`   ra   rb   Ú__doc__ri   rv   r%   r%   r%   r&   rd   «   s   rd   )Úrm_rf)Údelete_prefix_from_linked_dataé   Tc             C   s   t | ||ƒ t| ƒ d S )N)Ú_rm_rfry   )ÚpathZmax_retriesZtrashr%   r%   r&   rx   Ï   s    rx   c             C   s   d S )Nr%   )Ú_r%   r%   r&   Ú	hash_fileÛ   s    r~   c             C   s   dS )NFr%   )r}   r%   r%   r&   Úverifyß   s    r   )Úexecute_actionsÚexecute_instructionsÚexecute_planÚinstall_actions)Údisplay_actionsr%   c                sˆ   d| kr"‡ fdd„| d D ƒ| d< d| krD‡ fdd„| d D ƒ| d< d| krf‡ fdd„| d D ƒ| d< dd	„ t ˆ ƒD ƒ‰ t| ˆ |||ƒS )
NZFETCHc                s   g | ]}ˆ | ‘qS r%   r%   )Ú.0Úd)Úindexr%   r&   ú
<listcomp>ê   s    z#display_actions.<locals>.<listcomp>ZLINKc                s   g | ]}ˆ | ‘qS r%   r%   )r…   r†   )r‡   r%   r&   rˆ   ì   s    ZUNLINKc                s   g | ]}ˆ | ‘qS r%   r%   )r…   r†   )r‡   r%   r&   rˆ   î   s    c             S   s   i | ]
}||“qS r%   r%   )r…   Úprecr%   r%   r&   ú
<dictcomp>ï   s    z#display_actions.<locals>.<dictcomp>)r   Ú_display_actions)Zactionsr‡   Zshow_channel_urlsZspecs_to_removeZspecs_to_addr%   )r‡   r&   r„   è   s    r„   )Údist_str_in_indexÚfetch_indexÚ	get_indexFc             C   s&   t | ||||||ƒ}dd„ t|ƒD ƒS )Nc             S   s   i | ]}|t |ƒ“qS r%   )rQ   )r…   r‰   r%   r%   r&   rŠ   û   s    zget_index.<locals>.<dictcomp>)Ú
_get_indexr   )Úchannel_urlsZprependÚplatformZ	use_localÚ	use_cacheÚunknownÚprefixr‡   r%   r%   r&   rŽ   ø   s    rŽ   c             C   s   t | ||ƒ}dd„ t|ƒD ƒS )Nc             S   s   i | ]}|t |ƒ“qS r%   )rQ   )r…   r‰   r%   r%   r&   rŠ      s    zfetch_index.<locals>.<dictcomp>)Ú_fetch_indexr   )r   r’   r‡   r%   r%   r&   r   þ   s    r   c                 s&   ddl m‰  G ‡ fdd„dtƒ} | ƒ S )Nr   )ÚPackageCacheDatac                   s0   e Zd Z‡ fdd„Z‡ fdd„Z‡ fdd„ZdS )z$package_cache.<locals>.package_cachec                s   t ˆ  ¡  t|ƒ ¡ d ¡ƒS )N)ÚboolÚfirst_writableÚgetrQ   Úto_package_ref)rZ   Údist)r–   r%   r&   r]     s    z1package_cache.<locals>.package_cache.__contains__c                s   dd„ t ˆ  ¡ ƒD ƒS )Nc             s   s   | ]}t |ƒV  qd S )N)rQ   )r…   Úvr%   r%   r&   ú	<genexpr>  s    z<package_cache.<locals>.package_cache.keys.<locals>.<genexpr>)r   r˜   )rZ   )r–   r%   r&   Úkeys  s    z)package_cache.<locals>.package_cache.keysc                s   ˆ   ¡  t|ƒ ¡ ¡ d S )N)r˜   ÚremoverQ   rš   )rZ   r›   )r–   r%   r&   Ú__delitem__  s    z0package_cache.<locals>.package_cache.__delitem__N)r`   ra   rb   r]   rž   r    r%   )r–   r%   r&   Úpackage_cache  s   r¡   )Úcore.package_cache_datar–   Úobject)r¡   r%   )r–   r&   r¡     s    r¡   c             C   s˜   t dtjd tj tj | ¡¡tj tj |¡¡kr:d S trRd}tj	t
|d}n
d}tj}tj tj | |¡¡s†t tj | |¡¡ t| |||ƒ d S )Nz'WARNING: symlink_conda() is deprecated.)ÚfileZcondabin)ÚshellÚbin)ÚprintÚsysÚstderrÚosr|   ÚnormcaseÚnormpathr   Ú	functoolsÚpartialÚwin_conda_bat_redirectÚsymlinkÚisdirÚjoinÚmakedirsÚ_symlink_conda_hlp)r”   Úroot_dirr¥   ÚwhereÚ
symlink_fnr%   r%   r&   Úsymlink_conda  s    (r¸   c       
      C   sÞ   dddg}t j | |¡}t j |¡s.t  |¡ xª|D ]¢}t j |||¡}t j ||¡}y.t j |¡rlt|ƒ t j |¡s‚|||ƒ W q4 ttfk
rÔ }	 z.t j |¡rÂ|	j	t	j
t	jt	jt	jfkrÂn‚ W d d }	~	X Y q4X q4W d S )NrE   ZactivateZ
deactivate)rª   r|   r²   r±   r³   Úlexistsrx   ÚIOErrorÚOSErrorÚerrnoZEPERMZEACCESZEROFSÚEEXIST)
r”   rµ   r¶   r·   ZscriptsZprefix_whereÚfZ	root_fileZprefix_fileÚer%   r%   r&   r´   %  s"    


r´   c          
   C   sH  ddl m} yt tj |¡¡ W nF tk
rh } z(|jtjkrVtj 	tj |¡¡rVn‚ W dd}~X Y nX tj 
|d ¡s¢t|d dƒ}| d|  ¡ W dQ R X |sªd}tj 
|¡sDt|dƒT}| d¡ |  d	¡rø| d
|| d | d ƒ ¡ n| d|| d | ƒ ¡ W dQ R X t |¡j}||d@ d? O }t ||¡ dS )a-  Special function for Windows XP where the `CreateSymbolicLink`
        function is not available.

        Simply creates a `.bat` file at `dst` which calls `src` together with
        all command line arguments.

        Works of course only with callable files, e.g. `.bat` or `.exe` files.
        r   )ÚshellsNz.batÚwz@echo off
call "%s" %%*
zbash.exez#!/usr/bin/env bash 
rE   z%s "$@"Zpath_toz.exezsource %s "$@"i$  é   )ÚutilsrÀ   rª   r³   r|   Údirnamer»   r¼   r½   r±   ÚisfileÚopenÚwriteÚendswithÚstatÚst_modeÚchmod)ÚsrcÚdstr¥   rÀ   Úexcr¾   Úmoder%   r%   r&   r¯   ?  s*    	 

 $r¯   c                s8   ddl m} ddlm‰  || ƒ}‡ fdd„t|jƒD ƒS )z?
    Return a dictionary of the linked packages in prefix.
    r   )Ú
PrefixData)rQ   c                s   i | ]}|ˆ |ƒ“qS r%   r%   )r…   Úprefix_record)rQ   r%   r&   rŠ   s  s    zlinked_data.<locals>.<dictcomp>)Úcore.prefix_datarÐ   Úmodels.distrQ   r   Z_prefix_records)r”   Úignore_channelsrÐ   Úpdr%   )rQ   r&   Úlinked_datal  s    rÖ   c                s:   ddl m} | ¡ ‰ tt| |dƒ}t‡ fdd„|D ƒƒS )z8
    Return the Dists of linked packages in prefix.
    r   )ÚPackageType)rÔ   c             3   s    | ]\}}|j ˆ kr|V  qd S )N)Zpackage_type)r…   r›   Z
prefix_rec)Úconda_package_typesr%   r&   r   }  s    zlinked.<locals>.<genexpr>)Úmodels.enumsr×   rØ   r   rÖ   Úset)r”   rÔ   r×   Zldr%   )rØ   r&   Úlinkedv  s    rÛ   c             C   sH   ddl m} || ƒ}| |jd¡}|dkr.dS t|ƒ |¡r@|S dS dS )z
    Return the install metadata for a linked package in a prefix, or None
    if the package is not linked in the prefix.
    r   )rÐ   N)rÒ   rÐ   r™   Únamer.   Úmatch)r”   r›   rÐ   rÕ   rÑ   r%   r%   r&   Ú	is_linked  s    rÞ   é   c             C   s   t | ||||dS )N)Zmd5Úsha256Úsize)Ú	_download)ZurlZdst_pathZsessionZmd5sumZurlstxtZretriesrà   rá   r%   r%   r&   r    ’  s    r    )rz   T)Nr%   r%   )r%   TNFFNN)FN)N)F)F)NNFrß   NN)²Z
__future__r   r   r   r   Zcollections.abcr   rm   ÚImportErrorÚcollectionsr¼   r­   rª   r¨   rg   Úwarningsr!   Ú r   Zbase.contextr	   r
   Z
core.solver   Z
cli.commonr   r   r   Zcli.conda_argparser   r   r   Úcommonr   Z_compatZcommon.compatr   r   r   r   r   r   r   r   Zgateways.connection.sessionr   Zgateways.disk.creater   Zcommon.toposortr   Zgateways.disk.linkr   Zgateways.connection.downloadr   r    râ   Zhandle_proxy_407r¢   r)   Zgateways.disk.deleter*   r+   Zmiscr,   r-   Zresolver.   r/   r0   r1   ZNoPackagesFoundZNoPackagesFoundErrorrÃ   r2   r3   r4   r5   Zcommon.pathr6   Zgateways.disk.readr7   Zmd5_fileZmodels.versionr8   r9   Zmodels.channelr:   Zconda.base.contextrE   r;   r<   r=   Z_vendor.auxlib.entityr>   Zbase.constantsr?   r@   rA   Zget_default_urlsrB   Z_PREFIX_PLACEHOLDERZprefix_placeholderrF   rG   Z	arch_nameZanaconda_uploadZbinstar_uploadÚbitsZdefault_prefixZdefault_pythonZ	envs_dirsZ	pkgs_dirsr‘   Zroot_prefixrµ   Zroot_writableZsubdirZconda_privateZconda_buildrC   Zget_rc_urlsZget_local_urlsZload_condarcÚ
exceptionsrI   rJ   rK   rL   ZCondaFileNotFoundErrorrM   rÙ   rN   rO   Zmodels.recordsrP   ZIndexRecordrÓ   rQ   Zgateways.subprocessrR   rS   Zcore.subdir_datarT   rU   rV   rW   rX   r£   rY   rc   rd   rx   r{   rÒ   ry   ZKEYSZKEYS_DIRr~   r   r€   r   r‚   rƒ   r„   r‹   Z
core.indexrŒ   r   r•   rŽ   r   r¡   r¸   r´   r¯   rÖ   rÛ   rÞ   r%   r%   r%   r&   Ú<module>   s$  

(








 



 


-


 