Ë
    g
f   ã                   óž   — d Z dZdZdZdZdZddlZddlZddlm	Z	 ddl
Z
 e
j                  d	d
«       ddlmZ ddlmZ ddlmZ  G d„ d«      Zy)a×  
Utilities for obtaining information about accessible hypertext and hyperlinks
These utilities are app-type- and toolkit-agnostic. Utilities that might have
different implementations or results depending on the type of app (e.g. terminal,
chat, web) or toolkit (e.g. Qt, Gtk) should be in script_utilities.py file(s).

N.B. There are currently utilities that should never have custom implementations
that live in script_utilities.py files. These will be moved over time.
z$Id$z
$Revision$z$Date$zCopyright (c) 2024 Igalia, S.L.ÚLGPLé    N)ÚurlparseÚAtspiz2.0)r   é   )Údebug)ÚAXObjectc                   ó´   — e Zd ZdZed„ «       Zed„ «       Zed„ «       Zed„ «       Zedd„«       Z	ed„ «       Z
ed„ «       Zedd	„«       Zed
„ «       Zed„ «       Zy)ÚAXHypertextzNUtilities for obtaining information about accessible hypertext and hyperlinks.c                 óN  — t        j                  | «      sy	 t        j                  j	                  | «      }d| d|› d�g}t        j                  t        j                  |d«       |S # t
        $ r4}d|› �}t        j                  t        j                  |d«       Y d}~yd}~ww xY w)z(Returns the number of hyperlinks in obj.r   z+AXHypertext: Exception in _get_link_count: TNzAXHypertext:zreports z hyperlinks)
r   Úsupports_hypertextr   Ú	HypertextÚget_n_linksÚ	Exceptionr   ÚprintMessageÚ
LEVEL_INFOÚprintTokens)ÚobjÚcountÚerrorÚmsgÚtokenss        ú3/usr/lib/python3/dist-packages/orca/ax_hypertext.pyÚ_get_link_countzAXHypertext._get_link_count3   s›   € ô ×*Ñ*¨3Ô/Øð	Ü—O‘O×/Ñ/°Ó4ˆEð ! #¨°%°¸Ð'DÐEˆÜ×Ñœ%×*Ñ*¨F°DÔ9Øˆøô ò 	Ø?À¸wÐGˆCÜ×Ñœu×/Ñ/°°dÔ;Üûð	ús   ˜A' Á'	B$Á0*BÂB$c                 óô   — t        j                  | «      sy	 t        j                  j	                  | |«      }|S # t
        $ r4}d|› �}t        j                  t        j                  |d«       Y d}~yd}~ww xY w)z4Returns the hyperlink object at the specified index.Nz.AXHypertext: Exception in _get_link_at_index: T)	r   r   r   r   Úget_linkr   r   r   r   )r   ÚindexÚlinkr   r   s        r   Ú_get_link_at_indexzAXHypertext._get_link_at_indexE   sp   € ô ×*Ñ*¨3Ô/Øð	Ü—?‘?×+Ñ+¨C°Ó7ˆDð ˆøô ò 	ØBÀ5À'ÐJˆCÜ×Ñœu×/Ñ/°°dÔ;Üûð	ús   ˜ : º	A7Á*A2Á2A7c                 óœ  — g }t        t        j                  | «      «      D ]k  }t        j                  | |«      }|t        j	                  |«      cxk  r|k  s$n |t        j                  |«      cxk  r|k  sŒXn Œ[|j                  |«       Œm dt        |«      › d�| d|› d|› �g}t        j                  t        j                  |d«       |S )zIReturns all the hyperlinks in obj who started within the specified range.úAXHypertext: ú hyperlinks found inzbetween start: z
 and end: T)Úranger
   r   r   Úget_link_start_offsetÚget_link_end_offsetÚappendÚlenr   r   r   )r   Ústart_offsetÚ
