o
    Gï÷_'%  ã                   @   s¶  d Z ddlmZ zddlZ[W n ey!   ddlmZ dZY dS w ddlm	Z
 ddlmZmZ ddlmZmZ dd	lmZ dd
lmZmZmZmZmZmZmZmZ ddlmZ ddlmZm Z  ddlm!Z! ddl"m#Z#m$Z$m%Z%m&Z&m'Z' ddl(m)Z)m*Z*m+Z, dZedƒZ-eede-f ge-f Z.ze/ W n e0yž   e1Z/Y nw dd„ Z2da3e#d)dd„ƒZ4e#d*dd„ƒZ5e#d+dd„ƒZ6e#d,dd „ƒZ7d!d"„ Z8da9e#d#d$„ ƒZ:e#d%d&„ ƒZ;e#d'd(„ ƒZ<dS )-z
Hypothesis strategies.
é    )Úabsolute_importN)ÚTuple© )Úreader)ÚdirnameÚjoin)Úascii_lettersÚdigits)Ú
maxunicode)ÚCallableÚIterableÚListÚOptionalÚSequenceÚTextÚTypeVarÚcast)Úopené   )Ú
DecodedURLÚ
EncodedURL)Úassume)Ú	compositeÚintegersÚlistsÚsampled_fromÚtext)Ú	IDNAErrorÚcheck_labelÚencode)Údecoded_urlsÚencoded_urlsÚhostname_labelsÚ	hostnamesÚ	idna_textÚpathsÚport_numbersÚT.c                  C   sò   t swg } tttƒdƒ}t|ƒ�[}tdd„ |D ƒdd�}t|ƒ |D ]A}|\}}}|dkr-q!|d  dd	¡}t|ƒd	krB| 	|d ¡ d
d„ |D ƒ\}	}
t
|	|
d	 ƒD ]}|tkrZ n|  	t|ƒ¡ qRq!W d  ƒ n1 smw   Y  d | ¡a t S )z>
        Returns a string containing IDNA characters.
        zidna-tables-properties.csv.gzc                 s   s   � | ]}|  d ¡V  qdS )úutf-8N)Údecode)Ú.0Úliner   r   ú6/usr/lib/python3/dist-packages/hyperlink/hypothesis.pyÚ	<genexpr>Q   ó   € z"idna_characters.<locals>.<genexpr>ú,)Ú	delimiterÚPVALIDr   ú-r   c                 s   s   � | ]}t |d ƒV  qdS )é   N)Úint)r*   Úir   r   r,   r-   b   r.   NÚ )Ú_idnaCharactersr   r   Ú__file__Ú	open_gzipÚ
csv_readerÚnextÚsplitÚlenÚappendÚranger
   Úunichr)ÚresultÚdataFileNameÚdataFiler   ÚrowÚcodesÚpropÚdescriptionÚstartEndÚstartÚendr5   r   r   r,   Úidna_characters?   s8   ÿ
þ
€îú
rK   r6   c                 C   sj   t ƒ }|dks	J ‚|dur|dksJ ‚tt| t|||d�ƒƒ}zt|ƒ W |S  ty4   tdƒ Y |S w )a(  
        A strategy which generates IDNA-encodable text.

        @param min_size: The minimum number of characters in the text.
            C{None} is treated as C{0}.

        @param max_size: The maximum number of characters in the text.
            Use C{None} for an unbounded size.
        r   N©Úmin_sizeÚmax_sizeÚalphabetF)rK   r   r   r   Úidna_encoder   r   )ÚdrawrM   rN   rO   rA   r   r   r,   r$   o   s   þ
ý
ýr$   Fc                 C   s$   |rd}nd}t t| t|dd�ƒƒS )z†
        A strategy which generates port numbers.

        @param allow_zero: Whether to allow port C{0} as a possible value.
        r   r   iÿÿ  )Ú	min_valueÚ	max_value)r   r4   r   )rQ   Ú
