+
    lHàjµ8  ã                  ób  a € 0 t $ R t^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	H
t ^ RIHtHt ^ RIHt ^ RIHtHtHtHtHt ^ RIHt ^ RIHt ^ R	IHtHt ^ R
IHtHt ]P@                  ! ]!4      t". R;Ot#R<t$Rt%Rt&^ t'](! RR04      t)]PT                  ! R4      t+^–t,]-].R3,          t// t0R]1R&    ! R R]24      t3 ! R R]44      t5R R lt6R R lt7R R lt8R R lt9R R  lt:R! R" lt;R# R$ lt<R% R& lt=R' R( lt>R) R* lt?R+ R, lt@R- R. ltAR/ R0 ltBR1 R2 ltCR3 R4 ltDR5 R6 ltER7 R8 ltFR9 R: ltGR# )=a  File inputs and outputs of connector tools.

The model passes a local path wherever a tool takes a file. Before execute, each path is checked
with the media-delivery rule (the one that guards ``MEDIA:`` attachments), staged through the tool
gateway, and PUT to the presigned storage URL; the gateway's descriptor replaces the path. Files a
tool returns are downloaded at once into the profile's connector downloads folder, and the model
sees ``{name, mimetype, path}``. Storage URLs and keys never reach the model or the logs.
)ÚannotationsN)Úreplace)ÚUTCÚdatetime)ÚPath)ÚAnyÚIteratorÚMappingÚOptionalÚSequence)ÚToolGatewayError)ÚPlannedCall)Úparse_connector_nameÚvendor_slug_candidates)ÚCONNECTOR_FILE_MAX_BYTESÚexecute_error_familyÚFileInputErrorzPass a local file path.Ú*ÚlocalÚdockerz[\x00-\x1f\x7f<>:\"|?*\\/].zdict[str, tuple[Path_, ...]]Ú_FILE_INPUTSc                  ó   € ] tR t^5tRtRtR# )Ú_Stagedz`A descriptor this dispatch staged; a second file-input path over the same value leaves it alone.© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__static_attributes__r   ó    ÚC/home/ubuntu/.hermes/hermes-agent/tools/connectors/gateway/files.pyr   r   5   s   † Ýjr    r   c                  óF   a € ] tR t^9tRtRR/R V 3R llltR R ltRtV ;t# )	r   zBA file input refused before the call reached execute; nothing ran.ÚhintNc               ó(   € V ^8„  d   QhRRRRRRRR/# )é   ÚcodeÚstrÚmessager#   úOptional[str]ÚreturnÚNoner   )Úformats   "r!   Ú__annotate__ÚFileInputError.__annotate__<   s)   € ÷ ñ ˜Sð ¨3ð ¸ð ÐRVñ r    c               	ó>   <€ \         SV `  V4       Wn        W0n        R # ©N)ÚsuperÚ__init__r&   r#   )Úselfr&   r(   r#   Ú	__class__s   &&&$€r!   r2   ÚFileInputError.__init__<   s   ø€ Ü‰Ñ˜Ô!ØŒ	ØŽ	r    c               ó   € V ^8„  d   QhRR/# )r%   r*   údict[str, Any]r   )r,   s   "r!   r-   r.   A   s   € ÷ .ñ .˜ñ .r    c                ó¬   € RV P                   R\        V 4      R\        V P                   4      /pV P                  '       d   V P                  VR&   RRRV/# )zGThe call's error entry, in the shape the gateway's execute errors take.r&   r(   Úfamilyr#   ÚdataNÚerror)r&   r'   r   r#   )r3   r;   s   & r!   ÚresultÚFileInputError.resultA   sN   € à!'¨¯©°I¼sÀ4»yÈ(ÔThÐim×irÑirÓTsÐ tˆØ�9�9ˆ9Ø ŸI™IˆE�&‰MØ˜˜g uÐ-Ð-r    )r&   r#   )	r   r   r   r   r   r2   r<   r   Ú__classcell__)r4   s   @r!   r   r   9   s!   ø† ÙLðÈ÷ ò ÷
.ó .r    c               ó$   € V ^8„  d   QhRRRRRR/# )r%   Únamer'   Úinput_schemar   r*   r7   r   )r,   s   "r!   r-   r-   N   s!   € ÷ *ñ *˜3ð *¨cð *°nñ *r    c           
     ó¨   € \        V\        4      '       g   / # \        \        P                  \	        WR^ 4      4      4      \
        V &   \        V4      # )z¢The tool's parameters as the model sees them (file inputs become path strings); records the
file-input argument paths for ``name`` so execute knows what to stage.r   )Ú
isinstanceÚdictÚtupleÚfromkeysÚ_file_pathsr   Ú_as_model_schema)r@   rA   s   &&r!   Úmodel_parametersrI   N   sD   € ô �l¤D×)Ò)Øˆ	ÜœtŸ}™}¬[¸ÐUWÐYZÓ-[Ó\Ó]„L�ÑÜ˜LÓ)Ð)r    c               ó    € V ^8„  d   QhRRRR/# )r%   Únoder   r*   r   )r,   s   "r!   r-   r-   W   s   € ÷ Iñ I˜3ð I 3ñ Ir    c                ó   € \        V \        4      '       d   V  Uu. uF  p\        V4      NK  	  up# \        V \        4      '       g   V # V P	                  R 4      RJ d9   V P	                  R4      ;'       g    R R\
         2P                  4       pRRRV/# V P                  4        UUu/ uF  w  r4V\        V4      bK  	  upp# u upi u uppi )Úfile_uploadableTÚdescriptionÚ Ú ÚtypeÚstring)rC   ÚlistrH   rD   ÚgetÚFILE_INPUT_NOTEÚstripÚitems)rK   ÚitemrN   ÚkeyÚvalues   &    r!   rH   rH   W   s¼   € Ü�$œ×ÒÙ37Ó8±4¨4Ô  Ö&±4Ñ8Ð8Ü�dœD×!Ò!ØˆØ‡x�xÐ!Ó" dÓ*ØŸ™ -Ó0×6Ð6°BÐ7°q¼Ð8IÐJ×PÑPÓRˆØ˜ -°Ð=Ð=Ø;?¿:¹:¼<ÔH¹<©Z¨SˆCÔ! %Ó(Ò(¹<ÒHÐHùò 9ùó Is   ›CÂ*C
c          
     ó,   € V ^8„  d   QhRRRRRRRRR	R
/# )r%   rK   r   Úrootr7   ÚpathÚPath_ÚdepthÚintr*   zIterator[Path_]r   )r,   s   "r!   r-   r-   b   s6   € ÷ Uñ U�cð U ð U°uð UÀSð UÈ_ñ Ur    c           	   #  ój  "  € ^ RI Hp \        V \        4      '       d   V\        8”  d   R# V! W4      p V P                  R4      RJ d   Vx € R# R F@  pV P                  V4      ;'       g    R F  p\        WaW#^,           4       Rj  x€L
  K   	  KB  	  V P                  R4      p\        V\        4      '       d;   VP                  4        F&  w  r‰\        W‘. VOVN5V^,           4       Rj  x€L
  K(  	  \        V P                  R4      V. VO\        N5V^,           4       Rj  x€L
  R#  L¤ LA L
5i)	zbArgument paths of every ``file_uploadable`` subschema: properties, items, combinators, local refs.)Úresolve_local_schema_refNrM   TÚ
propertiesrW   )ÚanyOfÚoneOfÚallOfr   )	Útools.schema_sanitizerrb   rC   rD   Ú_MAX_SCHEMA_DEPTHrT   rG   rW   Ú_ARRAY_ITEM)
rK   r\   r]   r_   rb   ÚbranchÚoptionrc   rY   Úchilds
   &&&&      r!   rG   rG   b   s  é € å?ä�dœD×!Ò! UÔ->Ô%>ÙÙ# DÓ/€DØ‡x�xÐ!Ó" dÓ*ØŠ
ÙÛ-ˆØ—h‘h˜vÓ&×,Ð,¨"Ò,ˆFÜ" 6°¸qµyÓA×AÒAó -ñ .ð —‘˜,Ó'€JÜ�*œd×#Ò#Ø$×*Ñ*Ö,‰JˆCÜ" 5°°$°¸±¸eÀa½iÓH×HÒHñ -ä˜4Ÿ8™8 GÓ,¨dÐ4H°dÐ4H¼KÑ4HÈ%ÐRSÍ)ÓT×TÒTñ Bñ IÙTùs=   ‚A)D3Á,D3ÂD-Â	A$D3Ã-D/Ã.8D3Ä&D1Ä'D3Ä/D3Ä1D3c               ó$   € V ^8„  d   QhRRRRRR/# )r%   Úclientr   Úplanr   r*   ztuple[Path_, ...]r   )r,   s   "r!   r-   r-   v   s"   € ÷ #ñ #˜sð #¨+ð #Ð:Kñ #r    c                ó�  a€ VP                   \        9   d   \        VP                   ,          # \        VP                   4      pVf   R# \        VP                  VP
                  4      p V P                  \        V4      4      ;'       g    / P                  R4      ;'       g    / o\        T3R lT 4       / 4      p\        TP                   TP                  R4      ;'       g    / 4       \        TP                   ,          #   \         d8   p\        P                  RTP                   TP                  4       Ru Rp?# Rp?ii ; i)zOThe plan's file-input paths: recorded by search or describe, else fetched once.NÚschemaszQconnector %s: schema fetch for file inputs failed (%s); executing without stagingc              3  ó„   <"  € T F5  p\        SP                  V4      \        4      '       g   K*  SV,          x € K7  	  R # 5ir0   )rC   rT   rD   )Ú.0Úslugrq   s   & €r!   Ú	<genexpr>Ú%_known_file_inputs.<locals>.<genexpr>„   s-   øé € Ð_©Z T¼:ÀgÇkÁkÐRVÓFWÔY]×;^”=�7˜4—=’=«Zùs
   ƒ'A ¯A rA   r   )r@   r   r   r   Ú	connectorÚtoolrq   rS   rT   r   ÚloggerÚwarningr&   ÚnextrI   )rn   ro   ÚparsedÚ
candidatesÚexcÚschemarq   s   &&    @r!   Ú_known_file_inputsr€   v   sõ   ø€ à‡y�y”LÔ Ü˜DŸI™IÕ&Ð&Ü! $§)¡)Ó,€FØ‚~Øˆ	Ü'¨×(8Ñ(8¸&¿+¹+ÓF€JðØ—>‘>¤$ zÓ"2Ó3×9Ð9°r×>Ñ>¸yÓI×OÐOÈRˆô
 Ô_©ZÓ_ÐacÓd€FÜ�T—Y‘Y §
¡
¨>Ó :× @Ð @¸bÔAÜ˜Ÿ	™	Õ"Ð"øô ô Ü�‰ÐjØ—y‘y #§(¡(ô	,à�	ûðús*   Á* D ÂD Â$D ÄEÄ,E Ä:EÅ Ec               ó(   € V ^8„  d   QhRRRRRRRR/# )r%   rn   r   ro   r   Útask_idr)   r*   r   )r,   s   "r!   r-   r-   Ž   s(   € ÷ 8ñ 8˜ð 8 Kð 8¸]ð 8È{ñ 8r    c               óÖ   a aa€ \        SP                  4      '       g   S# \        S S4      pV'       g   S# SP                  pV F  p\        WEV VV3R l4      pK  	  \	        SVR7      # )z³``plan`` with each file-input path replaced by a staged descriptor for ``plan.tool``.

Raises ``FileInputError`` when a path is refused or a stage fails; nothing is executed then.c                ó    <€ \        SSV S4      # r0   )Ú
_stage_one)Úrawrn   ro   r‚   s   &€€€r!   Ú<lambda>Ústage_inputs.<locals>.<lambda>™   s   ø€ ¼ZÈÐPTÐVYÐ[bÔ=cr    )Ú	arguments)Ú	_has_textr‰   r€   Ú_substituteÚdataclass_replace)rn   ro   r‚   Úpathsr‰   r]   s   ffd   r!   Ústage_inputsrŽ   Ž   sZ   ú€ ô �T—^‘^×$Ò$ØˆÜ˜v tÓ,€EßØˆØ—‘€IÛˆÜ 	Ö1cÓdŠ	ñ ä˜T¨YÔ7Ð7r    c               ó    € V ^8„  d   QhRRRR/# )r%   rZ   r   r*   Úboolr   )r,   s   "r!   r-   r-   �   s   € ÷ ñ �Sð ˜Tñ r    c                ó¢  € \        V \        4      '       d   R# \        V \        4      '       dQ   \        ;QJ d*    R V P	                  4        4       F  '       g   K   R# 	  R# ! R V P	                  4        4       4      # \        V \
        \        34      '       d5   \        ;QJ d    R V  4       F  '       g   K   R# 	  R# ! R V  4       4      # R# )zCA file input needs a string; a call with none has nothing to stage.Tc              3  ó8   "  € T F  p\        V4      x € K  	  R # 5ir0   ©rŠ   ©rs   rX   s   & r!   ru   Ú_has_text.<locals>.<genexpr>¢   s   é € Ð>©~ t”9˜T—?�?«~ùó   ‚Fc              3  ó8   "  € T F  p\        V4      x € K  	  R # 5ir0   r“   r”   s   & r!   ru   r•   ¤   s   é € Ð5©u t”9˜T—?�?«uùr–   )rC   r'   r	   ÚanyÚvaluesrS   rE   ©rZ   s   &r!   rŠ   rŠ   �   s‘   € ä�%œ×ÒÙÜ�%œ×!Ò!ß‹sÑ>¨u¯|©|¬~Ó>�sŒsÐ>ŠsÐ>ˆsÑ>¨u¯|©|¬~Ó>Ó>Ð>Ü�%œ$¤˜×'Ò'ß‹sÑ5©uÓ5�sŒsÐ5ŠsÐ5ˆsÑ5©uÓ5Ó5Ð5Ùr    c               ó$   € V ^8„  d   QhRRRRRR/# )r%   rZ   r   r]   zSequence[str]r*   r   )r,   s   "r!   r-   r-   ¨   s!   € ÷ ñ �sð  -ð ¸3ñ r    c                óê  € V'       gb   \        V \        4      '       d	   V! V 4      # \        V \        4      '       d,   \        V \        4      '       g   RV 9   d   \	        RRRR7      hV # V^ ,          VR,          rCV\
        8X  d5   \        V \        4      '       d   V  Uu. uF  p\        WTV4      NK  	  up# T # \        V \        4      '       d   W09   d   / V CV\        W,          WB4      /C# V # u upi )zbA copy of ``value`` with the leaf at ``path`` staged; missing or non-path leaves stay as they are.Ús3keyÚFILE_NOT_ALLOWEDz=File inputs take a local file path, not a storage descriptor.z(Pass the path of the local file to send.©r#   :é   NN)rC   r'   r	   r   r   ri   rS   r‹   )rZ   r]   ÚstageÚheadÚrestrX   s   &&&   r!   r‹   r‹   ¨   sØ   € çÜ�eœS×!Ò!Ù˜“<ÐÜ�eœW×%Ò%¬j¸Ä×.HÒ.HÈWÐX]ÔM]Ü Ð!3Ð5tØ&PôRð RàˆØ�a•˜$˜r�(ˆ$ØŒ{ÔÜEOÐPUÔW[×E\ÒE\¹5ÓA¹5°4”˜D¨Ö.¹5ÑAÐgÐbgÐgÜ�%œ×!Ò! d¤mØE�%ÐE˜œ{¨5­;¸ÓDÑEÐEØ€Lùò Bs   Â C0c          
     ó,   € V ^8„  d   QhRRRRRRRRR	R
/# )r%   rn   r   ro   r   r†   r'   r‚   r)   r*   zdict[str, str]r   )r,   s   "r!   r-   r-   ¹   s0   € ÷ )ñ )�sð ) +ð )°Cð )À-ð )ÐTbñ )r    c           	     ó~  € \        W#4      p\        W$4      p\        V4      P                  RR p\        P
                  ! V4      ^ ,          ;'       g    Rp V P                  VP                  P                  4       VP                  VV\        V4      R7      p T P                  TR,          TR	,          T4       \!        TR,          4      #   \         d@   p	T	P                  R8X  d   \        R\        T	4      4      T	h\        RRT RT	 24      T	hRp	?	ii ; i  \         d   p	\        RR
T RT	 24      T	hRp	?	ii ; i)éÿ   Nzapplication/octet-stream)Útoolkitrx   ÚfilenameÚmimetypeÚsizeÚTOOL_NOT_ALLOWEDÚFILE_UPLOAD_FAILEDz!The tool gateway could not stage z: Ú
upload_urlÚheadersz
Uploading z to storage failed: Ú
descriptoriÿÿÿ)Ú_readable_fileÚ_read_bytesr   r@   Ú	mimetypesÚ
guess_typeÚ
stage_filerw   Úlowerrx   Úlenr   r&   r   r'   Úput_filer   )
rn   ro   r†   r‚   r]   r:   r@   r©   Ústagedr~   s
   &&&&      r!   r…   r…   ¹   sD  € Ü˜#Ó'€DÜ�sÓ!€DÜ�‹:�?‰?˜4˜5Ð!€DÜ×#Ò# DÓ)¨!Õ,×JÐJÐ0J€HðoØ×"Ñ"¨4¯>©>×+?Ñ+?Ó+AÈÏ	É	Ð\`Ø,4¼3¸t»9ð #ó FˆðjØ�‰˜˜|Õ,¨f°YÕ.?ÀÔFô �6˜,Õ'Ó(Ð(øô ô oØ�8‰8Ð)Ô)Ü Ð!3´S¸³XÓ>ÀCÐGÜÐ1Ð5VÐW[ÐV\Ð\^Ð_bÐ^cÐ3dÓeÐknÐnûðoûô ô jÜÐ1°ZÀ¸vÐEYÐZ]ÐY^Ð3_Ó`ÐfiÐiûðjús1   ÁAC Â!D ÃDÃ:DÄDÄD<Ä$D7Ä7D<c               ó$   € V ^8„  d   QhRRRRRR/# ©r%   r†   r'   r‚   r)   r*   r   )r,   s   "r!   r-   r-   Ì   s&   € ÷ @ñ @˜ð @ mð @¸ñ @r    c                óæ   € ^ RI Hp ^ RIHp \	        W4      pV! WC! RR4      R7      pV'       d   V# \        V4      P                  4       '       g   \        RV  R2RR	7      h\        R
