
    ɯei!                      p    d Z ddlmZmZmZmZmZmZmZm	Z	 ddl
Z
ddlZddlmZ dedefdZ G d	 d
      Zy)z/
Queue management for Streamlit notifications.
    )Dict	GeneratorIterableListLiteralOptionalUnionCallableN   )StatusElementNotificationxreturnc                     | j                    S )z/Sort notifications by priority (highest first).)priority)r   s    e/var/www/html/glpi_dashboard/venv/lib/python3.12/site-packages/streamlit_notify/notification_queue.pydefault_sort_funcr      s    JJ;    c                      e Zd ZdZ	 d5dedeeegef      ddfdZ	e
dee   fd       Ze
defd       Ze
deegef   fd	       Zd6d
Zd6dZdefdZdefdZdeddfdZdee   ddfdZdeeef   ddfdZdedefdZdedee   fdZdedee   fdZdedee   fdZdedee   fdZdedee   fdZ	 	 d7dee   ded   dee   fdZ d6dZ!d8dedefdZ"d8dedefd Z#defd!Z$defd"Z%defd#Z&defd$Z'defd%Z(dedefd&Z)dedefd'Z*ded(eddfd)Z+deddfd*Z,defd+Z-d,e.defd-Z/d,e.defd.Z0d,e.defd/Z1de2eddf   fd0Z3de2eddf   fd1Z4d2 Z5d3e6ee.f   fd4Z7y)9NotificationQueuez7
    A queue for managing Streamlit notifications.
    N
queue_name	sort_funcr   c                 P    || _         |t        }|| _        | j                          y)zInitialize the queue.N)_queue_namer   
_sort_funcensure_queue)selfr   r   s      r   __init__zNotificationQueue.__init__   s*     !+)IFOr   c                 \    | j                          t        j                  | j                     S )zGet the current queue.)r   stsession_stater   r   s    r   queuezNotificationQueue.queue%   s'     	 0 011r   c                     | j                   S )zGet the name of the queue.)r   r!   s    r   r   zNotificationQueue.queue_name+   s     r   c                     | j                   S )z'Get the sorting function for the queue.)r   r!   s    r   r   zNotificationQueue.sort_func0   s     r   c                 x    | j                   t        j                  vrg t        j                  | j                   <   yy)z)Ensure the queue exists in session state.N)r   r   r    r!   s    r   r   zNotificationQueue.ensure_queue5   s1    2#3#3313BT--. 4r   c                 P    | j                   j                  | j                         y)zSort the queue by priority.)keyN)r"   sortr   r!   s    r   _sortzNotificationQueue._sort:   s    

DOO,r   c                     t        |       dkD  S )zCheck if the queue has items.r   lenr!   s    r   	has_itemszNotificationQueue.has_items>       4y1}r   c                     t        |       dk(  S )zCheck if the queue is empty.r   r+   r!   s    r   is_emptyzNotificationQueue.is_emptyB   s    4yA~r   itemc                 Z    | j                   j                  |       | j                          y)zAdd an item to the queue.N)r"   appendr)   r   r1   s     r   r3   zNotificationQueue.appendF   s    

$

r   itemsc                 Z    | j                   j                  |       | j                          y)z Add multiple items to the queue.N)r"   extendr)   )r   r5   s     r   r7   zNotificationQueue.extendK   s    

% 

r   c                     t        |t              r| j                  j                  |       y|| j                  v r| j                  j	                  |       yt        d| d      )zRemove an item from the queue.NzItem: z not found in queue.)
isinstanceintr"   popremove
ValueErrorr4   s     r   r<   zNotificationQueue.removeP   sW     dC JJNN4 4::JJd#6$';<==r   c                     || j                   v S z!Check if an item is in the queue.r"   r4   s     r   containszNotificationQueue.contains]   s    tzz!!r   r   c                 `    | j                   D cg c]  }|j                  |k  s| c}S c c}w )zGGet all items in the queue with priority less than the specified value.r"   r   r   r   r1   s      r   _get_all_less_thanz$NotificationQueue._get_all_less_thana   %    !%Ht}}x/GHHH   ++c                 `    | j                   D cg c]  }|j                  |k  s| c}S c c}w )zSGet all items in the queue with priority less than or equal to the specified value.rC   rD   s      r   _get_all_less_than_equal_toz-NotificationQueue._get_all_less_than_equal_toe   '     "&It}}/HIIIrG   c                 `    | j                   D cg c]  }|j                  |kD  s| c}S c c}w )zJGet all items in the queue with priority greater than the specified value.rC   rD   s      r   _get_all_greater_thanz'NotificationQueue._get_all_greater_thank   rF   rG   c                 `    | j                   D cg c]  }|j                  |k\  s| c}S c c}w )zVGet all items in the queue with priority greater than or equal to the specified value.rC   rD   s      r   _get_all_greater_than_equal_toz0NotificationQueue._get_all_greater_than_equal_too   rJ   rG   c                 `    | j                   D cg c]  }|j                  |k(  s| c}S c c}w )zFGet all items in the queue with priority equal to the specified value.rC   rD   s      r   _get_all_equal_toz#NotificationQueue._get_all_equal_tou   s%    !%It}}/HIIIrG   priority_type)leltgegteqc                    |n|dk(  r| j                  |      S |dk(  r| j                  |      S |dk(  r| j                  |      S |dk(  r| j                  |      S |dk(  r| j	                  |      S | j
                  j                         S )zGet all items in the queue.rR   rS   rT   rU   rV   )rI   rE   rN   rL   rP   r"   copy)r   r   rQ   s      r   get_allzNotificationQueue.get_ally   s     $77AA$&..x88$&::8DD$&11(;;$&--h77zz  r   c                 8    | j                   j                          y)zClear the queue.N)r"   clearr!   s    r   r[   zNotificationQueue.clear   s    

r   indexc                 8    | j                   j                  |      S )zPop an item from the queue.)r"   r;   r   r\   s     r   r;   zNotificationQueue.pop   s    zz~~e$$r   c                      | j                   |   S )z/Get an item from the queue without removing it.r@   r^   s     r   getzNotificationQueue.get       zz%  r   c                     t        |       S zGet the size of the queue.r+   r!   s    r   sizezNotificationQueue.size   s    4yr   c                 ,    t        | j                        S rc   )r,   r"   r!   s    r   __len__zNotificationQueue.__len__   s    4::r   c                 N    d| j                   dt        | j                         dS )#String representation of the queue.zNotificationQueue(name=z, items=)r   r,   r"   r!   s    r   __repr__zNotificationQueue.__repr__   s(    ()9)9(<HS_DUUVWWr   c                 N    d| j                    dt        | j                         dS )rh   zNotificationQueue(z, z items)rj   r!   s    r   __str__zNotificationQueue.__str__   s'    #D$4$4#5RDJJ7HPPr   c                     t        |       dkD  S )z$Boolean representation of the queue.r   r+   r!   s    r   __bool__zNotificationQueue.__bool__   r.   r   c                 $    | j                  |      S r?   )rA   r4   s     r   __contains__zNotificationQueue.__contains__   s    }}T""r   c                      | j                   |   S )zGet an item by index.r@   r^   s     r   __getitem__zNotificationQueue.__getitem__   ra   r   valuec                 B    || j                   |<   | j                          y)zSet an item by index.N)r"   r)   )r   r\   rt   s      r   __setitem__zNotificationQueue.__setitem__   s    !

