a
    &0_                     @   s   d dl mZ d dlZd dlZddlmZ dZdddd	d
dddZzddlm	Z	 e	j
ZW n eyh   Y n0 dejv rxdZejd  dkrdejv rejd dZnejdeZdd ZddddddZdddddZdd Zdd Zd d! Zd$d"d#ZdS )%    )absolute_importN   )getattr   allow)cextN)r   pure)cffiN)r   r   )Nr   )   cr      cffis
   cffi-allows   pys   rust+cs   rust+c-allow)__modulepolicy__Z__pypy__r
      ZHGMODULEPOLICYzutf-8c                 C   sd   i }t | t ||gdd}zt|| ||< }W n tyN   td| Y n0 t|dd  || S )Nr   )levelzcannot import name %s__doc__)
__import__globalsr   AttributeErrorImportError)pkgnamemodnameZ
fakelocalspkgmod r   2/usr/lib/python3/dist-packages/mercurial/policy.py_importfrom@   s    r         ))r   base85)r   Zbdiff)r   Zmpatch)r   Zosutilr   parsersr   )r   r   )r   
charencode)r   r   ))r   r   )r   r   )r   r   )r   r   c                 C   s:   t | |f}t|dd }||kr6td| |||f d S )Nversionz=cannot import module %s.%s (expected version: %d, actual: %r))_cextversionsgetr   r   )r   r   r   ZexpectedZactualr   r   r   	_checkmod_   s    
r#   c                 C   s   zt t \}}W n ty.   tdt Y n0 |s<|s<J |rt|| f|| f\}}z$t||}||krxt||| |W S  ty   |s Y n0 t|| f|| f\}}t||S )z7Import module according to policy and check API versionzinvalid HGMODULEPOLICY %r)_packageprefspolicyKeyErrorr   _modredirectsr"   r   r#   )r   ZverpkgZpurepkgZpnZmnr   r   r   r   	importmodj   s"    
r(   c                   C   s
   t dS )z;Assuming the policy is a Rust one, tell if it's permissive.s   -allow)r%   endswithr   r   r   r   _isrustpermissive   s    r*   c                 C   s   t ds|S ztd| }W n" ty>   t r8| Y S  Y n0 |du rL|S zt||W S  ty   t rt| Y S td| Y n0 dS )a  Import Rust module according to policy and availability.

    If policy isn't a Rust one, this returns `default`.

    If either the module or its member is not available, this returns `default`
    if policy is permissive and raises `ImportError` if not.
    s   rustZrustextNzCannot import name %s)r%   
startswithr   r   r*   r   r   )r   memberdefaultr   r   r   r   
importrust   s     
r.   )NN)Z
__future__r   ossysZpycompatr   r%   r$    r   Zmodulepolicyr   builtin_module_namesversion_infoenvironencoder"   r   r!   r'   r#   r(   r*   r.   r   r   r   r   <module>   sN   