V  R2RR	7      h)z`The host path of a file the model may send, by the media-delivery rule; else ``FileInputError``.)Úvalidate_media_delivery_path)Úget_session_envÚHERMES_SESSION_KEYrO   )Úsession_keyÚFILE_NOT_FOUNDz' is not a regular file on this machine.z"Pass the path of an existing file.rŸ   rž   z@ may not leave this machine: the file-sending policy refuses it.zyFiles under the Hermes downloads and cache folders, or a folder listed in gateway.media_delivery_allow_dirs, can be sent.)Úgateway.platforms.baser¼   Úgateway.session_contextr½   Ú_backend_pathr   Úis_filer   )r†   r‚   r¼   r½   Ú	candidateÚalloweds   &&    r!   r°   r°   Ì   s‚   € åCÝ7ä˜cÓ+€IÙ*¨9À/ÐRfÐhjÓBkÔl€GßØˆÜ�	‹?×"Ñ"×$Ò$ÜÐ-°#°Ð6]Ð/^Ø"FôHð 	Hä
Ø˜s˜eÐ#cÐdð?ô@ð @r    c               ó$   € V ^8„  d   QhRRRRRR/# rº   r   )r,   s   "r!   r-   r-   Þ   s!   € ÷ 2ñ 2�sð 2 ]ð 2°sñ 2r    c                ó–   € ^ RI HpHp T;'       g    RpV! V4      pV\        9  d   \	        RRV R2RR7      h\        V! W4      4      # )z¸``raw`` as an absolute path in the terminal backend's namespace, resolved the way the file
tools resolve it. Backends whose files live on another machine are refused, as ``MEDIA:`` is.)Ú_resolve_path_for_taskÚ_terminal_env_type_for_taskÚdefaultrž   zFiles in the z\ terminal backend are not on this machine, so they cannot be sent as a connector file input.zNUse a file on this machine, or switch to the local or Docker terminal backend.rŸ   )Útools.file_tools_pathsrÉ   rÊ   Ú_HOST_READABLE_BACKENDSr   r'   )r†   r‚   rÉ   rÊ   ÚtaskÚbackends   &&    r!   rÃ   rÃ   Þ   sb   € ÷ [à×Ð�i€DÙ)¨$Ó/€GØÔ-Ô-ÜØ -°¨yð 9@ð !@àaôcð 	cô Ñ% cÓ0Ó1Ð1r    c               ó$   € V ^8„  d   QhRRRRRR/# )r%   r†   r'   r]   r*   Úbytesr   )r,   s   "r!   r-   r-   í   s!   € ÷ ñ �Sð  ð ¨ñ r    c           	     ó~  €  \         P                  P                  V4      pV\        8”  d(   \	        R V  RVR	,           R\        R	,           R24      h\        V4      P                  4       pT'       g   \	        RT  R24      hT#   \         d-   p\	        RT  RTP                  ;'       g    T R24      ThRp?ii ; i)
ÚFILE_TOO_LARGEz is z+ MiB; connector file inputs are limited to z MiB.rÀ   z could not be read: Ú.Nz
 is empty.i   )	Úosr]   Úgetsizer   r   r   Ú
read_bytesÚOSErrorÚstrerror)r†   r]   rª   r:   r~   s   &&   r!   r±   r±   í   sÑ   € ðlÜ�w‰w�‰˜tÓ$ˆØÔ*Ô*Ü Ð!1Ø$' 5¨¨T°kÕ-BÐ,CÐCnÜ$<ÀÕ$MÐ#NÈeð"UóVð Vô �D‹z×$Ñ$Ó&ˆ÷ ÜÐ-°#°°jÐ/AÓBÐBØ€Køô	 ô lÜÐ-°#°Ð6JÈ3Ï<É<×K^ÐK^Ð[^ÐJ_Ð_`Ð/aÓbÐhkÐkûðlús   ‚A*B ÂB<Â'B7Â7B<c               ó$   € V ^8„  d   QhRRRRRR/# )r%   rn   r   r<   r*   r   )r,   s   "r!   r-   r-     s!   € ÷ >ñ >˜ð > cð >¨cñ >r    c                ó®   € \        V\        4      '       d'   VP                  R4      f   VP                  R4      f   V# / VCR\        WR,          4      /C# )z¹A successful result with each ``{name, mimetype, url}`` replaced by ``{name, mimetype, path}``,
or ``{name, mimetype, error}`` when the download failed. Errors and replays pass through.r;   r:   )rC   r	   rT   Ú_saved)rn   r<   s   &&r!   Úsave_outputsrÝ     sN   € ô �fœg×&Ò&¨&¯*©*°WÓ*=Ò*IÈVÏZÉZÐX^ÓM_ÒMgØˆØ=ˆfÐ=�fœf V°F­^Ó<Ñ=Ð=r    c               ó$   € V ^8„  d   QhRRRRRR/# )r%   rn   r   rZ   r*   r   )r,   s   "r!   r-   r-   	  s&   € ÷ Fñ F�3ð F˜sð F sñ Fr    c           	     ó>  € \        V\        4      '       d   V Uu. uF  p\        W4      NK  	  up# \        V\        4      '       g   V# \	        V4      '       d   \        W4      # VP                  4        UUu/ uF  w  r2V\        W4      bK  	  upp# u upi u uppi r0   )rC   rS   rÜ   r	   Ú_is_file_outputÚ	_downloadrW   )rn   rZ   rX   rY   s   &&  r!   rÜ   rÜ   	  sƒ   € Ü�%œ×ÒÙ16Ó7±¨”�vÖ$±Ñ7Ð7Ü�eœW×%Ò%ØˆÜ�u×ÒÜ˜Ó'Ð'Ø7<·{±{´}ÔE±}©)¨#ˆC”˜Ó%Ò%±}ÒEÐEùò 8ùó
 Fs   ›BÁ9Bc               ó    € V ^8„  d   QhRRRR/# )r%   rZ   úMapping[str, Any]r*   r�   r   )r,   s   "r!   r-   r-     s   € ÷ 9ñ 9Ð,ð 9°ñ 9r    c                ó¸   a € \         ;QJ d    V 3R  lR 4       F  '       d   K   RM	  RM! V 3R  lR 4       4      ;'       d    S R,          P                  R4      # )c              3  ób   <"  € T F$  p\        SP                  V4      \        4      x € K&  	  R # 5ir0   )rC   rT   r'   )rs   rY   rZ   s   & €r!   ru   Ú"_is_file_output.<locals>.<genexpr>  s%   øé € ÐVÑ:U°3Œz˜%Ÿ)™) C›.¬#×.Ð.Ó:Uùs   ƒ,/ÚurlFT)r@   r©   rç   )zhttps://zhttp://)ÚallÚ
