
    eOS                         S SK r S SKrS SKrSSKJr  \" \R                  " S5      5      rS rS r	 " S S\
5      r " S	 S
5      r " S S5      rg)    N   )build_re c                 2    [         R                  " SSU 5      $ )Nz([.?*+^$[\]\\(){}|-])z\\\1)resub)strings    1/usr/lib/python3/dist-packages/linkify_it/main.py
_escape_rer      s    66*GV<<    c                 P     U R                  U5      nU$ ! [         a    Sn U$ f = f)N)index
ValueError)textsearch_valueresults      r
   	_index_ofr      s7    L) M  Ms    %%c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )SchemaError   zLinkify schema errorc                 F   > SR                  X5      n[        TU ]	  U5        g )Nz%(LinkifyIt) Invalid schema '{}': '{}')formatsuper__init__)selfnamevalmessage	__class__s       r
   r   SchemaError.__init__   s     9@@K!r    )__name__
__module____qualname____firstlineno____doc__r   __static_attributes____classcell__)r    s   @r
   r   r      s    " "r   r   c                   $    \ rS rSrSrS rS rSrg)Match    a  Match result.

Attributes:
    schema (str): Prefix (protocol) for matched string.
    index (int): First position of matched string.
    last_index (int): Next position after matched string.
    raw (str): Matched string.
    text (str): Notmalized text of matched string.
    url (str): Normalized url of matched string.

Args:
    linkifyit (:class:`linkify_it.main.LinkifyIt`) LinkifyIt object
    shift (int): text searh position
c                     SR                  U R                  R                  U R                  R                  U R                  5      $ )Nz{}.{}({!r}))r   r    r$   r#   __dict__r   s    r
   __repr__Match.__repr__0   s4    ##NN%%t~~'>'>
 	
r   c                     UR                   nUR                  nUR                  X4 nUR                  R	                  5       U l        X2-   U l        XB-   U l        XPl        XPl	        XPl
        g N)_index_last_index_text_cache_schemalowerschemar   
last_indexrawr   url)r   	linkifyitshiftstartendr   s         r
   r   Match.__init__5   s_      ##$$U/''--/]
+	r   )r   r:   r;   r9   r   r<   N)r#   r$   r%   r&   r'   r0   r   r(   r"   r   r
   r+   r+       s    


r   r+   c                       \ rS rSrSrS rS rS rS rS r	S r
S	 rSS jrS rS rS rS rS rS rS rS rSS jrS rS rSrg
)	LinkifyItB   a  Creates new linkifier instance with optional additional schemas.

By default understands:

- ``http(s)://...`` , ``ftp://...``, ``mailto:...`` & ``//...`` links
- "fuzzy" links and emails (example.com, foo@bar.com).

``schemas`` is an dict where each key/value describes protocol/rule:

- **key** - link prefix (usually, protocol name with ``:`` at the end, ``skype:``
  for example). `linkify-it` makes shure that prefix is not preceeded with
  alphanumeric char. Only whitespaces and punctuation allowed.

- **value** - rule to check tail after link prefix

  - *str* - just alias to existing rule
  - *dict*

    - *validate* - either a ``re.Pattern``, ``re str`` (start with ``^``, and don't
      include the link prefix itself), or a validator ``function`` which, given
      arguments *self*, *text* and *pos* returns the length of a match in *text*
      starting at index *pos*. *pos* is the index right after the link prefix.
    - *normalize* - optional function to normalize text & url of matched
      result (for example, for @twitter mentions).

``options`` is an dict:

- **fuzzyLink** - recognige URL-s without ``http(s):`` prefix. Default ``True``.
- **fuzzyIP** - allow IPs in fuzzy links above. Can conflict with some texts
  like version numbers. Default ``False``.
- **fuzzyEmail** - recognize emails without ``mailto:`` prefix.
- **---** - set `True` to terminate link with `---` (if it's considered as long
  dash).

Args:
    schemas (dict): Optional. Additional schemas to validate (prefix/validator)
    options (dict): { fuzzy_link | fuzzy_email | fuzzy_ip: True | False }.
        Default: {"fuzzy_link": True, "fuzzy_email": True, "fuzzy_ip": False}.
