
    lKj&                     p   d Z ddlZddlZddlZddlmc mZ ddlm	Z	 ddl
mZmZmZ ddlmZmZ ddlmZ ddlmZ ddlmZ dd	lmZmZ dd
lmZ dZdZdZdefdZ ed       G d d             Z  G d dejB                        Z" G d de"      Z# G d de"      Z$ G d de      Z% G d de      Z&dZ'dZ(y) z%Announcements handler for JupyterLab.    N)	Awaitable)asdict	dataclassfield)datetimetimezone)
APIHandler)
translator)parse)
httpclientweb)__version__z%Y-%m-%dT%H:%M:%S%zz%https://pypi.org/pypi/jupyterlab/jsonz7https://github.com/jupyterlab/jupyterlab/releases/tag/vdt_strc                 N    t        j                  |       j                         dz  S )Ni  )r   fromisoformat	timestamp)r   s    r/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/jupyterlab/handlers/announcements.pyformat_datetimer      s!    !!&)335<<    T)frozenc                       e Zd ZU dZeed<   eed<   eed<   dZeed<    ee	      Z
e	eef   ed<    ee      Zeed	<   y
)NotificationuK  Notification

    Attributes:
        createdAt: Creation date
        message: Notification message
        modifiedAt: Modification date
        type: Notification type — ["default", "error", "info", "success", "warning"]
        link: Notification link button as a tuple (label, URL)
        options: Notification options
    	createdAtmessage
modifiedAtdefaulttype)default_factorylinkoptionsN)__name__
__module____qualname____doc__float__annotations__strr   r   tupler   dictr     r   r   r   r      sJ    	 LD#!%8D%S/8$/GT/r   r   c            	       p    e Zd ZdZdeddfdZej                  dedez  e	ee	eef   f   z     fd       Z
y)CheckForUpdateABCzAbstract class to check for update.

    Args:
        version: Current JupyterLab version

    Attributes:
        version - str: Current JupyterLab version
        logger - logging.Logger: Server logger
    versionreturnNc                     || _         y N)r-   )selfr-   s     r   __init__zCheckForUpdateABC.__init__>   s	    r   c                 $   K   d}t        |      w)a  Get the notification message if a new version is available.

        Returns:
            None if there is not update.
            or the notification message
            or the notification message and a tuple(label, URL link) for the user to get more information
        z-CheckForUpdateABC.__call__ is not implemented)NotImplementedError)r1   msgs     r   __call__zCheckForUpdateABC.__call__A   s      >!#&&s   )r!   r"   r#   r$   r'   r2   abcabstractmethodr   r(   r6   r*   r   r   r,   r,   3   s[       		'	$*uS%S/=Q7R*R S 	' 	'r   r,   c                   6    e Zd ZdZdeeeeeef   f      fdZy)CheckForUpdatezDefault class to check for update.

    Args:
        version: Current JupyterLab version

    Attributes:
        version - str: Current JupyterLab version
        logger - logging.Logger: Server logger
    r.   c                   K   t        j                         }	 |j                  t        ddi       d{   }t	        j
                  |j                        j                  d      }|d   }t        | j                        t        |      k  rEt        j                  d      }|j                  d| d	      |j                  d
      t         | ffS y7 # t        $ r'}| j                  j!                  d|       Y d}~yd}~ww xY ww)  Get the notification message if a new version is available.

        Returns:
            None if there is no update.
            or the notification message
            or the notification message and a tuple(label, URL link) for the user to get more information
        Content-Typezapplication/jsonheadersNinfor-   
jupyterlabzA newer version (z) of JupyterLab is available.u   Read more…zFailed to get latest versionexc_info)r   AsyncHTTPClientfetchJUPYTERLAB_LAST_RELEASE_URLjsonloadsbodygetr   r-   r
   loadgettextJUPYTERLAB_RELEASE_URL	Exceptionloggerdebug)r1   http_clientresponsedatalast_versiontranses          r   r6   zCheckForUpdate.__call__Y   s     !002	(..+');< /  H ::hmm,008D	?L
 T\\"U<%88"5MM$5l^C`"ab]]>27M6N|n4]^ 
 #  	KK<qI	s?   DC C7C ,A'DC 	DD ;D DDN)r!   r"   r#   r$   r   r(   r'   r6   r*   r   r   r:   r:   N   s*    	%U38_0D*E F r   r:   c                   "    e Zd ZdZded   fdZy)NeverCheckForUpdatea7  Check update version that does nothing.

    This is provided for administrators that want to
    turn off requesting external resources.

    Args:
        version: Current JupyterLab version

    Attributes:
        version - str: Current JupyterLab version
        logger - logging.Logger: Server logger
    r.   Nc                    K   yw)r<   Nr*   )r1   s    r   r6   zNeverCheckForUpdate.__call__   s      s   )r!   r"   r#   r$   r   r6   r*   r   r   rX   rX   w   s    	$ r   rX   c                   Z     e Zd ZdZ	 ddedz  ddf fdZej                  d        Z xZ	S )CheckForUpdateHandlerziCheck for Updates API handler.

    Args:
        update_check: The class checking for a new version
    Nupdate_checkerr.   c                     t         |           |t        t              n|| _        | j
                  | j                  _        y r0   )super
initializerX   r   r\   logrO   )r1   r\   	__class__s     r   r_   z CheckForUpdateHandler.initialize   s<     	0>0F,N 	 &*XX"r   c                   K   d}| j                          d{   }|rt        |t              r|dfn|\  }}t        j                  t
        j                        j                         dz  }t        j                  |j                               j                         }t        |||d|d|dgdi	      }| j                  d
       | j                  t        j                   d|dn
t#        |      i             y7 w)zCheck for updates.
        Response:
            {
                "notification": Optional[Notification]
            }
        Nr*   )tzg     @@r@   rS   updateidtagsr   r   r   r   r   r       notification)r\   
isinstancer'   r   nowr   utcr   hashlibsha1encode	hexdigestr   
set_statusfinishrG   dumpsr   )r1   rj   outr   r   rl   hash_s          r   rJ   zCheckForUpdateHandler.get   s      '')))3C)=S"I3MGT,,(,,/99;fDCLL!12<<>E'z!BCL 	JJ0D&Q]J^_`	
 *s   C<C:C"C<r0   )
r!   r"   r#   r$   r:   r_   r   authenticatedrJ   __classcell__ra   s   @r   r[   r[      sC     15.&-. 
. 	
 
r   r[   c                   Z     e Zd ZdZ	 ddedz  ddf fdZej                  d        Z xZ	S )NewsHandlerzSNews API handler.

    Args:
        news_url: The Atom feed to fetch for news
    Nnews_urlr.   c                 0    t         |           || _        y r0   )r^   r_   r|   )r1   r|   ra   s     r   r_   zNewsHandler.initialize   s     	 r   c                   