startswithrš   s   fr!   rà   rà     sE   ø€ ß‹3ÔVÑ:UÓV�3�3Š3ÔVÑ:UÓVÓV÷ 9ð 9Øˆe�×ÑÐ 7Ó8ð9r    c               ó$   € V ^8„  d   QhRRRRRR/# )r%   rn   r   Úfilerã   r*   r7   r   )r,   s   "r!   r-   r-     s"   € ÷ ñ �cð Ð!2ð °~ñ r    c                óh  € VP                  4        UUu/ uF  w  r#VR9  g   K  W#bK  	  ppp \        WR ,          VR,          4      VR&   V# u uppi   \        \        3 dN   p\        P                  R\        TR,          4      \        T4      P                  4       RT 2TR&    Rp?T# Rp?ii ; i)rç   r@   r]   z(connector file download of %s failed: %szdownload failed: r;   N)rç   Ú	expiresAt)	rW   Ú_fetch_to_downloadsr   rØ   ry   rz   Ú
_safe_namerQ   r   )rn   rë   rY   rX   Úkeptr~   s   &&    r!   rá   rá     s¨   € Ø'+§z¡z¤|ÔW¡|™)˜#°sÐBVÑ7VŒIˆCŠI¡|€DÑWð2Ü*¨6¸µ;ÀÀVÅÓMˆˆV‰ð €Kùó Xøô œgÐ&ô 2Ü�‰ÐAÄ:ÈdÐSYÍlÓC[Ô]aÐbeÓ]f×]oÑ]oÔpØ+¨C¨5Ð1ˆˆW�Ø€Kûð2ús"   ”A¤A®A ÁB1Á$AB,Â,B1c               ó(   € V ^8„  d   QhRRRRRRRR/# )r%   rn   r   rç   r'   r@   r*   r   )r,   s   "r!   r-   r-   "  s(   € ÷ 2ñ 2 ð 2¨#ð 2°Sð 2¸Sñ 2r    c                ó   € ^ RI HpHpHp V! V! 4       V,          4      p\        P
                  ! VRRR7      p V;_uu_ 4        V P                  WP                  \        R7       RRR4       \        V\        V4      4      p\        P                  ! VP                  V4       \        V4      \        VP                  4      P!                  RR7       #   + '       g   i     Lv; i  \        TP                  4      P!                  RR7       i ; i)	zªStream ``url`` into a temp file, then link it under a fresh name: a cut download never leaves
a partial file under the final name, and an existing file is never replaced.)ÚCONNECTOR_DOWNLOADS_SUBDIRÚget_hermes_homeÚmkdir_under_hermes_homez	.partial-F)ÚdirÚprefixÚdelete)Ú	max_bytesNT)Ú
missing_ok)Úhermes_constantsró   rô   rõ   ÚtempfileÚNamedTemporaryFileÚget_fileÚwriteÚDOWNLOAD_MAX_BYTESÚ_reserve_namerï   rÕ   r   r@   r'   r   Úunlink)	rn   rç   r@   ró   rô   rõ   ÚfolderÚhandleÚtargets	   &&&      r!   rî   rî   "  sÀ   € ÷ fÑeá$¡_Ó%6Ð9SÕ%SÓT€FÜ×(Ò(¨V¸KÐPUÔV€Fð2ßŠVØ�O‰O˜C§¡Ô9KˆOÔL÷ ä˜v¤z°$Ó'7Ó8ˆÜ
�
Š
�6—;‘; Ô'Ü�6‹{äˆV�[‰[Ó× Ñ ¨DÐ Õ1÷ �Vûô 	ˆV�[‰[Ó× Ñ ¨DÐ Õ1ús$   ¹
C& Á"CÁ%AC& ÃC#	ÃC& Ã&'Dc               ó$   € V ^8„  d   QhRRRRRR/# )r%   r  r   r@   r'   r*   r   )r,   s   "r!   r-   r-   3  s!   € ÷ 6ñ 6˜$ð 6 cð 6¨dñ 6r    c                ó~  € \         P                  ! \        4      P                  R4      p\        P
                  P                  V4      w  r4\        R4       FE  pY^ 8X  d   V RV 2MV RV RV V 2,          p VP                  R4      P                  4        Vu # 	  \        RV 24      h  \         d     Ke  i ; i)zYCreate an empty file under a fresh ``<UTC stamp>-<name>``; the download then replaces it.z%Y%m%dT%H%M%SZiè  Ú-Úxbzno free name for )r   Únowr   ÚstrftimerÕ   r]   ÚsplitextÚrangeÚopenÚcloseÚFileExistsError)r  r@   ÚstampÚstemÚsuffixÚattemptr  s   &&     r!   r  r  3  s¿   € ä�LŠLœÓ×&Ñ&Ð'7Ó8€EÜ—7‘7×#Ñ# DÓ)�L€DÜ˜–;ˆØ¸1´˜e˜W A d VÑ,ÀUÀGÈ1ÈTÈFÐRSÐT[ÐS\Ð]cÐ\dÐBeÕfˆð	Ø�K‰K˜Ó×#Ñ#Ô%ð Šñ ô Ð-¨d¨VÐ4Ó
