
    liW!                     V    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y)    N)Enum)AnyDictOptionalc                        e Zd ZdZdZdZdZdZy)UrlTypesz4
    Enum to represent different types of URLS.
    r            N)__name__
__module____qualname____doc__UNKNOWNURLINTERNALEXTERNAL     L/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/xlsxwriter/url.pyr   r      s     G
CHHr   r   c                   J   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y)Urlz.
    A class to represent URLs in Excel.

    i      linkreturnNc                    t         j                  | _        || _        || _        || _        d| _        d| _        d| _        d| _	        d| _
        | j                          t        | j                        | j                  kD  rt        d      t        | j                        | j                  kD  rt        d      t        | j                        | j                  kD  rt        d      | j!                          y )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$4"&
'+
	%* tzz?T---BCCt||t///TUUtyy>D222Q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    &&*oo&:&:%; <&&*&8&8%9 :&&*jj\ 2&&*&=&=%> ?&&*jj\ 2&&*ii[ 1&&*ll^ 4&&*&:&:%; <&&*oo%6b
:	
r   optionsc                     t        |t              st        d      |j                  d      }t        |t              r& | |d         }|j                  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(K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     zzr   valuec                     || _         y)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     yyr   c                     || _         y)zSet the screen tip for the URL.NrF   rD   s     r   r7   zUrl.tipx   s     	r   c                    | j                   j                  d      rEt        j                  | _        | j
                  s#| j                   j                  ddd      | _        yy| j                   j                  d      rt        j                  | _        | j                   j                  ddd      | _        | j                   j                  ddd      | _         | j                   | _	        | j
                  s| j                  | _        yy| j                   j                  d      s| j                   j                  d      rpt        j                  | _        | j                  j                  ddd      }|}|j                  ddd      }|j                  ddd      }|j                  d	d
      }| j                  |      r|| _         n
d|z   | _         | j
                  s|| _        d| j                   v r)| j                   j                  dd      \  | _         | _	        | j                  r;| j                  |      r"| j                   j                  d
d	      | _        n|| _        n| j                   | _        | j                  j                  d      r#| j                  j                  ddd      | _        yyd| j                   v rt        j                  | _        | j
                  s| j                   | _        d| j                   v r)| j                   j                  dd      \  | _         | _	        | j                  r| j                  | _        y| j                   | _        y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}   s    ::  +&llDO::!ZZ//	2qA
  ZZ"";/&//DO&*jj&8&8c1&MD#++KQ?DJ::DL::!\\
  ZZ""9-1F1F{1S&//DO ))11+z1MH I!))*b!<I!)))R;I!))#t4I%%i0&
')3
::&
djj +/::+;+;C+C(
DL ##)))4.2jj.@.@s.KD+.6D+ +/**' &&11%8*.*A*A*I*I%QSUV*W' 9
 djj &llDO::!ZZ
djj +/::+;+;C+C(
DL ##*.*<*<'*.**' 1$2D2D1EFGGr   c                 t    d| _         | j                  | _        | j                          | j	                          y)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                  k7  r@| j                  | j                        | _        | j                  | j
                        | _        | j                   t        j                  k(  r"| j
                  j                  dd      | _        yy)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   sy     ??h///))$**5DJ&*&6&6t7N7N&OD# ??h///&*&=&=&E&Ec5&QD# 0r   c                     | j                   S )z$Get the target for relationship IDs.)r!   r2   s    r   _targetzUrl._target   s    &&&r   c                 @    | j                   t        j                  k(  ryy)z)Get the target mode for relationship IDs.r   External)r   r   r   r2   s    r   _target_modezUrl._target_mode   s    ??h///r   r6   c                 `    | j                  d      ry| d   j                         r	| d   dk(  ryy)z"Check if a URL is a relative path.z\\Fr   r	   :T)rL   isalphar6   s    r   rN   zUrl._is_relative_path   s1     >>% q6>>A#r   c                    t        j                  d|       r| S | j                  dd      j                  dd      j                  dd      j                  dd	      j                  d
d      j                  dd      j                  dd      j                  dd      j                  dd      j                  dd      j                  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     99&,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      sR   
 KS T 0
# 
& 4S> huo  2 c   
[[# $   S   	ZZ   MH^		R' 'c  s t   
 
 
 
r   r   )	rk   enumr   typingr   r   r   r   r   r   r   r   <module>rt      s+    
  & &t q
 q
r   