end_offsetÚlinksÚir   r   s          r   Úget_all_links_in_rangez"AXHypertext.get_all_links_in_rangeU   sÀ   € ð ˆÜ”{×2Ñ2°3Ó7Ó8ò 	#ˆAÜ×1Ñ1°#°qÓ9ˆDØœ{×@Ñ@ÀÓFÔSÈÔSØ¤×!@Ñ!@ÀÓ!FÔTÈ*ÖTØ—‘˜TÕ"ð		#ð "¤# e£* Ð-AÐBÀCØ# L >°¸J¸<ÐHðJˆä×Ñœ%×*Ñ*¨F°DÔ9Øˆó    c                 ó  — g }t        t        j                  | «      «      D ],  }t        j                  | |«      }|€Œ|j	                  |«       Œ. dt        |«      › d�| g}t        j                  t        j                  |d«       |S )z,Returns a list of all the hyperlinks in obj.r    r!   T)	r"   r
   r   r   r%   r&   r   r   r   )r   r)   r*   r   r   s        r   Úget_all_linkszAXHypertext.get_all_linkse   sƒ   € ð ˆÜ”{×2Ñ2°3Ó7Ó8ò 	#ˆAÜ×1Ñ1°#°qÓ9ˆDØÑØ—‘˜TÕ"ð	#ð
 "¤# e£* Ð-AÐBÀCÐHˆÜ×Ñœ%×*Ñ*¨F°DÔ9Øˆr,   c                 óf  — 	 t         j                  j                  | «      }t         j                  j	                  ||«      }d| d|› d|› �g}t        j                  t        j                  |d«       |S # t
        $ r4}d|› �}t        j                  t        j                  |d«       Y d}~yd}~ww xY w)z;Returns the URI associated with obj at the specified index.z(AXHypertext: Exception in get_link_uri: TNÚ zAXHypertext: URI ofz	at index z is )
r   Ú
AccessibleÚget_hyperlinkÚ	HyperlinkÚget_urir   r   r   r   r   )r   r   r   Úurir   r   r   s          r   Úget_link_urizAXHypertext.get_link_uris   s¤   € ð	Ü×#Ñ#×1Ñ1°#Ó6ˆDÜ—/‘/×)Ñ)¨$°Ó6ˆCð (¨°	¸%¸ÀÀSÀEÐ.JÐKˆÜ×Ñœ%×*Ñ*¨F°DÔ9Øˆ
øô ò 	Ø<¸U¸GÐDˆCÜ×Ñœu×/Ñ/°°dÔ;Üûð	ús   ‚?A3 Á3	B0Á<*B+Â+B0c                 óð  — t        | t        j                  «      r| }nt        j                  j	                  | «      }|€*d| g}t        j                  t
        j                  |d«       y	 t        j                  j                  |«      }d| d|› �g}t        j                  t
        j                  |d«       |S # t        $ r4}d|› �}t        j                  t
        j                  |d«       Y d}~yd}~ww xY w)z7Returns the start offset of obj in the associated text.Nú'AXHypertext: Couldn't get hyperlink forTéÿÿÿÿz1AXHypertext: Exception in get_link_start_offset: zAXHypertext: Start offset ofúis )Ú
isinstancer   r3   r1   r2   r   r   r   Úget_start_indexr   r   ©r   r   r   Úoffsetr   r   s         r   r#   z!AXHypertext.get_link_start_offsetƒ   sÚ   € ô �cœ5Ÿ?™?Ô+Ø‰Dä×#Ñ#×1Ñ1°#Ó6ˆDàˆ<Ø?ÀÐEˆFÜ×Ñœe×.Ñ.°¸Ô=Øð	Ü—_‘_×4Ñ4°TÓ:ˆFð 1°#¸¸V¸H°~ÐFˆÜ×Ñœ%×*Ñ*¨F°DÔ9Øˆøô ò 	ØEÀeÀWÐMˆCÜ×Ñœu×/Ñ/°°dÔ;Üûð	úó   Á*B8 Â8	C5Ã*C0Ã0C5c                 óð  — t        | t        j                  «      r| }nt        j                  j	                  | «      }|€*d| g}t        j                  t
        j                  |d«       y	 t        j                  j                  |«      }d| d|› �g}t        j                  t
        j                  |d«       |S # t        $ r4}d|› �}t        j                  t
        j                  |d«       Y d}~yd}~ww xY w)z5Returns the end offset of obj in the associated text.Nr8   Tr9   z/AXHypertext: Exception in get_link_end_offset: zAXHypertext: End offset ofr:   )r;   r   r3   r1   r2   r   r   r   Úget_end_indexr   r   r=   s         r   r$   zAXHypertext.get_link_end_offsetœ   sÚ   € ô �cœ5Ÿ?™?Ô+Ø‰Dä×#Ñ#×1Ñ1°#Ó6ˆDàˆ<Ø?ÀÐEˆFÜ×Ñœe×.Ñ.°¸Ô=Øð	Ü—_‘_×2Ñ2°4Ó8ˆFð /°°s¸6¸(°^ÐDˆÜ×Ñœ%×*Ñ*¨F°DÔ9Øˆøô ò 	ØCÀEÀ7ÐKˆCÜ×Ñœu×/Ñ/°°dÔ;Üûð	úr?   c                 ór  — t         j                  | |«      }|syt        |«      }t        j                  j                  |j                  «      }|r9t        j                  j                  |«      d   }t        j                  dd|«      }d| d|› d�g}t        j                  t        j                  |d«       |S )	z>Strip directory and suffix off of the URL associated with obj.r0   r   z[-_]ú zAXHypertext: Basename for linkzis 'ú'T)r
   r6   r   ÚosÚpathÚbasenameÚsplitextÚreÚsubr   r   r   )r   r   Úremove_extensionr5   Ú