5Ð5øô ô 	Úð	ús   Á:B-Â-B<Â;B<c               ó    € V ^8„  d   QhRRRR/# )r%   r@   r'   r*   r   )r,   s   "r!   r-   r-   A  s   € ÷ 0ñ 0�Sð 0˜Sñ 0r    c                óÌ   € \         P                  ! RV 4      R,          p\        P                  RV4      P	                  4       P	                  R4      pV\
        ) R ;'       g    R# )zPA basename safe on every OS: no separators, control characters, or ``.``/``..``.z[\\/]Ú_rÔ   Nrë   éÿÿÿÿ)ÚreÚsplitÚ_UNSAFE_NAME_CHARSÚsubrV   Ú_MAX_NAME_CHARS)r@   ÚbaseÚcleaneds   &  r!   rï   rï   A  sV   € ä�8Š8�H˜dÓ# BÕ'€DÜ ×$Ñ$ S¨$Ó/×5Ñ5Ó7×=Ñ=¸cÓB€GØ”OÐ#Ð$Ð%×/Ð/¨Ð/r    )r   r   rI   rÝ   rŽ   i   )HÚ__conditional_annotations__r   Ú
__future__r   Úloggingr²   rÕ   r  rü   Údataclassesr   rŒ   r   r   Úpathlibr   Útypingr   r   r	   r
   r   Útools.connectors.gateway.errorsr   Útools.connectors.gateway.merger   Útools.connectors.gateway.namesr   r   Útools.connectors.gateway.wirer   r   Ú	getLoggerr   ry   Ú__all__r   rU   ri   rh   Ú	frozensetrÍ   Úcompiler  r  rE   r'   r^   r   Ú__annotations__rD   r   Ú	Exceptionr   rI   rH   rG   r€   rŽ   rŠ   r‹   r…   r°   rÃ   r±   rÝ   rÜ   rà   rá   rî   r  rï   )r   s   @r!   Ú<module>r0     s   øðôõ #ã Û Û 	Û 	Û Ý 4ß "Ý ß =Õ =å <Ý 6ß Wß Xà	×	Ò	˜8Ó	$€ò€ð &Ð Ø+€à€ØÐ ñ $ W¨hÐ$7Ó8Ð Ø—Z’ZÐ =Ó>Ð Ø€àˆc�3ˆh�€à-/€Ð*Ó /ôkˆdô kô.�Yô .õ**õIõUõ(#õ08õõõ")õ&@õ$2õõ(>õFõ9õ
õ2õ"6÷0r    