
    hje                        d Z ddlmZ ddlZ ej        e          ZddlZddlZddl	m
Z
 ddlmZ ddlmZ dd	lmZmZmZmZ dd
lmZmZ dZ G d de          ZdS )zI Abstract base class for subcommands that output to a file (or stdout).

    )annotationsN)abstractmethodsplitext   )Document   )ArgArgsArgument
Subcommand)!build_single_handler_applicationsdie)FileOutputSubcommandc                      e Zd ZU dZded<   edd            Zedd	            ZddZddZ	ddZ
ddZedd            ZdS )r   zG Abstract subcommand to output applications as some type of file.

    str	extensionoutput_type_namereturnr
   c                2    dt          ddd|z  d          fS )a   Returns a positional arg for ``files`` to specify file inputs to
        the command.

        Subclasses should include this to their class ``args``.

        Example:

            .. code-block:: python

                class Foo(FileOutputSubcommand):

                    args = (

                        FileOutputSubcommand.files_arg("FOO"),

                        # more args for Foo

                    ) + FileOutputSubcommand.other_args()

        fileszDIRECTORY-OR-SCRIPT+z1The app directories or scripts to generate %s forN)metavarnargshelpdefault)r   )clsr   s     Elib/python3.11/site-packages/bokeh/command/subcommands/file_output.py	files_argzFileOutputSubcommand.files_arg?   s4    , )EIYZ	
 
 
  	    r   c                ^    dt          ddt          d          fdt          ddd	
          ffS )a.   Return args for ``-o`` / ``--output`` to specify where output
        should be written, and for a ``--args`` to pass on any additional
        command line args to the subcommand.

        Subclasses should append these to their class ``args``.

        Example:

            .. code-block:: python

                class Foo(FileOutputSubcommand):

                    args = (

                        FileOutputSubcommand.files_arg("FOO"),

                        # more args for Foo

                    ) + FileOutputSubcommand.other_args()

        )z-oz--outputFILENAMEappendz1Name of the output file or - for standard output.)r   actiontyper   z--argszCOMMAND-LINE-ARGSz...zMAny command line arguments remaining are passed on to the application handler)r   r   r   )r   r   )r   s    r   
other_argszFileOutputSubcommand.other_args\   sW    0  "H	" " "  x+d   
 	
r    routeextc                6    |dk    rd}n
|dd         }| d| S )


        /index   N. )selfr'   r(   bases       r   filename_from_routez(FileOutputSubcommand.filename_from_route   s1     C<<DD9Dr    argsargparse.NamespaceNonec                B   fdj         D             }t          j         |          }j        g }nt          j                  }t	          |          t	          |          k    r.t          dt	          |          t	          |          fz             |                                D ]t\  }}|                                }t	          |          dk    r|                    d          }n| 	                    || j
                  }|                     ||           udS )r*   c                     i | ]
}|j         S r/   )r3   ).0fr3   s     r   
<dictcomp>z/FileOutputSubcommand.invoke.<locals>.<dictcomp>   s    444A!di444r    NzC--output/-o was given too many times (%d times for %d applications)r   )r   r   outputlistlenr   itemscreate_documentpopr2   r   
write_file)	r0   r3   argvsapplicationsoutputsr'   appdocfilenames	    `       r   invokezFileOutputSubcommand.invoke   s&    54444448UKK;!#GG4;''Gw<<#l++++UWs<0012 3 3 3 )..00 	1 	1LUC%%''C7||a";;q>>33E4>JJOOD(C0000	1 	1r    rG   rF   r   c                    d fd}d fd}                                }t          |t                    r ||           dS t          |t                    r ||           dS d	k    st	          |          d
k    rdfd}ndfd}t          |          D ]Z\  }}	t          |	t                    r ||	 ||                     0t          |	t                    r ||	 ||                     [dS )r*   contentr   rG   r   r5   c                    |dk    rt          |            n?t          |dd          5 }|                    |            d d d            n# 1 swxY w Y                       |           d S )N-wzutf-8)encoding)printopenwriteafter_write_file)rJ   rG   filer3   rF   r0   s      r   	write_strz2FileOutputSubcommand.write_file.<locals>.write_str   s    3g(C'::: (dJJw'''( ( ( ( ( ( ( ( ( ( ( ( ( ( (!!$#66666s   AAAbytesc                   |dk    r%t           j        j                            |            n=t	          |d          5 }|                    |            d d d            n# 1 swxY w Y                       |           d S )NrL   wb)sysstdoutbufferrQ   rP   rR   )rJ   rG   r9   r3   rF   r0   s      r   write_bytesz4FileOutputSubcommand.write_file.<locals>.write_bytes   s    3
!''0000(D)) %QGGG$$$% % % % % % % % % % % % % % %!!$#66666s   AA#&A#rL   r-   iintc                    S )Nr/   )r\   rG   s    r   indexedz0FileOutputSubcommand.write_file.<locals>.indexed   s    #Or    c                :    t                    \  }}| d|  | S )N_r   )r\   rootr(   rG   s      r   r_   z0FileOutputSubcommand.write_file.<locals>.indexed   s-     ( 2 2ID#"--Q----r    N)rJ   r   rG   r   r   r5   )rJ   rU   rG   r   r   r5   )r\   r]   r   r   )file_contents
isinstancer   rU   r=   	enumerate)
r0   r3   rG   rF   rT   r[   contentsr_   r\   rJ   s
   ````      r   rA   zFileOutputSubcommand.write_file   s   	7 	7 	7 	7 	7 	7 	7 	7	7 	7 	7 	7 	7 	7 	7 	7 %%dC00h$$ 	5Ih)))))%(( 	5K(+++++3#h--1"4"4$ $ $ $ $ $ $. . . . . . (11 5 5
7gs++ 5Igwwqzz2222// 5K444	5 5r    c                    dS )r*   Nr/   )r0   r3   rG   rF   s       r   rR   z%FileOutputSubcommand.after_write_file   s	     	r    %str | bytes | list[str] | list[bytes]c                    t                      )a    Subclasses must override this method to return the contents of the output file for the given doc.
        subclassed methods return different types:
        str: html, json
        bytes: SVG, png

        Raises:
            NotImplementedError

        )NotImplementedError)r0   r3   rF   s      r   rc   z"FileOutputSubcommand.file_contents   s     "###r    N)r   r   r   r
   )r   r   )r'   r   r(   r   r   r   )r3   r4   r   r5   )r3   r4   rG   r   rF   r   r   r5   )r3   r4   rF   r   r   rh   )__name__
__module____qualname____doc____annotations__classmethodr   r&   r2   rH   rA   rR   r   rc   r/   r    r   r   r   7   s          
 NNN   [8 #
 #
 #
 [#
J	 	 	 	1 1 1 14'5 '5 '5 '5T    
$ 
$ 
$ ^
$ 
$ 
$r    r   )rn   
__future__r   logging	getLoggerrk   logargparserX   abcr   os.pathr   documentr   
subcommandr
   r   r   r   utilr   r   __all__r   r/   r    r   <module>r|      s%    # " " " " " g!!  



             !                      : 9 9 9 9 9 9 9k$ k$ k$ k$ k$: k$ k$ k$ k$ k$r    