parsed_urirG   r   s          r   Úget_link_basenamezAXHypertext.get_link_basenameµ   s�   € ô ×&Ñ& s¨EÓ2ˆÙØä˜c“]ˆ
Ü—G‘G×$Ñ$ Z§_¡_Ó5ˆÙÜ—w‘w×'Ñ'¨Ó1°!Ñ4ˆHÜ—v‘v˜g s¨HÓ5ˆHà2°C¸4À¸zÈÐ9KÐLˆÜ×Ñœ%×*Ñ*¨F°DÔ9Øˆr,   c                 óR  — t        j                  | «      sy	 t        j                  j	                  | |«      }|dk  ryt        j                  | |«      }|€y	 t        j                  j                  |d«      }d|› d�| d|g}t        j                  t        j                  |d«       |S # t
        $ r4}d|› �}t        j                  t        j                  |d«       Y d}~yd}~ww xY w# t
        $ r4}d|› �}t        j                  t        j                  |d«       Y d}~yd}~ww xY w)zAReturns the embedded-object child of obj at the specified offset.Nz/AXHypertext: Exception in get_child_at_offset: Tr   zAXHypertext: Child at offset z inÚis)r   r   r   r   Úget_link_indexr   r   r   r   r
   r   r3   Ú
get_objectr   )r   r>   r   r   r   r   Úchildr   s           r   Úget_child_at_offsetzAXHypertext.get_child_at_offsetÇ   s  € ô ×*Ñ*¨3Ô/Øð	Ü—O‘O×2Ñ2°3¸Ó?ˆEð �1Š9Øä×-Ñ-¨c°5Ó9ˆØˆ<Øð	Ü—O‘O×.Ñ.¨t°QÓ7ˆEð 2°&°¸Ð=¸sÀDÈ%ÐPˆÜ×Ñœ%×*Ñ*¨F°DÔ9Øˆøô+ ò 	ØCÀEÀ7ÐKˆCÜ×Ñœu×/Ñ/°°dÔ;Üûð	ûô ò 	ØCÀEÀ7ÐKˆCÜ×Ñœu×/Ñ/°°dÔ;Üûð	ús/   ˜ B) Á C) Â)	C&Â2*C!Ã!C&Ã)	D&Ã2*D!Ä!D&c                 ó~   — t        j                  t        j                  | «      «      syt        j	                  | «      S )zHReturns the offset of the embedded-object obj in the text of its parent.r9   )r   Úsupports_textÚ
get_parentr
   r#   )r   s    r   Úget_character_offset_in_parentz*AXHypertext.get_character_offset_in_parentç   s1   € ô ×%Ñ%¤h×&9Ñ&9¸#Ó&>Ô?Øä×0Ñ0°Ó5Ð5r,   N)r   )r   F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústaticmethodr   r   r+   r.   r6   r#   r$   rM   rS   rW   © r,   r   r
   r
   0   sË   „ ÙXàñó ðð" ñó ðð ñó ðð ñó ðð òó ðð ñó ðð0 ñó ðð0 òó ðð" ñó ðð> ñ6ó ñ6r,   r
   )r[   Ú__id__Ú__version__Ú__date__Ú__copyright__Ú__license__rE   rI   Úurllib.parser   ÚgiÚrequire_versionÚgi.repositoryr   r0   r   Ú	ax_objectr   r
   r]   r,   r   ú<module>rh      sX   ðñ*ð €Ø€Ø€Ø1€Ø€ã 	Û 	Ý !ã 	Ø €× Ñ �7˜EÔ "Ý å Ý ÷~6ò ~6r,   