allow_zerorR   r   r   r,   r&   �   s   r&   Tc              	   C   sÌ   |r>t t| tddd�ƒƒ}z| d¡ W n; ty=   t| d¡ƒdtdƒ kr;|dd… }t| d¡ƒdtdƒ ks(Y nw t t| tddttt d	 ƒd
�ƒƒ}zt	|ƒ W |S  t
ye   tdƒ Y |S w )zÀ
        A strategy which generates host name labels.

        @param allow_idn: Whether to allow non-ASCII characters as allowed by
            internationalized domain names (IDNs).
        r   é?   ©rM   rN   ÚasciiÚpunycodezxn--Néÿÿÿÿr2   rL   F)r   r   r$   r   ÚUnicodeEncodeErrorr=   r   r   r	   r   ÚUnicodeErrorr   )rQ   Ú	allow_idnÚlabelr   r   r,   r"   Ÿ   s6   	ü€üýÿþ
ý
ýr"   c              	      s¤   t t| t|d� ‡ fdd„¡ƒƒg}|t tt | tt|d�ddd�ƒƒ7 }tdd„ |D ƒƒt|ƒ d d	krM|d
d… }tdd„ |D ƒƒt|ƒ d d	ks6d |¡S )aD  
        A strategy which generates host names.

        @param allow_leading_digit: Whether to allow a leading digit in host
            names; they were not allowed prior to RFC 1123.

        @param allow_idn: Whether to allow non-ASCII characters as allowed by
            internationalized domain names (IDNs).
        )r\   c                    s   ˆ rdS | d t vS )NTr   )r	   )Úl©Úallow_leading_digitr   r,   Ú<lambda>ß   s   zhostnames.<locals>.<lambda>r   é   rV   c                 s   s   � | ]}t |ƒV  qd S )N)r=   )r*   r]   r   r   r,   r-   ô   s   € zhostnames.<locals>.<genexpr>éü   NrY   Ú.)	r   r   r"   Úfilterr   r   Úsumr=   r   )rQ   r`   r\   Úlabelsr   r_   r,   r#   Í   s.   

ÿÿþÿýÿþ""ÿ
r#   c                  C   s    t du rdd„ } d | ƒ ¡a t S )zH
        Returns a string containing valid URL path characters.
        Nc               	   s   sN   � t tƒD ]} t| ƒ}|dv rqz| d¡ W n	 ty    Y qw |V  qd S )Nz#/?r(   )r?   r
   r@   r   rZ   )r5   Úcr   r   r,   Úchars  s   €ÿózpath_characters.<locals>.charsr6   )Ú_path_charactersr   )ri   r   r   r,   Úpath_charactersù   s   rk   c                 C   s$   t tt | ttdtƒ d�dd�ƒƒS )Nr   )rM   rO   é
   )rN   )r   r   r   r   r   rk   ©rQ   r   r   r,   r%     s   ÿþr%   c                 C   sf   t tt | tdd�ƒƒ}t t| tƒ ƒƒ}t tt | tƒ ƒƒ}|dkr$d}tt t| t	dƒƒƒ|||d�S )z£
        A strategy which generates L{EncodedURL}s.
        Call the L{EncodedURL.to_uri} method on each URL to get an HTTP
        protocol-friendly URI.
        T)rT   r   N)ÚhttpÚhttps)ÚschemeÚhostÚportÚpath)
r   r   r4   r&   r   r#   r   r%   r   r   )rQ   rr   rq   rs   r   r   r,   r!   #  s   ür!   c                 C   s   t | tƒ ƒƒS )z£
        A strategy which generates L{DecodedURL}s.
        Call the L{EncodedURL.to_uri} method on each URL to get an HTTP
        protocol-friendly URI.
        )r   r!   rm   r   r   r,   r    9  s   r    )r   N)F)T)TT)=Ú__doc__Ú
__future__r   Ú
hypothesisÚImportErrorÚtypingr   Ú__all__Úcsvr   r:   Úos.pathr   r   Ústringr   r	   Úsysr
   r   r   r   r   r   r   r   r   Úgzipr   r9   r6   r   r   r   Úhypothesis.strategiesr   r   r   r   r   Úidnar   r   r   rP   r'   ÚDrawCallabler@   Ú	NameErrorÚchrrK   r7   r$   r&   r"   r#   rk   rj   r%   r!   r    r   r   r   r,   Ú<module>   sZ   
ý(

ÿ. -+
	
