B
    XM\Ü  ã               @   sÂ   d dl mZmZmZ d dlZd dlZd dlmZ d dlm	Z	 d 
¡ Ze d¡Ze d¡Ze d¡Ze d	¡Ze d
e ej¡ ¡Zdd„ Zdd„ Zdd„ Zdefdd„Zdefdd„Zdd„ ZdS )é    )Úabsolute_importÚdivisionÚprint_functionN)Ú
exceptions)Ú
comma_joinzT
AGPL
LGPL
GPL3
GPL2
GPL
BSD
MIT
APACHE
PSF
CC
PUBLIC-DOMAIN
PROPRIETARY
OTHER
NONE
z	GPL[^3]*2z	GPL[^2]*3zGPL[^2]*>= *2zCC\w+z[%s]c             C   s   t  | ¡pt | ¡S )z3True if family matches GPL3 or GPL >= 2, else False)Úgpl23_regexÚsearchÚ
gpl3_regex)Úfamily© r   ú9lib/python3.7/site-packages/conda_build/license_family.pyÚ
match_gpl3!   s    
r   c             C   s:   |   ¡ } t dd| ¡} t dd| ¡} t dd| ¡} |  ¡ S )z7Set to ALL CAPS, replace common GPL patterns, and stripzGENERAL PUBLIC LICENSEZGPLzLESSER *ÚLzAFFERO *ÚA)ÚupperÚreÚsubÚstrip)Úsr   r   r   Ú	normalize'   s
    r   c             C   s   t  d| ¡} t dd| ¡} | S )z0Remove punctuation, spaces, tabs, and line feedsú z\s+Ú )Ú
punk_regexr   r   )r   r   r   r   Úremove_special_characters0   s    r   c             C   s,   t | tƒr|  d|  d¡¡}n| }t||ƒS )z—Return best guess of license_family from the conda package index.

    Note: Logic here is simple, and focuses on existing set of allowed families
    Úlicense_familyÚlicense)Ú
isinstanceÚdictÚgetÚguess_license_family)ÚindexÚ
recognizedÚlicense_namer   r   r   Úguess_license_family_from_index7   s    
r#   c             C   s’   | dkrdS t | ƒ} t dd| ¡}t|ƒr.dS t |¡r<dS t | ¡rJdS t| ƒ} x|D ]}t|ƒ| krX|S qXW x|D ]}| t|ƒkrv|S qvW dS )	z—Return best guess of license_family from the conda package index.

    Note: Logic here is simple, and focuses on existing set of allowed families
    NZNONEz[A,L]GPLr   ZGPL3ZGPL2ZCCZOTHER)r   r   r   r   Ú
gpl2_regexr   Úcc_regexr   )r"   r!   Z	sans_lgplr
   r   r   r   r   F   s$    



r   c             C   sf   y| d d }W n t k
r$   d S X dd„ tD ƒ}tt|ƒƒ|krbtt d|tttƒƒf ¡ƒ‚d S )NZaboutr   c             S   s   g | ]}t t|ƒƒ‘qS r   )r   r   )Ú.0Zfamr   r   r   ú
<listcomp>k   s   z/ensure_valid_license_family.<locals>.<listcomp>z?about/license_family '%s' not allowed. Allowed families are %s.)	ÚKeyErrorÚallowed_license_familiesr   r   ÚRuntimeErrorr   Úindentr   Úsorted)Úmetar   Zallowed_familiesr   r   r   Úensure_valid_license_familyf   s    r.   )Z
__future__r   r   r   r   ÚstringZconda_buildr   Zconda_build.utilsr   Úsplitr)   Úcompiler$   r	   r   r%   ÚescapeZpunctuationr   r   r   r   r#   r   r.   r   r   r   r   Ú<module>   s$   



	