
    GhJ'                     |   S r SSKrSSKrSSKrSSKJs  Jr  SSKJ	r	  SSK
JrJrJr  SSKJrJr  SSKJrJr  SSKJr  SSKJr  SS	KJr  SS
KJrJr  SSKJr  SrSrSr S\!4S jr"\" SS9 " S S5      5       r# " S S\RH                  5      r% " S S\%5      r& " S S\%5      r' " S S\5      r( " S S\5      r)Sr*S r+g)!z%Announcements handler for JupyterLab.    N)	Awaitable)asdict	dataclassfield)datetimetimezone)OptionalUnion)
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                 P    [         R                  " U 5      R                  5       S-  $ )Ni  )r   fromisoformat	timestamp)r   s    tC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\jupyterlab/handlers/announcements.pyformat_datetimer      s!    !!&)335<<    T)frozenc                   |    \ rS rSr% Sr\\S'   \\S'   \\S'   Sr\\S'   \	" \
S9r\
\\4   \S	'   \	" \S9r\\S
'   Srg)Notification   u+  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options N)__name__
__module____qualname____firstlineno____doc__float__annotations__strr    r   tupler"   dictr#   __static_attributes__r$   r   r   r   r      sJ    	 LD#!%8D%S/8$/GT/r   r   c                   |    \ rS rSrSrS\SS4S jr\R                  S\	\
S\\\\\\4   4   4      4S j5       rSrg)	CheckForUpdateABC4   zAbstract class to check for update.

Args:
    version: Current JupyterLab version

Attributes:
    version - str: Current JupyterLab version
    logger - logging.Logger: Server logger
versionreturnNc                     Xl         g Nr3   )selfr3   s     r   __init__CheckForUpdateABC.__init__?   s    r   c                 $   #    Sn[        U5      e7f)zGet 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)r8   msgs     r   __call__CheckForUpdateABC.__call__B   s      >!#&&s   r7   )r%   r&   r'   r(   r)   r,   r9   abcabstractmethodr   r
   r-   r>   r/   r$   r   r   r1   r1   4   s_       		'	%c5eCQTHoAU;V0V*W X 	' 	'r   r1   c                   @    \ rS rSrSrS\\\\\\4   4      4S jrSr	g)CheckForUpdateO   zDefault class to check for update.

Args:
    version: Current JupyterLab version

Attributes:
    version - str: Current JupyterLab version
    logger - logging.Logger: Server logger
r4   c                   #    [         R                  " 5       n UR                  [        SS0S9I Sh  vN n[        R
                  " UR                  5      R                  S5      nUS   n[        U R                  5      [        U5      :  aF  [        R                  " S5      nUR                  SU S	35      UR                  S
5      [         U 344$ g N! [         a$  nU R                  R!                  SUS9   SnAgSnAff = f7f)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infor3   
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   r3   r   load__JUPYTERLAB_RELEASE_URL	Exceptionloggerdebug)r8   http_clientresponsedatalast_versiontranses          r   r>   CheckForUpdate.__call__Z   s     !002	(..+');< /  H ::hmm,008D	?L
 T\\"U<%88"5HH0>[\]XXn-2H1I,/XY 
 #  	KK<qI	s?   DC C8C +A)DC 
D C?:D?DDr$   N)
r%   r&   r'   r(   r)   r   r-   r,   r>   r/   r$   r   r   rC   rC   O   s*    	%U38_0D*E F r   rC   c                   ,    \ rS rSrSrS\S   4S jrSrg)NeverCheckForUpdatex   a  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
r4   Nc                    #    g7f)rF   Nr$   )r8   s    r   r>   NeverCheckForUpdate.__call__   s
      s   r$   )r%   r&   r'   r(   r)   r   r>   r/   r$   r   r   rc   rc   x   s    	$ r   rc   c                   h   ^  \ rS rSrSr S	S\\   SS4U 4S jjjr\R                  S 5       r
SrU =r$ )
CheckForUpdateHandler   z]Check for Updates API handler.

Args:
    update_check: The class checking for a new version
Nupdate_checkerr4   c                    > [         TU ]  5         Uc  [        [        5      OUU l        U R
                  U R                  l        g r6   )super
initializerc   r   rj   logrY   )r8   rj   	__class__s     r   rm    CheckForUpdateHandler.initialize   s<     	0>0F,N 	 &*XX"r   c                 
  #    SnU R                  5       I Sh  vN nU(       a  [        U[        5      (       a  US4OUu  p4[        R                  " [
        R                  S9R                  5       S-  n[        R                  " UR                  5       5      R                  5       n[        UUUSUSUS/S.0S	9nU R                  S
5        U R                  [        R                   " SUc  SO
[#        U5      05      5        g N7f)zXCheck for updates.
Response:
    {
        "notification": Optional[Notification]
    }
Nr$   )tzg     @@rJ   r]   updateidtagsr   r   r   r    r"   r#      notification)rj   
isinstancer,   r   nowr   utcr   hashlibsha1encode	hexdigestr   
set_statusfinishrQ   dumpsr   )r8   ry   outr   r"   r{   hash_s          r   rT   CheckForUpdateHandler.get   s      '')))3C)=)=S"I3MG,,(,,/99;fDCLL!12<<>E'z!BCL 	JJ0D&Q]J^_`	
 *s   DDC)D)rj   r6   )r%   r&   r'   r(   r)   r	   rC   rm   r   authenticatedrT   r/   __classcell__ro   s   @r   rh   rh      sH     48. 0. 
