
    h!                     N    S SK r S SKJr  S SKJr   " S S\5      r " S S5      rg)    N)Enum)Optionalc                   (    \ rS rSrSrSrSrSrSrSr	g)	UrlTypes   z,
Enum to represent different types of URLS.
r             N)
__name__
__module____qualname____firstlineno____doc__UNKNOWNURLINTERNALEXTERNAL__static_attributes__r       aC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\xlsxwriter/url.pyr   r      s     G
CHHr   r   c                   D   \ rS rSrSrSrSrS\4S jrS r	\
S\S	\S    4S
 j5       r\S	\4S j5       r\R                   S\4S j5       r\S	\4S j5       r\R                   S\4S j5       rS rS rS rS	\4S jrS	\4S jr\S\S	\4S j5       r\S\S	\4S j5       rSrg)Url   z&
A class to represent URLs in Excel.

i      linkc                    [         R                  U l        Xl        Xl        Xl        SU l        SU l        SU l        SU l	        SU l
        U R                  5         [        U R                  5      U R                  :  a  [        S5      e[        U R                  5      U R                  :  a  [        S5      e[        U R                  5      U R                  :  a  [        S5      eU R!                  5         g )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__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                    SU R                   R                   SU R                   SU R                   SU R                   SU R
                   SU R                   SU R                   SU R                   S	U R                   S
3$ )z6
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__Url.__repr__<   s    &&*oo&:&:%; <&&*&8&8%9 :&&*jj\ 2&&*&=&=%> ?&&*jj\ 2&&*ii[ 1&&*ll^ 4&&*&:&:%; <&&*oo%6b
:	
r   optionsreturnc                     [        U[        5      (       d  [        S5      eUR                  S5      n[        U[        5      (       a+  U " US   5      nUR                  S5      (       a
  US   Ul        U$ )a  
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$   )clsr7   r:   s      r   from_optionsUrl.from_optionsO   se     '4((KLLkk% c3gen%C{{5!!"5>
r   c                     U R                   $ )z5Get the alternative, user-friendly, text for the URL.r#   r4   s    r   textUrl.texti   s     zzr   valuec                     Xl         g)z5Set the alternative, user-friendly, text for the URL.NrE   r.   rH   s     r   rF   rG   n   s	     
r   c                     U R                   $ )zGet the screen tip for the URL.r$   r4   s    r   r;   Url.tips   s     yyr   c                     Xl         g)zSet the screen tip for the URL.NrL   rJ   s     r   r;   rM   x   s	     	r   c                 ^   U R                   R                  S5      (       aJ  [        R                  U l        U R
                  (       d#  U R                   R                  SSS5      U l        ggU R                   R                  S5      (       a  [        R                  U l        U R                   R                  SSS5      U l        U R                   R                  SSS5      U l         U R                   U l	        U R
                  (       d  U R                  U l        ggU R                   R                  S5      (       d!  U R                   R                  S5      (       Ga  [        R                  U l        U R                  R                  SSS5      nUnUR                  SSS5      nUR                  SSS5      nUR                  S	S
5      nU R                  U5      (       a  X l         O
SU-   U l         U R
                  (       d  X l        SU R                   ;   a)  U R                   R                  SS5      u  U l         U l	        U R                  (       a?  U R                  U5      (       a"  U R                   R                  S
S	5      U l        OXl        OU R                   U l        U R                  R                  S5      (       a#  U R                  R                  SSS5      U l        ggSU R                   ;   a  [        R                  U l        U R
                  (       d  U R                   U l        SU R                   ;   a)  U R                   R                  SS5      u  U l         U l	        U R                  (       a  U R                  U l        gU R                   U l        g[        SU R                   35      e)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(   Url._parse_url}   s    ::  ++&llDO::!ZZ//	2qA
  ZZ"";//&//DO&*jj&8&8c1&MD#++KQ?DJ::DL::!\\
  ZZ""9--1F1F{1S1S&//DO ))11+z1MH I!))*b!<I!)))R;I!))#t4I%%i00&
')3
::&
djj +/::+;+;C+C(
DL ##)))44.2jj.@.@s.KD+.6+ +/**' &&11%88*.*A*A*I*I%QSUV*W' 9
 djj &llDO::!ZZ
djj +/::+;+;C+C(
DL ##*.*<*<'*.**' 1$2D2D1EFGGr   c                 t    SU l         U R                  U l        U R                  5         U R	                  5         g)zo
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-   r4   s    r   _set_object_linkUrl._set_object_link   s/      $''
r   c                 @   U R                   [        R                  :w  a@  U R                  U R                  5      U l        U R                  U R
                  5      U l        U R                   [        R                  :X  a"  U R
                  R                  SS5      U l        gg)z-Escape special characters in the URL strings.rP   z%23N)r   r   r   _escape_urlr!   r"   r   rT   r4   s    r   r-   Url._escape_strings   sy     ??h///))$**5DJ&*&6&6t7N7N&OD# ??h///&*&=&=&E&Ec5&QD# 0r   c                     U R                   $ )z$Get the target for relationship IDs.)r"   r4   s    r   _targetUrl._target   s    &&&r   c                 B    U R                   [        R                  :X  a  gg)z)Get the target mode for relationship IDs.r   External)r   r   r   r4   s    r   _target_modeUrl._target_mode   s    ??h///r   r:   c                 v    U R                  S5      (       a  gU S   R                  5       (       a
  U S   S:X  a  gg)z"Check if a URL is a relative path.z\\Fr   r   :T)rS   isalphar:   s    r   rU   Url._is_relative_path   s7     >>%  q6>>A#r   c                    [         R                  " SU 5      (       a  U $ U R                  SS5      R                  SS5      R                  SS5      R                  SS	5      R                  S
S5      R                  SS5      R                  SS5      R                  SS5      R                  SS5      R                  SS5      R                  SS5      $ )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searchrT   rj   s    r   r^   Url._escape_url   s     99&,,J KKU#WS% WS% WS% WS% WS% WS% WS% WS% WS% WS% 	
r   )	r%   r&   r!   r   r    r'   r"   r#   r$   N)r   r   r   r   r   r*   r,   r@   r/   r5   classmethodr=   r   rB   propertyrF   setterr;   r(   r[   r-   ra   re   staticmethodboolrU   r^   r   r   r   r   r   r      s.   
 KS 0
& 4 HUO  2 c   
[[#   S   	ZZ  MH^		R' 'c  s t   
 
 
 
r   r   )rx   enumr   typingr   r   r   r   r   r   <module>r      s(    
  t q
 q
r   