
    dh              
           S r SSKrSSKJr  SSKJrJrJr  SSKJ	r	  SSK
Jr  S\S\S	\S
\S\4
S jrS\S\4S jr " S S\5      rg)zLoads .ipynb notebook files.    N)Path)AnyListUnion)Document)
BaseLoadercellinclude_outputsmax_output_length	tracebackreturnc                    U S   nU S   nU(       a   U S   nU(       a  US:X  a  W(       a  SUS   R                  5       ;   a@  US   S   nUS   S   nU(       a  US   S   nS	U S
U SU SU SU S3$ S	U S
U SU SU S3	$ US   S   S:X  a,  US   S   n[        U[        U5      5      n	S	U S
U SUSU	  S3$  gS	U S
U S3$ ! [          a     Nf = f)aS  Combine cells information in a readable format ready to be used.

Args:
    cell: A dictionary
    include_outputs: Whether to include the outputs of the cell.
    max_output_length: Maximum length of the output to be displayed.
    traceback: Whether to return a traceback of the error.

Returns:
    A string with the cell information.

	cell_typesourceoutputscodeenamer   evaluer   'z	' cell: 'z'
, gives error 'z', with description 'z'
and traceback 'z'

z',with description 'output_typestreamtextz'
 with output: 'N )KeyErrorkeysminlen)
r	   r
   r   r   r   r   output
error_nameerror_value
min_outputs
             e/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/document_loaders/notebook.pyconcatenate_cellsr#      sj    [!I(^F	)_F 9.6fQinn&&7+J )H-K"1Ik2		{)F83Ej\ R**5 7&&/[7 	{)F83Ej\ R))4U< AY}%1AYv&F.F<JI;ix 0";J/07 2  9+Yvhe447  		s   C 
CCxc                 P   [        U [        5      (       a  U R                  SS5      $ [        U [        5      (       a  U  Vs/ sH  n[	        U5      PM     sn$ [        U [
        5      (       a.  U R                  5        VVs0 sH  u  p#U[	        U5      _M     snn$ U $ s  snf s  snnf )zMRecursively remove newlines, no matter the data structure they are stored in.
r   )
isinstancestrreplacelistremove_newlinesdictitems)r$   elemkvs       r"   r+   r+   @   s     !Syyr""	At		234!$%!44	At		45GGI>I&1?1%%I>>	 5>s   B B"c                   `    \ rS rSrSr    SS\\\4   S\S\	S\S\4
S jjr
S	\\   4S
 jrSrg)NotebookLoaderM   z'Load `Jupyter notebook` (.ipynb) files.pathr
   r   remove_newliner   c                 @    Xl         X l        X0l        X@l        XPl        g)a  Initialize with a path.

Args:
    path: The path to load the notebook from.
    include_outputs: Whether to include the outputs of the cell.
        Defaults to False.
    max_output_length: Maximum length of the output to be displayed.
        Defaults to 10.
    remove_newline: Whether to remove newlines from the notebook.
        Defaults to False.
    traceback: Whether to return a traceback of the error.
        Defaults to False.
N	file_pathr
   r   r5   r   )selfr4   r
   r   r5   r   s         r"   __init__NotebookLoader.__init__P   s     * .!2,"    r   c                   ^  [        T R                  5      n[        USS9 n[        R                  " U5      nSSS5        WS    VVVs/ sH/  nUR                  5        VVs0 sH  u  pVUS;   d  M  XV_M     snnPM1     nnnnT R                  (       a  [        [        [        U5      5      nSR                  [        [        U 4S jU5      5      5      nS[        U5      0n	[        XS	9/$ ! , (       d  f       N= fs  snnf s  snnnf )
zLoad documents.utf8)encodingNcells)r   r   r   r   c                 \   > [        U TR                  TR                  TR                  5      $ )N)r#   r
   r   r   )r$   r9   s    r"   <lambda>%NotebookLoader.load.<locals>.<lambda>   s$    /4//1G1Gr<   r   )page_contentmetadata)r   r8   openjsonloadr-   r5   r*   mapr+   joinr(   r   )
r9   pfdr	   r/   r0   filtered_datar   rE   s
   `         r"   rH   NotebookLoader.loadk   s      !f%		!A &
 '

" !%

Xfq5W0WTQTX" 	 

  _m!DEMww "		
 c!f%d>??1 &% Y
s)   C+	D!C<0C<6D+
C9<Dr7   N)F
   FF)__name__
__module____qualname____firstlineno____doc__r   r(   r   boolintr:   r   r   rH   __static_attributes__ r<   r"   r2   r2   M   sd    1
 !&!#$#CI# # 	#
 # #6@	h@r<   r2   )rU   rG   pathlibr   typingr   r   r   langchain_core.documentsr   )langchain_community.document_loaders.baser   r,   rV   rW   r(   r#   r+   r2   rY   r<   r"   <module>r^      si    "   # # - @1
1!%1:=1JN11h
s 
s 
<@Z <@r<   