. . 	
 
r   rh   c                   h   ^  \ rS rSrSr S	S\\   SS4U 4S jjjr\R                  S 5       r
SrU =r$ )
NewsHandler   zGNews API handler.

Args:
    news_url: The Atom feed to fetch for news
Nnews_urlr4   c                 .   > [         TU ]  5         Xl        g r6   )rl   rm   r   )r8   r   ro   s     r   rm   NewsHandler.initialize   s     	 r   c                   ^
^#    / n[         R                  " 5       nU R                  b  [        R                  " S5      m
SS0mTR                  5        H  u  p4[        R                  " X45        M      UR                  U R                  SS0S9I Sh  vN n[        R                  " UR                  5      nU
U4S jn[        XvR                  S	T5      5      nUR                  U5        U R#                  S5        U R%                  [&        R(                  " S[+        [        [,        U5      5      05      5        g N! [         a1  n	U R                  R!                  S
U R                   3U	S9   Sn	A	NSn	A	ff = f7f)zHGet the news.

Response:
    {
        "news": List[Notification]
    }
NrK   atomzhttp://www.w3.org/2005/AtomrG   zapplication/atom+xmlrH   c                 B  >^  SS[         S[        [            S[         4U U4S jjjnU" S5      nU" S5      nU" S5      nU" SU5      nU" S	S
S9nT R                  ST5      n[        U5      S:  a(  [	        [        S U5      5      nU(       a  US   OUS   n	O[        U5      S:X  a  US   OS n	U	b  U	R                  S5      OS n
U(       a  SR                  X&/5      OUn[        U5      n[        U5      n[        UUUSU
c  S OTR                  S5      U
4SUS/S.0S9nU$ )Nattrr   r4   c                 v   > TR                  SU  3T5      nUb  UR                  $ Ub  U$ SU  3n[        U5      e)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_text:NewsHandler.get.<locals>.build_entry.<locals>.get_xml_text   sU    $(IIdVnn$M	$0#,>>1$0#*N #ZZ^Y_ ` $ #+7"33r   titleru   updated	publishedsummary )r   z	atom:link   c                 *    U R                  S5      S:H  $ )Nrel	alternate)rT   )elems    r   <lambda>6NewsHandler.get.<locals>.build_entry.<locals>.<lambda>   s    TXXe_P[=[r   r   href
rJ   zOpen full postr]   newsrt   rw   r6   )r,   r	   findalllenlistfilterrT   joinr   r   rV   )r   r   entry_titleentry_identry_updatedentry_publishedentry_summarylinksr   	link_node
entry_linkr   modified_at
created_atry   r_   r   s   `              r   build_entry$NewsHandler.get.<locals>.build_entry   sS   
43 
4# 
4RU 
4 
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!6UYJ DQ		;">?Va  #2-"@K!0!AJ#/ '",#.#%- " "HH%56&
 #&.)/%!$L$ ('r   z
atom:entryz,Failed to get announcements from Atom feed: rL   rx   r   )r   rN   r   r   rU   itemsETregister_namespacerO   
fromstringrS   mapr   extendrX   rn   rZ   r   r   rQ   r   r   r   )r8   r   r[   keyspecr\   treer   entriesr`   r_   r   s             @@r   rT   NewsHandler.get   sB      002==$OOL1E %&CDN+113	%%c0 4@!,!2!2MM+-CD "3 "  }}X]]31(f k<<n+UVG$ 	DJJS->(?@ABEv  B4==/R  sD   A.E:3D< D:AD< *AE::D< <
E7'E2-E:2E77E:)r   r6   )r%   r&   r'   r(   r)   r	   r,   rm   r   r   rT   r/   r   r   s   @r   r   r      sK     #'!3-! 
! ! 	WC WCr   r   z/lab/api/newsz/lab/api/update),r)   r@   r}   rQ   xml.etree.ElementTreeetreeElementTreer   collections.abcr   dataclassesr   r   r   r   r   typingr	   r
   jupyter_server.base.handlersr   #jupyterlab_server.translation_utilsr   packaging.versionr   tornador   r   jupyterlab._versionr   ISO8601_FORMATrP   rW   r,   r   r   ABCr1   rC   rc   rh   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 +
\fC* fCR % . r   