Ë
    âß²jï  ã                   óN  — U d Z ddlZddlZddlZddlmZ ddlmZmZmZ ddl	m
Z
 ddlmZ  ej                  e«      Z ej                   «       Zi Zeeeef   eeee
   f   f   ed<   defd	„Zdeeef   fd
„Zdefd„Zdeeee
   f   fd„Zdee
   fd„Zdefd„Zdd„Zdefd„Zy)u,  Timezone-aware clock for Hermes.

``now()`` returns a tz-aware datetime in the user's configured IANA timezone. Resolution order:
``HERMES_TIMEZONE`` env var, then ``timezone`` in ``~/.hermes/config.yaml``, else server-local
time. Invalid timezone values log a warning and fall back â€” never crash.
é    N)Údatetime)ÚDictÚOptionalÚTuple)ÚZoneInfo)Úget_config_pathÚ	_tz_cacheÚreturnc                  óf   — ddl m}   | «       ryt        j                  dd«      j	                  «       S )a   ``HERMES_TIMEZONE`` when it may speak for the active profile. Under the multiplexed
    gateway the env var holds only the DEFAULT profile's value (bridged from its config.yaml at
    startup), so every routed profile must read its own config.yaml instead.r   ©Úis_multiplex_activeÚ ÚHERMES_TIMEZONE)Úagent.secret_scoper   ÚosÚgetenvÚstripr   s    ú0/home/ubuntu/.hermes/hermes-agent/hermes_time.pyÚ_env_timezoner      s+   € õ 7áÔØÜ�9‰9Ð&¨Ó+×1Ñ1Ó3Ð3ó    c                  óL   — t        «       } | rd| fS dt        t        «       «      fS )NÚenvironmentÚconfig)r   Ústrr   )Útz_envs    r   Ú_timezone_cache_identityr   (   s(   € Ü‹_€FÙ&,ˆM˜6Ð"ÐT°8¼SÄÓARÓ=SÐ2TÐTr   c                  óž  — t        «       } | r| S 	 	 ddlm}  |t        «       «      }|rB|j                  dd«      }t        |t        «      r |j                  «       r|j                  «       S y# t        $ rH ddl}t        «       }|j                  «       r%|j                  |j                  d¬«      «      xs i ni }Y Œ•w xY w# t        $ r Y yw xY w)uV   Read the configured IANA timezone string (or ``""``). Does file I/O â€” callers cache.r   )Úload_user_config_effectiveNzutf-8)ÚencodingÚtimezoner   )r   Úhermes_cli.config_effectiver   r   Ú	ExceptionÚyamlÚexistsÚ	safe_loadÚ	read_textÚgetÚ
isinstancer   r   )r   r   Úcfgr#   Úconfig_pathÚtz_cfgs         r   Ú_resolve_timezone_namer,   -   sÇ   € ä‹_€FÙØˆðð
	rÝNÙ,¬_Ó->Ó?ˆCñ
 Ø—W‘W˜Z¨Ó,ˆFÜ˜&¤#Ô&¨6¯<©<¬>Ø—|‘|“~Ð%ð øô ò 	rÛÜ)Ó+ˆKØU`×UgÑUgÔUi�4—>‘> +×"7Ñ"7ÀÐ"7Ó"IÓJÒPÉbÐoqŠCð	rûô ò ØØðús0   ‘A, §AC  Á,AB=Â:C  Â<B=Â=C  Ã 	CÃCc                  óˆ  — t        «       } t        5  t        j                  | «      }|�|cddd«       S 	 ddd«       t	        «       }d}|r	 t        |«      }t        5  t        j                  | ||f«      cddd«       S # 1 sw Y   ŒKxY w# t        $ r!}t        j                  d||«       Y d}~ŒYd}~ww xY w# 1 sw Y   yxY w)zECached ``(configured name, ZoneInfo | None)`` for the active profile.Nz=Invalid timezone '%s': %s. Falling back to server local time.)
r   Ú_cache_lockr	   r'   r,   r   r"   ÚloggerÚwarningÚ
setdefault)Úcache_identityÚentryÚnameÚtzÚexcs        r   Ú_timezone_entryr7   G   sÈ   € ä-Ó/€NÜ	ñ Ü—‘˜nÓ-ˆØÐØ÷ñ à÷ô "Ó#€DØ	€BÙð	gÜ˜$“ˆBô 
ñ @Ü×#Ñ# N°T¸2°JÓ?÷@ñ @÷ð ûô ò 	gÜ�N‰NÐZÐ\`Ðbe×fÑfûð	gú÷@ð @ús/   ‘A?ÁB ÁB8Á?BÂ	B5ÂB0Â0B5Â8Cc                  ó   — t        «       d   S )zHReturn the active profile's configured ZoneInfo, or None (server-local).é   ©r7   © r   r   Úget_timezoner<   [   s   € äÓ˜QÑÐr   c                  ó   — t        «       d   S )z°The active profile's configured IANA timezone string, or ``""`` (server-local). Same
    resolution and cache as :func:`get_timezone`; for handing ``TZ`` to sandboxed children.r   r:   r;   r   r   Úget_timezone_namer>   `   s   € ô Ó˜QÑÐr   c                  ób   — t         5  t        j                  «        ddd«       y# 1 sw Y   yxY w)zUClear the cached timezone so the next call re-resolves it (after config/env changes).N)r.   r	   Úclearr;   r   r   Úreset_cacherA   f   s$   € ä	ñ Ü�‰Ô÷÷ ñ ús   ‡%¥.c                  óˆ   — t        «       } | �t        j                  | «      S t        j                  «       j                  «       S )zHCurrent time as a tz-aware datetime: configured zone, else server-local.)r<   r   ÚnowÚ
astimezone)r5   s    r   rC   rC   l   s0   € ä	‹€BØ!˜~Œ8�<‰<˜ÓÐN´8·<±<³>×3LÑ3LÓ3NÐNr   )r
   N)Ú__doc__Úloggingr   Ú	threadingr   Útypingr   r   r   Úzoneinfor   Úhermes_constantsr   Ú	getLoggerÚ__name__r/   ÚLockr.   r	   r   Ú__annotations__r   r   r,   r7   r<   r>   rA   rC   r;   r   r   ú<module>rO      sì   ðòó Û 	Û Ý ß (Ñ (Ý å ,à	ˆ×	Ñ	˜8Ó	$€ð ˆi�n‰nÓ€ØCE€	ˆ4��c˜3�h‘  s¨H°XÑ,>Ð'>Ñ!?Ð?Ñ@Ó Eð4�só 4ðU %¨¨S¨¡/ó Uð
 ó ð4@˜˜s H¨XÑ$6Ð6Ñ7ó @ð( �h˜xÑ(ó  ð
 ˜3ó  óðOˆXô Or   