
    	iW!                     d    d dl Z d dlmZ d dlmZmZmZ  G d de          Z G d d          ZdS )    N)Enum)AnyDictOptionalc                   "    e Zd ZdZdZdZdZdZdS )UrlTypesz4
    Enum to represent different types of URLS.
    r            N)__name__
__module____qualname____doc__UNKNOWNURLINTERNALEXTERNAL     F/srv/django_bis/venv311/lib/python3.11/site-packages/xlsxwriter/url.pyr   r      s.          G
CHHHHr   r   c                   n   e Zd ZdZdZdZdeddfdZdefdZe	d	e
eef         ded          fd
            Zedefd            Zej        deddfd            Zedefd            Zej        deddfd            ZddZddZddZdefdZdefdZededefd            Zededefd            ZdS )Urlz.
    A class to represent URLs in Excel.

    i      linkreturnNc                    t           j        | _        || _        || _        || _        d| _        d| _        d| _        d| _	        d| _
        |                                  t          | j                  | j        k    rt          d          t          | j                  | j        k    rt          d          t          | j                  | j        k    rt          d          |                                  d S )N Fr   z#URL exceeds Excel's maximum length.z5Anchor segment or url exceeds Excel's maximum length.z2Hyperlink tool tip exceeds Excel's maximum length.)r   r   
_link_type_original_url_link_relationship_link_text_tip_anchor_is_object_link
_rel_index
_parse_urllenMAX_URL_LEN
ValueErrorMAX_PARAMETER_LEN_escape_strings)selfr   s     r   __init__zUrl.__init__$   s    $,$4"&
'+
	%* tz??T---BCCCt|t///TUUUty>>D222QRRRr   c                     d| j         j         d| j         d| j         d| j         d| j         d| j         d| j         d| j         d	| j	         d
S )zF
        Return a string representation of the Url instance.

        z
Url:
  _link_type         = z
  _original_url      = z
  _link              = z
  _relationship_link = z
  _text              = z
  _tip               = z
  _anchor            = z
  _is_object_link    = z
  _rel_index         = 
)
r   namer   r    r!   r"   r#   r$   r%   r&   r-   s    r   __repr__zUrl.__repr__<   s    
:&*o&:
: 
: '+&8
: 
: '+j	
: 
:
 '+&=
: 
: '+j
: 
: '+i
: 
: '+l
: 
: '+&:
: 
: '+o
: 
: 
:	
r   optionsc                    t          |t                    st          d          |                    d          }t          |t                    r3 | |d                   }|                    d          r|d         |_        |S )aM  
        For backward compatibility, convert the 'url' key and 'tip' keys in an
        options dictionary to a Url object, or return the Url object if already
        an instance.

        Args:
            options (dict): A dictionary that may contain a 'url' key.

        Returns:
            url: A Url object or None.

        z-The 'options' parameter must be a dictionary.urltip)
isinstancedict	TypeErrorgetstrr#   )clsr4   r6   s      r   from_optionszUrl.from_optionsO   s     '4(( 	MKLLLkk%  c3 	*#gen%%C{{5!! *"5>
r   c                     | j         S )z5Get the alternative, user-friendly, text for the URL.r"   r2   s    r   textzUrl.texti   s     zr   valuec                     || _         dS )z5Set the alternative, user-friendly, text for the URL.Nr@   r-   rB   s     r   rA   zUrl.textn   s     


r   c                     | j         S )zGet the screen tip for the URL.r#   r2   s    r   r7   zUrl.tips   s     yr   c                     || _         dS )zSet the screen tip for the URL.NrF   rD   s     r   r7   zUrl.tipx   s     			r   c                 <   | j                             d          r=t          j        | _        | j        s#| j                             ddd          | _        dS dS | j                             d          rvt          j        | _        | j                             ddd          | _        | j                             ddd          | _         | j         | _	        | j        s| j	        | _        dS dS | j                             d          s| j                             d          rit          j
        | _        | j                            ddd          }|}|                    ddd          }|                    ddd          }|                    d	d
          }|                     |          r|| _         n
