
    G_'%                        d Z ddlmZ 	 ddlZ[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,	 e- d Z0da1e dd       Z2e dd       Z3e d d       Z4e d!d       Z5d Z6da7e d        Z8e d        Z9e d        Z:y# e.$ r e/Z-Y Pw xY w# e;$ r ddlm<Z< dZ*Y yw xY w)"z
Hypothesis strategies.
    )absolute_importN)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                     t         sg } t        t        t              d      }t	        |      5 }t        d |D        d      }t        |       |D ]  }|\  }}}|dk7  r|d   j                  dd      }t        |      dk(  r|j                  |d          d	 |D        \  }	}
t        |	|
dz         D ]'  }|t        kD  r o| j                  t        |             )  	 d
d
d
       dj                  |       a t         S # 1 sw Y    xY w)z>
        Returns a string containing IDNA characters.
        zidna-tables-properties.csv.gzc              3   >   K   | ]  }|j                  d         yw)utf-8N)decode).0lines     6/usr/lib/python3/dist-packages/hyperlink/hypothesis.py	<genexpr>z"idna_characters.<locals>.<genexpr>Q   s     ?dT[[)?s   ,)	delimiterPVALIDr   -r   c              3   4   K   | ]  }t        |d         yw)   N)int)r+   is     r-   r.   z"idna_characters.<locals>.<genexpr>b   s     !?#a*!?s   N )_idnaCharactersr   r   __file__	open_gzip
csv_readernextsplitlenappendranger	   unichr)resultdataFileNamedataFiler   rowcodespropdescriptionstartEndstartendr6   s               r-   idna_charactersrL   ?   s    F
  !#BL <( 1H#?h?! V! 1C/2,E4x' !"1v||C3H8}) 4!?h!?JE3"5#'2 1z>!fQi01114 "hhv.O91 1s   B/C<<Dr7   c           
          t               }|dk\  sJ ||dk\  sJ t        t         | t        |||                  }	 t	        |       |S # t
        $ r t        d       Y |S w xY 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   min_sizemax_sizealphabetF)rL   r   r   r   idna_encoder   r   )drawrO   rP   rQ   rB   s        r-   r#   r#   o   sy     #$1}}q= =x(XNO
	   	5M	s   A A#"A#c           	      R    |rd}nd}t        t         | t        |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   r5   r   )rS   
allow_zerorU   s      r-   r%   r%      s*     IICheLMNN    c                     |r4t        t         | t        dd                  }	 |j                  d       n9t        t         | t        ddt        t        t        z   d	z         
                  }	 t        |       |S # t        $ r[ t        |j                  d            dt        d      z
  kD  r/|dd }t        |j                  d            dt        d      z
  kD  r/Y qw xY w# t        $ r t        d       Y |S w xY 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   ?   rO   rP   asciipunycodezxn--Nr2   rN   F)r   r   r#   r   UnicodeEncodeErrorr>   r   r   r   r   UnicodeErrorr   )rS   	allow_idnlabels      r-   r!   r!      s     tIq2$FGHE
'W% !"!#!%mf&<t&C!D	E	 = & ' %,,z23b3v;6FF "#2JE	 %,,z23b3v;6FF	'6  	5M	s$   A> 1C% >A C"!C"%C=<C=c                    t        t         | t        |      j                  fd                  g}|t        t        t            | t        t        |      dd                  z  }t        d |D              t        |      z   dz
  dkD  r*|dd	 }t        d |D              t        |      z   dz
  dkD  r*d
j                  |      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).
        )ra   c                 "    rdS | d   t         vS )NTr   )r   )lallow_leading_digits    r-   <lambda>zhostnames.<locals>.<lambda>   s    $7D =>qT=O rX   r      r[   c              3   2   K   | ]  }t        |        y w)N)r>   )r+   rb   s     r-   r.   zhostnames.<locals>.<genexpr>   s     1#e*1s      Nr^   .)	r   r   r!   filterr   r   sumr>   r   )rS   rf   ra   labelss    `  r-   r"   r"      s     #i8??	
 	$J#i8	
 		
 1&11CK?!CcICR[F 1&11CK?!CcI yy  rX   c                  L    t         d } dj                   |              a t         S )zH
        Returns a string containing valid URL path characters.
        c               3      K   t        t              D ](  } t        |       }|dv r	 |j                  d       | * y # t        $ r Y 7w xY ww)Nz#/?r)   )r@   r	   rA   r   r_   )r6   cs     r-   charszpath_characters.<locals>.chars  sZ     z* Aq	A Ez !) G . ! !s%   #A>A	A
A	A

Ar7   )_path_charactersr   )rr   s    r-   path_charactersrt      s(     #"  "wwuw/rX   c                 x    t        t        t            | t        t	        dt                     d                  S )Nr   )rO   rQ   
   )rP   )r   r   r   r   r   rt   rS   s    r-   r$   r$     s4     JdA0ABRP
 	
rX   c           
      <   t        t        t            | t        d                  }t        t         | t                           }t        t        t            | t                           }|dk(  rd}t        t        t         | t        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)rW   r   N)httphttps)schemehostportpath)
r   r   r5   r%   r   r"   r   r$   r   r   )rS   r}   r|   r~   s       r-   r    r    #  s~     HSM4(E#FGD$y{+,HTNDM219Dd<0C#DEF	
 	
rX   c                 4    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    rw   s    r-   r   r   9  s     $|~.//rX   )Tuple )r   N)F)T)TT)=__doc__
__future__r   
hypothesiscsvr   r;   os.pathr   r   stringr   r   sysr	   typingr
   r   r   r   r   r   r   r   gzipr   r:   r7   r   r   r   hypothesis.strategiesr   r   r   r   r   idnar   r   r   rR   __all__r&   DrawCallablerA   	NameErrorchrrL   r8   r#   r%   r!   r"   rt   rs   r$   r    r   ImportErrorr   r   rX   r-   <module>r      sb   'z0 )%,	 	 	 '(!  CBG 	AXc1f-.12L,\ O @ O O + +Z )! )!V < 
 
 
 
* 0 0}  c  Gs#   C C CCC)(C)