a
    V_'%                     @   s  d Z ddlmZ zddlZ[W n$ eyB   ddlmZ dZY nr0 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 e0y>   e1Z/Y n0 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 sg } tttd}t|}tdd |D dd}t| |D ]}|\}}}|dkrZqB|d dd	}t|d	kr|	|d  d
d |D \}	}
t
|	|
d	 D ]}|tkr qB| 	t| qqBW d   n1 s0    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   3lib/python3.9/site-packages/hyperlink/hypothesis.py	<genexpr>Q       z"idna_characters.<locals>.<genexpr>,)Z	delimiterZ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)resultZdataFileNameZdataFiler   rowZcodesZpropdescriptionZstartEndstartendr3   r   r   r,   idna_characters?   s2    

0
rD   r4   c                 C   sj   t  }|dksJ |dur&|dks&J tt| t|||d}zt| W n tyd   td Y n0 |S )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)rD   r   r   r   idna_encoder   r   )drawrF   rG   rH   r?   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_valueZ	max_value)r   r2   r   )rJ   
allow_zerorK   r   r   r,   r&      s    r&   Tc              	   C   s   |rft t| tddd}z|d W q tyb   t|ddtd kr^|dd }q6Y q0 n$t t| tddttt d	 d
}zt	| W n t
y   td Y n0 |S )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   ?   rF   rG   asciiZpunycodezxn--Nr0   rE   F)r   r   r$   r   UnicodeEncodeErrorr;   r   r   r	   r   UnicodeErrorr   )rJ   	allow_idnlabelr   r   r,   r"      s,    	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rz|d
d }qJd|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).
        )rS   c                    s    rdS | d t vS )NTr   )r	   )lallow_leading_digitr   r,   <lambda>   s    zhostnames.<locals>.<lambda>r      rN   c                 s   s   | ]}t |V  qd S )N)r;   )r*   rT   r   r   r,   r-      r.   zhostnames.<locals>.<genexpr>   NrP   .)	r   r   r"   filterr   r   sumr;   r   )rJ   rW   rS   labelsr   rV   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   sP   t tD ]B} t| }|dv rqz|d W n tyB   Y qY n0 |V  qd S )Nz#/?r(   )r=   r
   r>   r   rQ   )r3   cr   r   r,   chars  s    
zpath_characters.<locals>.charsr4   )_path_charactersr   )r`   r   r   r,   path_characters   s    rb   c                 C   s$   t tt | ttdt dddS )Nr   )rF   rH   
   )rG   )r   r   r   r   r   rb   rJ   r   r   r,   r%     s    r%   c                 C   sf   t tt | tdd}t t| t }t tt | t }|dkrHd}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)rL   r   N)httphttps)schemehostportpath)
r   r   r2   r&   r   r#   r   r%   r   r   )rJ   ri   rh   rj   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!   rd   r   r   r,   r    9  s    r    )r   N)F)T)TT)=__doc__Z
__future__r   Z
hypothesisImportErrortypingr   __all__Zcsvr   r8   Zos.pathr   r   stringr   r	   sysr
   r   r   r   r   r   r   r   r   gzipr   r7   r4   r   r   r   Zhypothesis.strategiesr   r   r   r   r   Zidnar   r   r   rI   r'   ZDrawCallabler>   	NameErrorchrrD   r5   r$   r&   r"   r#   rb   ra   r%   r!   r    r   r   r   r,   <module>   sT   (


. -+
	
