Ë
    i›¾j§  ã                  ó„   — d dl mZ d dlZd dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZmZ dZdd„Zd	d
hZddd„Zddd„Zdd„Zy)é    )ÚannotationsN)Úmakedirs)ÚPath)Úsettings)ÚerrorÚinfoÚArgosTranslatec                ó:   — | j                  d«      }|dkD  r| d| S y)a.  Gets the protocol of a URL string

    For example if url is "https://www.argosopentech.com" "https" is returned.
    If the protocol can't be determined None is returned

    Args:
        url: The URL to get the protocol of

    Returns:
        The string representation of the protocol or None
    ú:r   N)Úfind)ÚurlÚprotocol_end_indexs     úc/home/spazio/kingdom_calls/work5/transenv/lib/python3.12/site-packages/argostranslate/networking.pyÚget_protocolr      s,   € ð Ÿ™ #›ÐØ˜AÒØÐ&Ð&Ð'Ð'Øó    ÚhttpÚhttpsc                óz  — t        | «      t        vryt        d| › �«       d}||k  rg	 t        j                  j                  | dt        i¬«      }t        j                  j                  |«      }|j                  «       }t        d| › �«       |S y# t        $ r}|dz  }t        |«       Y d}~nd}~ww xY w||k  rŒ”Œ.)a]  Downloads data from an url and returns it

    Args:
        url: The url to download (http, https)
        retry_count: The number of retries to attempt if the initial download fails.
                If retry_count is 0 the download will only be attempted once.

    Returns:
        The downloaded data, None is returned if the download fails
    NzGet r   z
User-Agent)ÚheaderszGot é   )r   Úsupported_protocolsr   ÚurllibÚrequestÚRequestÚ
USER_AGENTÚurlopenÚreadÚ	Exceptionr   )r   Úretry_countÚdownload_attempts_countÚreqÚresponseÚdataÚerrs          r   Úgetr%   #   sÄ   € ô �CÓÔ 3Ñ3ØÜˆ4�ˆuˆÔØÐØ
! [Ò
0ð	Ü—.‘.×(Ñ(ØØ%¤zÐ2ð )ó ˆCô —~‘~×-Ñ-¨cÓ2ˆHØ—=‘=“?ˆDÜ�4˜�u�ÔØˆKð øô ò 	Ø# qÑ(Ð#Ü�#�J‰Jûð	úð " [Ó
0øs   ©A%B Â	B3ÂB.Â.B3c                óp   — t        j                  | t        | «      «      D ]  }t        ||«      }|€Œ|c S  y)ag  Downloads data from a list of urls and returns it

    Args:
        urls: The urls to download (http, https)
        retry_count: The number of retries to attempt if the initial download fails.
                If retry_count is 0 the download will only be attempted once.

    Returns:
        The downloaded data, None is returned if the download fails
    N)ÚrandomÚsampleÚlenr%   )Úurlsr   r   Úattempts       r   Úget_fromr,   B   s>   € ô �}‰}˜T¤3 t£9Ó-ò ˆÜ�c˜;Ó'ˆØÑØŠNðð r   c                 ó–  — ddl m}  ddlm} t	        t
        j                  dz  «      }t        |d¬«       t        d«       t	        |dz  d	z  «      }|j                  «       s=	 t        d
«        |d«        | ddg¬«      }|j                  |«       t        d«       |S |S # t        $ r}t        t        |«      «       Y d}~yd}~ww xY w)zSDownloads Spacy multilingual model and saves it the cache directory for further user   )Úload)ÚdownloadÚspacyT)Úexist_okz'Looking for cached Spacy xx_sent_ud_sm.ÚsenterÚmodelz Downloading Spacy xx_sent_ud_sm.Úxx_sent_ud_smÚparser)Úexcludez(Spacy xx_sent_ud_sm successfully cached.N)r0   r.   Ú	spacy.clir/   r   r   Ú	cache_dirr   r   ÚexistsÚto_diskr   r   Ústr)Ú
spacy_loadÚspacy_downloadÚspacy_cacheÚspacy_modelÚnlpÚes         r   Úcache_spacyrB   T   s·   € å(Ý4ä”x×)Ñ)¨GÑ3Ó4€KÜˆ[ 4Õ(ÜÐ	2Ô3Ü�{ XÑ-°Ñ7Ó8€KØ×ÑÔð		ÜÐ3Ô4Ù˜?Ô+Ù˜_°x°jÔAˆCØ�K‰K˜Ô$ÜÐ;Ô<ØÐð
 Ðøô	 ò 	Ü”#�a“&ŒMÜûð	ús   Á#;B! Â!	CÂ*CÃC)r   r;   Úreturnz
str | None)é   )r   r;   r   ÚintrC   úbytes | None)r*   z	list[str]r   rE   rC   rF   )rC   zPath | None)Ú
__future__r   r'   Úurllib.requestr   Úosr   Úpathlibr   Úargostranslater   Úargostranslate.utilsr   r   r   r   r   r%   r,   rB   © r   r   ú<module>rN      s@   ðÝ "ã Û Ý Ý å #ß ,à€
óð$ ˜wÐ'Ð ôô>ô$r   