K   g }t        j                         }| j                  t        j                  d      
ddij                         D ]  \  }}t        j                  ||        	 |j                  | j                  ddi       d{   }t        j                  |j                        }
fd}t        ||j                  d	            }|j                  |       | j#                  d       | j%                  t'        j(                  dt+        t        t,        |            i             y7 # t        $ r4}	| j                  j!                  d
| j                   |	       Y d}	~	d}	~	ww xY ww)zpGet the news.

        Response:
            {
                "news": List[Notification]
            }
        NrA   atomzhttp://www.w3.org/2005/Atomr=   zapplication/atom+xmlr>   c                     ddt         dt         d z  dt         f fd} |d      } |d      } |d      } |d|      } |d	d
      } j                  d      }t        |      dkD  r#t        t	        d |            }|r|d   n|d   }	nt        |      dk(  r|d   nd }	|	|	j                  d      nd }
|r| d| n|}t        |      }t        |      }t        |||d|
d nj                  d      |
fd|dgdi      }|S )Nattrr   r.   c                 r    j                  d|        }||j                  S ||S d|  }t        |      )Nzatom:z7atom feed entry does not contain a required attribute: )findtextKeyError)r   r   	node_itemerror_mnodexml_namespacess       r   get_xml_textz:NewsHandler.get.<locals>.build_entry.<locals>.get_xml_text   sU    $(IIdVnn$M	$0#,>>1$0#*N #ZZ^Y_ ` $ #+7"33r   titlerf   updated	publishedsummary )r   z	atom:link   c                 *    | j                  d      dk(  S )Nrel	alternate)rJ   )elems    r   <lambda>z6NewsHandler.get.<locals>.build_entry.<locals>.<lambda>   s    TXXe_P[=[r   r   href
r@   zOpen full postrS   newsre   rh   r0   )	r'   findalllenlistfilterrJ   r   r   __)r   r   entry_titleentry_identry_updatedentry_publishedentry_summarylinksr   	link_node
entry_linkr   modified_at
created_atrj   rU   r   s   `              r   build_entryz$NewsHandler.get.<locals>.build_entry   sC   
43 
4t 
4s 
4 #/w"7K+D1H$0$;M&2;&NO$0B$GM LLnEE5zA~$(0[]b)c$d	4=IaL58	03E
aE!HT	:C:Ov!6UYJCPR?VaG"1-"@K!0!AJ#/ '",#.#%- " "HH%56&
 #&.)/%!$L$ ('r   z
atom:entryz,Failed to get announcements from Atom feed: rB   ri   r   )r   rD   r|   r
   rK   itemsETregister_namespacerE   
fromstringrI   mapr   extendrN   r`   rP   rr   rs   rG   rt   r   r   )r1   r   rQ   keyspecrR   treer   entriesrV   rU   r   s             @@r   rJ   zNewsHandler.get   sM      002==$OOL1E %&CDN+113	T%%c40 4>!,!2!2MM+-CD "3 "  }}X]]3/(b k4<<n+UVG$ 	DJJS->(?@ABAr  B4==/R   sD   A*E9/"D9 D7AD9 (AE97D9 9	E6*E1,E91E66E9r0   )
r!   r"   r#   r$   r'   r_   r   rw   rJ   rx   ry   s   @r   r{   r{      sF      $!*! 
! 	UC UCr   r{   z/lab/api/newsz/lab/api/update))r$   r7   rn   rG   xml.etree.ElementTreeetreeElementTreer   collections.abcr   dataclassesr   r   r   r   r   jupyter_server.base.handlersr	   #jupyterlab_server.translation_utilsr
   packaging.versionr   tornador   r   jupyterlab._versionr   ISO8601_FORMATrF   rM   r'   r   r   ABCr,   r:   rX   r[   r{   news_handler_pathcheck_update_handler_pathr*   r   r   <module>r      s    +
    " " % 0 0 ' 3 : # # +&E R =C = $0 0 0(' '6&& &R+ 2+
J +
\dC* dCN % . r   