d|z   | _         | j        s|| _        d| j         v r(| j                             dd          \  | _         | _	        | j        r>|                     |          r!| j                             d
d	          | _        n|| _        n| j         | _        | j                            d          r#| j                            ddd          | _        dS dS d| j         v rxt          j        | _        | j        s| j         | _        d| j         v r(| j                             dd          \  | _         | _	        | j        r| j        | _        dS | j         | _        dS t          d| j                   )z%Parse the URL and determine its type.zmailto:r   r	   z	internal:#zfile://z	external:zfile:////\z.\z://zUnknown URL type: N)r    
startswithr   r   r   r"   replacer   r!   r$   r   r   _is_relative_pathsplitr%   r*   )r-   file_url	link_paths      r   r'   zUrl._parse_url}   s4    :  ++ I	H&lDO: B!Z//	2qAA


B B Z"";// B	H&/DO&*j&8&8c1&M&MD#++KQ??DJ:DL: *!\


* * Z""9-- 8	H1F1F{1S1S 8	H&/DO )11+z1MMH I!))*b!<<I!)))R;;I!))#t44I%%i00 4&

')3
: '&
dj  +/:+;+;C+C+C(
DL # 5)))44 7.2j.@.@s.K.KD++.6D++ +/*' &11%88 X*.*A*I*I%QSUV*W*W'''X X
 dj  &lDO: (!Z
dj  +/:+;+;C+C+C(
DL # 5*.*<'''*.*''' F$2DFFGGGr   c                 |    d| _         | j        | _        |                                  |                                  dS )z
        Set the _is_object_link flag and re-parse the URL since the relationship
        link is different for object links.

        TN)r%   r   r    r'   r,   r2   s    r   _set_object_linkzUrl._set_object_link   s>      $'
r   c                    | j         t          j        k    r>|                     | j                  | _        |                     | j                  | _        | j         t          j        k    r"| j                            dd          | _        dS dS )z-Escape special characters in the URL strings.rI   z%23N)r   r   r   _escape_urlr    r!   r   rM   r2   s    r   r,   zUrl._escape_strings   s     ?h///))$*55DJ&*&6&6t7N&O&OD# ?h///&*&=&E&Ec5&Q&QD### 0/r   c                     | j         S )z$Get the target for relationship IDs.)r!   r2   s    r   _targetzUrl._target   s    &&r   c                 4    | j         t          j        k    rdS dS )z)Get the target mode for relationship IDs.r   External)r   r   r   r2   s    r   _target_modezUrl._target_mode   s    ?h///2zr   r6   c                     |                      d          rdS | d                                         r| d         dk    rdS dS )z"Check if a URL is a relative path.z\\Fr   r	   :T)rL   isalphar6   s    r   rN   zUrl._is_relative_path   sI     >>%   	5q6>> 	A#5tr   c                    t          j        d|           r| S |                     dd                              dd                              dd                              dd	                              d
d                              dd                              dd                              dd                              dd                              dd                              dd          S )z#Escape special characters in a URL.z%[0-9a-fA-F]{2}%z%25"z%22 z%20<z%3c>z%3e[z%5b]z%5d^z%5e`z%60{z%7b}z%7d)researchrM   r^   s    r   rU   zUrl._escape_url   s     9&,, 	J KKU##WS%  WS%  WS%  WS%  WS%  WS%  WS%  WS%  WS%  WS%  	
r   )r   N)r   r   r   r   r)   r+   r<   r.   r3   classmethodr   r   r   r>   propertyrA   setterr7   r'   rS   r,   rW   rZ   staticmethodboolrN   rU   r   r   r   r   r      s+        
 KS T    0
# 
 
 
 
& 4S> huo    [2 c    X 
[# $    [ S    X 	Z     ZMH MH MH MH^	 	 	 		R 	R 	R 	R' ' ' ' 'c     s t    \ 
 
 
 
 
 \
 
 
r   r   )	rk   enumr   typingr   r   r   r   r   r   r   r   <module>rt      s    
			       & & & & & & & & & &    t   q
 q
 q
 q
 q
 q
 q
 q
 q
 q
r   