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>,)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?   s8   


rD   r4   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)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   |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   ?   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"      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).
        )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-      s    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   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   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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)rL   r   N)ZhttpZhttps)Zschemehostportpath)
r   r   r2   r&   r   r#   r   r%   r   r   )rJ   rf   re   rg   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   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>   sZ   
(

. -+
	
