o
    ]iW!                     @   sJ   d dl Z d dlmZ d dlmZmZmZ G dd deZG dd dZdS )    N)Enum)AnyDictOptionalc                   @   s    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 r   r   S/var/www/html/stock_analysis/be/venv/lib/python3.10/site-packages/xlsxwriter/url.pyr      s    r   c                   @   s  e Zd ZdZdZdZdeddfddZdefd	d
Ze	de
eef ded  fddZedefddZejdeddfddZedefddZejdeddfddZd$ddZd$ddZd$ddZdefddZdefddZededefd d!Zededefd"d#ZdS )%Urlz.
    A class to represent URLs in Excel.

    i      linkreturnNc                 C   s   t j| _|| _|| _|| _d| _d| _d| _d| _	d| _
|   t| j| jkr,tdt| j| jkr8tdt| j| jkrDt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   r   r   r   __init__$   s"   zUrl.__init__c                 C   sP   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(   r   r   r   __repr__<   s(   	
zUrl.__repr__optionsc                 C   sJ   t |ts	td|d}t |tr#| |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   )clsr.   r/   r   r   r   from_optionsO   s   




zUrl.from_optionsc                 C      | j S )z5Get the alternative, user-friendly, text for the URL.r   r,   r   r   r   texti      zUrl.textvaluec                 C   
   || _ dS )z5Set the alternative, user-friendly, text for the URL.Nr9   r(   r<   r   r   r   r:   n      
c                 C   r8   )zGet the screen tip for the URL.r   r,   r   r   r   r0   s   r;   zUrl.tipc                 C   r=   )zSet the screen tip for the URL.Nr@   r>   r   r   r   r0   x   r?   c                 C   s  | j drtj| _| js| j ddd| _dS dS | j drEtj| _| j ddd| _| j ddd| _ | j | _	| jsC| j	| _dS dS | j dsQ| j drtj
| _| jddd}|}|ddd}|ddd}|d	d
}| |r||| _ nd| | _ | 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 rt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_pathr   r   r   r"   }   sZ   





zUrl._parse_urlc                 C   s"   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'   r,   r   r   r   _set_object_link   s   zUrl._set_object_linkc                 C   sL   | 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.rA   z%23N)r   r   r   _escape_urlr   r   r   rE   r,   r   r   r   r'      s   zUrl._escape_stringsc                 C   r8   )z$Get the target for relationship IDs.)r   r,   r   r   r   _target   s   zUrl._targetc                 C   s   | j tjkrdS dS )z)Get the target mode for relationship IDs.r   External)r   r   r   r,   r   r   r   _target_mode   s   zUrl._target_moder/   c                 C   s.   |  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)rD   isalphar/   r   r   r   rF      s
   
zUrl._is_relative_pathc                 C   sl   t 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searchrE   rQ   r   r   r   rK      s   
zUrl._escape_url)r   N)r
   r   r   r   r$   r&   r5   r)   r-   classmethodr   r   r   r7   propertyr:   setterr0   r"   rJ   r'   rL   rN   staticmethodboolrF   rK   r   r   r   r   r      s2     

O

r   )	r]   enumr   typingr   r   r   r   r   r   r   r   r   <module>   s
   
