§
    	ÊjÙ  ã                  ó�   — d Z ddlmZ ddlZddlZddlZddlZddlmZ ddl	m
Z
 ddlmZ  G d„ d	e
¦  «        Z G d
„ d¦  «        ZdS )z£Account persistence. ``AccountStore`` is the interface; ``JsonAccountStore`` is the default.

A SQLite/Redis store can be added by implementing the same protocol.
é    )ÚannotationsN)ÚPath)ÚProtocolé   )ÚAccountc                  ó   — e Zd Zdd„Zd	d„ZdS )
ÚAccountStoreÚreturnúlist[Account]c              ƒ  ó
   K  — d S ©N© )Úselfs    ú3C:\Projects\Muse2API\src\muse2api\accounts\store.pyÚloadzAccountStore.load   ó
   è è € € € ó    ÚaccountsÚNonec              ƒ  ó
   K  — d S r   r   )r   r   s     r   ÚsavezAccountStore.save   r   r   N©r
   r   ©r   r   r
   r   )Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r	   r	      s(   € € € € € Ø.Ð.Ð.Ð.Ø>Ð>Ð>Ð>Ð>Ð>r   r	   c                  ó.   — e Zd Zdd„Zdd„Zdd	„Zdd„ZdS )ÚJsonAccountStoreÚpathr   r
   r   c                óD   — || _         t          j        ¦   «         | _        d S r   )r   ÚasyncioÚLockÚ_lock)r   r   s     r   Ú__init__zJsonAccountStore.__init__   s   € ØˆŒ	Ý”\‘^”^ˆŒ
ˆ
ˆ
r   r   c              ƒ  óð   K  — | j                              ¦   «         sg S t          j        | j         j        d¬¦  «        ƒ d {V —†}|                     ¦   «         sg S d„ t          j        |¦  «        D ¦   «         S )Núutf-8©Úencodingc                ó6   — g | ]}t          j        |¦  «        ‘ŒS r   )r   Úmodel_validate)Ú.0Úitems     r   ú
<listcomp>z)JsonAccountStore.load.<locals>.<listcomp>"   s#   € ÐIÐIÐI°•Ô& tÑ,Ô,ÐIÐIÐIr   )r   Úis_filer!   Ú	to_threadÚ	read_textÚstripÚjsonÚloads)r   Úraws     r   r   zJsonAccountStore.load   s~   è è € ØŒy× Ò Ñ"Ô"ð 	ØˆIÝÔ% d¤iÔ&9ÀGÐLÑLÔLÐLÐLÐLÐLÐLÐLˆØ�yŠy‰{Œ{ð 	ØˆIØIÐI½¼ÀC¹¼ÐIÑIÔIÐIr   r   c              ƒ  óð   K  — t          j        d„ |D ¦   «         dd¬¦  «        }| j        4 ƒd {V —† t          j        | j        |¦  «        ƒ d {V —† d d d ¦  «        ƒd {V —† d S # 1 ƒd {V —†swxY w Y   d S )Nc                ó:   — g | ]}|                      d ¬¦  «        ‘ŒS )r2   )Úmode)Ú
model_dump)r+   Úas     r   r-   z)JsonAccountStore.save.<locals>.<listcomp>&   s&   € Ð9Ð9Ð9¨1ˆQ�\Š\˜vˆ\Ñ&Ô&Ð9Ð9Ð9r   Fé   )Úensure_asciiÚindent)r2   Údumpsr#   r!   r/   Ú_atomic_write)r   r   Úpayloads      r   r   zJsonAccountStore.save$   sH  è è € Ý”*Ø9Ð9°Ð9Ñ9Ô9ÈÐVWð
ñ 
ô 
ˆð ”:ð 	Að 	Að 	Að 	Að 	Að 	Að 	Að 	AÝÔ# DÔ$6¸Ñ@Ô@Ð@Ð@Ð@Ð@Ð@Ð@Ð@ð	Að 	Að 	Añ 	Aô 	Að 	Að 	Að 	Að 	Að 	Að 	Að 	Að 	Að 	Að 	Að 	Að 	Að 	Að 	Að 	Að 	Að 	Að 	Að 	Aøøøð 	Að 	Að 	Að 	Að 	Að 	As   ±!A%Á%
A/Á2A/r?   Ústrc                óü  — | j         j                             dd¬¦  «         t          j        | j         j        dd¬¦  «        \  }}	 t          j        |dd¬¦  «        5 }|                     |¦  «         d d d ¦  «         n# 1 swxY w Y   t          j        |d	¦  «         t          j	        || j         ¦  «         d S # t          $ r5 t
          j                              |¦  «        rt          j        |¦  «         ‚ w xY w)
NT)ÚparentsÚexist_okz
.accounts.z.tmp)ÚdirÚprefixÚsuffixÚwr&   r'   i€  )r   ÚparentÚmkdirÚtempfileÚmkstempÚosÚfdopenÚwriteÚchmodÚreplaceÚBaseExceptionÚexistsÚunlink)r   r?   ÚfdÚtmpÚfs        r   r>   zJsonAccountStore._atomic_write+   s.  € ØŒ	Ô×Ò t°dÐÑ;Ô;Ð;ÝÔ" t¤yÔ'7ÀÐU[Ð\Ñ\Ô\‰ˆˆCð	Ý”˜2˜s¨WÐ5Ñ5Ô5ð !¸Ø—’˜Ñ Ô Ð ð!ð !ð !ñ !ô !ð !ð !ð !ð !ð !ð !øøøð !ð !ð !ð !åŒH�S˜%Ñ Ô Ð ÝŒJ�s˜DœIÑ&Ô&Ð&Ð&Ð&øÝð 	ð 	ð 	ÝŒw�~Š~˜cÑ"Ô"ð Ý”	˜#‘”�Øð	øøøs0   ÁB< ÁB Á4B< Â BÂB< ÂBÂ2B< Â<?C;N)r   r   r
   r   r   r   )r?   r@   r
   r   )r   r   r   r$   r   r   r>   r   r   r   r   r      sl   € € € € € ð$ð $ð $ð $ðJð Jð Jð JðAð Að Að Aðð ð ð ð ð r   r   )Ú__doc__Ú
__future__r   r!   r2   rL   rJ   Úpathlibr   Útypingr   Úmodelr   r	   r   r   r   r   ú<module>r\      sÙ   ððð ð
 #Ð "Ð "Ð "Ð "Ð "à €€€Ø €€€Ø 	€	€	€	Ø €€€Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ð Ð ð?ð ?ð ?ð ?ð ?�8ñ ?ô ?ð ?ð
ð ð ð ð ñ ô ð ð ð r   