5

r   c                     | j                   |= y)zDelete an item by index.Nr@   r^   s     r   __delitem__zNotificationQueue.__delitem__   s    JJur   c                 ,    t        | j                        S )z$Hash of the queue based on its name.)hashr   r!   s    r   __hash__zNotificationQueue.__hash__   s    D$$%%r   otherc                     t        |t              sy| j                  |j                  k(  xr! | j                         |j                         k(  S )z(Check if this queue is equal to another.F)r9   r   r   rY   r   r|   s     r   __eq__zNotificationQueue.__eq__   s?    %!23 1 11Wdlln6W	
r   c                 &    | j                  |       S )z,Check if this queue is not equal to another.)r   r~   s     r   __ne__zNotificationQueue.__ne__   s    ;;u%%%r   c                 p    t        |t              st        S | j                         |j                         k  S )z)Check if this queue is less than another.)r9   r   NotImplementedrd   r~   s     r   __lt__zNotificationQueue.__lt__   s*    %!23!!yy{UZZ\))r   c              #   T   K   | j                   j                         E d{    y7 w)z,Iterate over the notifications in the queue.N)r"   rX   r!   s    r   __iter__zNotificationQueue.__iter__   s     ::??$$$s   (&(c              #   f   K   t        | j                  j                               E d{    y7 w)z0Iterate over the notifications in reverse order.N)reversedr"   rX   r!   s    r   __reversed__zNotificationQueue.__reversed__   s     DJJOO-...s   '1/1c                     t        | j                   d      }| j                  |_        |j                  | j                                |S )z#Create a shallow copy of the queue._copy)r   r   r7   rY   )r   	new_queues     r   __copy__zNotificationQueue.__copy__   sB    %)9)9(:%&@A	 $ 0 0	(r   memoc                     t        | j                   d      }| j                  |_        |j                  t        j                  | j                         |             |S )z Create a deep copy of the queue.r   )r   r   r7   rX   deepcopyrY   )r   r   r   s      r   __deepcopy__zNotificationQueue.__deepcopy__   sM    %)9)9(:%&@A	 $ 0 0	t||~t<=r   )N)r   N)NrV   )r   )8__name__
__module____qualname____doc__strr   r
   r   r:   r   propertyr   r"   r   r   r   r)   boolr-   r0   r3   r   r7   r	   r<   rA   rE   rI   rL   rN   rP   r   rY   r[   r;   r`   rd   rf   rk   rm   ro   rq   rs   rv   rx   r{   objectr   r   r   r   r   r   r   r   r    r   r   r   r      sE    KO H&?%@#%EFG 
	 2t56 2 2
  C     8%>$?$DE  4
-4 $ 4  
H%>? D 
>5!:C!?@ >T >"6 "4 "I3 I48Q3R IJJ	'	(JIc Id;T6U IJJ	'	(JJ# J$7P2Q J #'?C!3-! ;<! 
'	(	!&% %%> %! !%> !c  X# XQ Q$ #!: #t #! !)B ! -F 4 
  &# &
F 
t 
&F &t &*F *t *%)$=tT$IJ %/i(A4(MN /c6k!2 r   r   )r   typingr   r   r   r   r   r   r	   r
   rX   	streamlitr   notification_dataclassr   r:   r   r   r   r   r   <module>r      s?    W V V   =2 s 
U Ur   