c                 l   XS  nU R                   R                  S5      (       d?  SU R                   S   -   U R                   S   -   U R                   S   -   U R                   S'   [         R                  " U R                   S   U[         R                  S9nU(       a  [	        UR                  5       5      $ g)Nhttpz^\/\/src_authsrc_host_port_strictsrc_pathflagsr   r   getsearch
IGNORECASElengroupr   r   postailfoundss        r
   _validate_httpLinkifyIt._validate_httpk   s    Dzww{{6"" ''*%&''012 ''*%& GGFO 4776?DFv||~&&r   c                 (   XS  nU R                   R                  S5      (       dx  SU R                   S   -   S-   U R                   S   -   S-   U R                   S   -   S-   U R                   S	   -   U R                   S
   -   U R                   S   -   U R                   S'   [         R                  " U R                   S   U[         R                  S9nU(       a>  US:  a  XS-
     S:X  a  gUS:  a  XS-
     S:X  a  g[	        UR                  S5      5      $ g)Nnot_http^rG   z(?:localhost|(?:(?:
src_domainz)\.)+src_domain_root)src_portsrc_host_terminatorrI   rJ      :r   /rL   rR   s        r
   _validate_double_slash LinkifyIt._validate_double_slash}   s'   Dzww{{:&& ''*%&'( '','( 	
 ''+,-  ''*%& ''/01 ''*%	& GGJ 477:.BMMJaxDqMS0axDqMS0v||A''r   c                 T   XS  nU R                   R                  S5      (       d2  SU R                   S   -   S-   U R                   S   -   U R                   S'   [         R                  " U R                   S   U[         R                  S9nU(       a  [	        UR                  S5      5      $ g)NmailtorZ   src_email_name@src_host_strictrJ   r   rL   rR   s        r
   _validate_mailtoLinkifyIt._validate_mailto   s    Dzww{{8$$dgg.//#5@Q8RR GGH 4778,d"--Hv||A''r   c                      SU l         SU l        g )Nr   r   )r4   r6   r/   s    r
   _reset_scan_cacheLinkifyIt._reset_scan_cache   s    r   c                    ^ U4S jnU$ )Nc                    > XS  n[        T[        5      (       a%  [        R                  " TU[        R                  S9nO[        R                  " TU5      nU(       a  [        UR                  S5      5      $ g)NrJ   r   )
isinstancestrr   rN   rO   rP   rQ   )r   rS   rT   rU   regexs       r
   func)LinkifyIt._create_validator.<locals>.func   sZ    :D%%%5$bmmD 5$/6<<?++r   r"   )r   rs   rt   s    ` r
   _create_validatorLinkifyIt._create_validator   s    	 r   c                    ^  U 4S jnU$ )Nc                 (   > TR                  U 5        g r3   )	normalize)matchr   s    r
   rt   *LinkifyIt._create_normalizer.<locals>.func   s    NN5!r   r"   )r   rt   s   ` r
   _create_normalizerLinkifyIt._create_normalizer   s    	" r   c                 `    [        X5      nU R                  UR                     S   " U5        U$ )Nrz   )r+   	_compiledr9   )r   r>   r{   s      r
   _create_matchLinkifyIt._create_match   s+    d"u||$[1%8r   Nc                 n   SSSS.U l         SU R                  0SSSU R                  0SU R                  0S.U l        SU l        SR                  S	5      U l        U(       a-  U R                   R                  U5        U R                   U l	        OU R                   U l	        S
U l
        S
U l        SU l        SU l        U(       a-  U R                  R                  U5        U R                  U l        OU R                  U l        0 U l        U R                  U l        SU l        0 U l        U R'                  5         g )NTF)
fuzzy_linkfuzzy_emailfuzzy_ipvalidatehttp:)r   zhttps:zftp:z//mailto:aW  a[cdefgilmnoqrstuwxz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvwxyz]|d[ejkmoz]|e[cegrstu]|f[ijkmor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdeghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eosuw]|s[abcdeghijklmnortuvxyz]|t[cdfghjklmnortvwz]|u[agksyz]|v[aceginu]|w[fs]|y[et]|z[amw]uM   biz|com|edu|gov|net|org|pro|web|xxx|aero|asia|coop|info|museum|name|shop|рф|r   r   )default_optionsrV   rc   rj   default_schemastlds_2ch_src_resplittlds_defaultupdate_optsr4   r5   r7   r6   _schemasr   _tlds_tlds_replacedr   _compile)r   schemasoptionss      r
   r   LinkifyIt.__init__   s%    
 !$"5"56t::;"D$9$9: 
  y lqq
   ''0--DJ--DJ   ''0 00DM 00DM&&
#r   c           	      >  ^  [        T R                  5      T l        [        R                  " T R
                  5      nT R                  5         T R                  (       d  UR                  T R                  5        UR                  T R                  S   5        SR                  U5      T R                  S'   U 4S jnU" T R                  S   5      T R                  S'   U" T R                  S   5      T R                  S'   U" T R                  S	   5      T R                  S
'   U" T R                  S   5      T R                  S'   / n0 T l        T R                  R                  5        GH{  u  pEUc  M  SSS.nUT R                  U'   [        U[        5      (       Ga  [        UR!                  S5      ["        5      (       a$  T R%                  UR!                  S5      5      US'   O[        UR!                  S5      [&        5      (       a$  T R%                  UR!                  S5      5      US'   O[        UR!                  S5      [(        R*                  5      (       a  UR!                  S5      US'   Oi[        UR!                  S5      [(        R,                  5      (       a0  [/        [0        SUR!                  S5      5        T R2                  US'   O[5        XE5      e[        UR!                  S5      [(        R*                  5      (       a  UR!                  S5      US'   O[        UR!                  S5      [(        R,                  5      (       a0  [/        [0        SUR!                  S5      5        T R2                  US'   O5UR!                  S5      (       d  T R7                  5       US'   O[5        XE5      eGMJ  [        U[&        5      (       a  UR                  U5        GMs  [5        XE5      e   U H  nT R                  R!                  T R                  R!                  U5      5      (       d  M>  T R                  T R                  U      S   T R                  U   S'   T R                  T R                  U      S   T R                  U   S'   M     ST R7                  5       S.T R                  S'   SR                  T R                  R                  5        VVs/ s H*  u  pE[9        U5      S:  d  M  U(       d  M  [;        U5      PM,     snn5      nST R                  S   -   S-   U-   S-   n	U	T R                  S'   U	T R                  S'   ST R                  S   -   T R                  S'   SU	-   S-   T R                  S   -   S-   T R                  S '   T R=                  5         gs  snnf )!z Schemas compiler. Build regexps.src_xnr   src_tldsc                 B   > U R                  STR                  S   5      $ )Nz%TLDS%r   )replacer   )tplr   s    r
   untpl!LinkifyIt._compile.<locals>.untpl  s    ;;x)<==r   tpl_email_fuzzyemail_fuzzytpl_link_fuzzy
link_fuzzytpl_link_no_ip_fuzzylink_no_ip_fuzzytpl_host_fuzzy_testhost_fuzzy_testN)r   linkr   rt   rz   )r   rz   r   r   u   (^|(?!_)(?:[><｜]|src_ZPCcz))(r]   schema_testschema_searchrZ   schema_at_start(z)|(z)|@pretest)r   r   r   copydeepcopyr   _on_compiler   appendr   joinr   r   itemsrq   dictrM   RE_TYPErv   rr   types
MethodTypeFunctionTypesetattrrC   rt   r   r}   rP   r   rm   )
r   tldsr   aliasesr   r   compiledaliasslistre_schema_tests
   `         r
   r   LinkifyIt._compile   s    4::& }}TZZ(""KK,,-DGGH%&!hhtn
	> "'tww/@'A!B %dgg.>&? @&+DGG4J,K&L"#%*4773H+I%J!" ,,.ID{$($7H#+DNN4 #t$$cggj17;;+/+A+A#''*BU+VHZ(
 3S99+/+A+A#''*BU+VHZ(
 3U5E5EFF+.77:+>HZ(
 3U5G5GHHIvswwz/BC+/99HZ(%d00cggk2E4D4DEE,/GGK,@H[) 4e6H6HIIIvsww{/CD,0IIH[)--,0,C,C,EH[)%d00#s##t$d((Q /Z E>>%%dmm&7&7&>??04t}}U?S0T1DNN5!*- 26e@T1U2DNN5!+.  +/T=T=T=VWr
  "&!5!5!7!7IDt9q= !%( !
4 !7
 %twwz'::UBUJSP 	
 "0#1 %(477?+C%C!" . 5(4773D+EEM 		 	 -s   V
(V
1V
c                 B    X R                   U'   U R                  5         U $ )a  Add new rule definition. (chainable)

See :class:`linkify_it.main.LinkifyIt` init description for details.
``schema`` is a link prefix (``skype:``, for example), and ``definition``
is a ``str`` to alias to another schema, or an ``dict`` with ``validate`` and
optionally `normalize` definitions. To disable an existing rule, use
``.add(<schema>, None)``.

Args:
    schema (str): rule name (fixed pattern prefix)
    definition (`str` or `re.Pattern`): schema definition

Return:
    :class:`linkify_it.main.LinkifyIt`
)r   r   )r   r9   
definitions      r
   addLinkifyIt.addv  s      !+fr   c                 <    U R                   R                  U5        U $ )a  Override default options. (chainable)

Missed properties will not be changed.

Args:
    options (dict): ``keys``: [``fuzzy_link`` | ``fuzzy_email`` | ``fuzzy_ip``].
        ``values``: [``True`` | ``False``]

Return:
    :class:`linkify_it.main.LinkifyIt`
)r   r   )r   r   s     r
   setLinkifyIt.set  s     	

'"r   c                 t   Xl         SU l        [        U5      (       d  g[        R                  " U R                  S   U[        R
                  S9(       a  U R                  S   nSn[        R                  " X!US [        R
                  S9nU H  nUR                  S5      nUR                  5       UR                  5       S   UR                  5       S   4nU R                  XS	   U5      nU(       d  Mg  US	   U l        UR                  S5      [        US   5      -   U l        UR                  S5      [        US   5      -   U-   U l          O   U R                  R                  S
5      (       Ga  U R                   R                  S5      (       Gae  [        R                  " U R                  S   U[        R
                  S9nU(       a  UR                  S5      n	OSn	U	S:  Ga  U R                  S:  d  XR                  :  a  U R                  R                  S5      (       a  U R                  S   n
OU R                  S   n
[        R                  " X[        R
                  S9nU(       a  UR                  S5      [        UR                  5       S   5      -   nU R                  S:  d  XR                  :  a=  SU l        Xl        UR                  S5      [        UR                  5       5      -   U l        U R                  R                  S5      (       Ga  U R                   R                  S5      (       a  [#        US5      nUS:  a  [        R                  " U R                  S   U[        R
                  S9nU(       a  UR                  S5      [        UR                  5       S   5      -   nUR                  S5      [        UR                  5       5      -   nU R                  S:  d-  XR                  :  d  XR                  :X  a"  XR                  :  a  SU l        Xl        Xl        U R                  S:  $ )zSearches linkifiable pattern and returns ``True`` on success or ``False``
on fail.

Args:
    text (str): text to search

Returns:
    bool: ``True`` if a linkable pattern was found, otherwise it is ``False``.
r   Fr   rJ   r   r   Nr      r   r   r   r   r   r   r   r   r   rh   r   )r6   r4   rP   r   rN   rO   finditerr@   rQ   groupstest_schema_atr7   r?   r5   r   rM   r   r   )r   r   rs   r:   matched_itermatchedmlengthmatched_tldtld_pospatternmlr>   at_posme
next_shifts                   r
   testLinkifyIt.test  s"     4yy99TWW]+TGGGO,EJ;;u:;.?r}}UL'$[[^
]]_gnn&6q&97>>;KA;NO,,TQ4D6#$Q4DL")--"2S1Y">DK'.}}Q'7#ad)'Cf'LD$ ( ::>>,''DNN,>,>w,G,G)))*DK %++A.!|;;?g&;zz~~j11"&'',"7"&''*<"=7FB "c"))+a..A A;;?ekk.A+-DL*/K/1xx{S_/LD,::>>-((T^^-?-?	-J-JtS)F{ YYtww}5t2==QHHQK#biik!n*==E!#!s288:!>J a ;;.![[0ZBRBR5R'0&++5({{ar   c                 r    [         R                  " U R                   S   U[         R                  S9(       a  gg)a*  Very quick check, that can give false positives.

Returns true if link MAY BE can exists. Can be used for speed optimization,
when you need to check that link NOT exists.

Args:
    text (str): text to search

Returns:
    bool: ``True`` if a linkable pattern was found, otherwise it is ``False``.
r   rJ   TF)r   rN   rO   )r   r   s     r
   r   LinkifyIt.pretest  s'     99TWWY'R]]Cr   c                     U R                   R                  UR                  5       5      (       d  gU R                   R                  UR                  5       5      R                  S5      " X5      $ )a"  Similar to :meth:`linkify_it.main.LinkifyIt.test` but checks only
specific protocol tail exactly at given position.

Args:
    text (str): text to scan
    name (str): rule (schema) name
    position (int): length of found pattern (0 on fail).

Returns:
    int: text (str): text to search
r   r   )r   rM   r8   )r   r   r   positions       r
   r   LinkifyIt.test_schema_at  sM     ~~!!$**,//~~!!$**,/33J?OOr   c                    Sn/ nU R                   S:  a<  U R                  U:X  a,  UR                  U R                  U5      5        U R                  nU(       a  XS OUnU R                  U5      (       aT  UR                  U R                  U5      5        X@R                  S nX R                  -  nU R                  U5      (       a  MT  [        U5      (       a  U$ g)aY  Returns ``list`` of found link descriptions or ``None`` on fail.

We strongly recommend to use :meth:`linkify_it.main.LinkifyIt.test`
first, for best speed.

Args:
    text (str): text to search

Returns:
    ``list`` or ``None``: Result match description:
        * **schema** - link schema, can be empty for fuzzy links, or ``//``
          for protocol-neutral  links.
        * **index** - offset of matched text
        * **last_index** - offset of matched text
        * **raw** - offset of matched text
        * **text** - normalized text
        * **url** - link, generated from matched text
r   N)r4   r6   r   r   r5   r   rP   )r   r   r>   r   rT   s        r
   r{   LinkifyIt.match	  s    &  ;;! 0 0D 8MM$,,U34$$E  %tF|$ iiooMM$,,U34((*+D%%%E	 iioo v;;Mr   c                 <   Xl         SU l        [        U5      (       d  g[        R                  " U R                  S   U[        R
                  S9nU(       d  gUR                  5       UR                  5       S   UR                  5       S   4nU R                  XS   [        US   5      5      nU(       d  gUS   U l	        UR                  S5      [        US   5      -   U l        UR                  S5      [        US   5      -   U-   U l        U R                  S5      $ )zReturns fully-formed (not fuzzy) link if it starts at the beginning
of the string, and null otherwise.

Args:
    text (str): text to search

Retuns:
    ``Match`` or ``None``
r   Nr   rJ   r   r   r   )r6   r4   rP   r   rN   rO   rQ   r   r   r7   r?   r5   r   )r   r   rU   r   r   s        r
   match_at_startLinkifyIt.match_at_start3  s      4yy477#45t2==Q\\^V]]_Q/1CD$$TQ4QqT;tll1oAaD	1!<<?S1Y6?!!!$$r   c                 2   [        U[        5      (       a  UOU/nU(       d  X0l        SU l        U R	                  5         U $ U R                  R                  U5        [        [        [        U R                  5      5      SS9U l        U R	                  5         U $ )u1  Load (or merge) new tlds list. (chainable)

Those are user for fuzzy links (without prefix) to avoid false positives.
By default this algorythm used:

* hostname with any 2-letter root zones are ok.
* biz|com|edu|gov|net|org|pro|web|xxx|aero|asia|coop|info|museum|name|shop|рф
  are ok.
* encoded (`xn--...`) root zones are ok.

If list is replaced, then exact match for 2-chars root zones will be checked.

Args:
    list_tlds (list or str): ``list of tlds`` or ``tlds string``
    keep_old (bool): merge with current list if q`True`q (q`Falseq` by default)
T)reverse)rq   listr   r   r   extendsortedr   )r   	list_tldskeep_old_lists       r
   r   LinkifyIt.tldsS  sr    " (	488	ykJ"&DMMOK

% DTZZ14@
r   c                     UR                   (       d  SUR                  -   Ul        UR                   S:X  aI  [        R                  " SUR                  [        R                  S9(       d  SUR                  -   Ul        ggg)zyDefault normalizer (if schema does not define it's own).

Args:
    match (:class:`linkify_it.main.Match`): Match result
zhttp://r   z^mailto:rJ   N)r9   r<   r   rN   rO   )r   r{   s     r
   rz   LinkifyIt.normalizer  s[     ||!EII-EI<<9$RYY		.
 "EII-EI.
$r   c                     g)z"Override to modify basic RegExp-s.Nr"   r/   s    r
   r   LinkifyIt._on_compile  s    r   )r   r4   r5   r   r7   r   r6   r   r   r   r   r   r   r   )NN)F)r#   r$   r%   r&   r'   rV   rc   rj   rm   rv   r}   r   r   r   r   r   r   r   r   r{   r   r   rz   r   r(   r"   r   r
   rC   rC   B   so    &P$> 
0dy!v(L \"P"(T%@>.r   rC   )r   r   r   ucrer   typecompiler   r   r   	Exceptionr   r+   rC   r"   r   r
   <module>r      sR     	   rzz#
=") " D@	 @	r   