o
    Zh0h                     @   s  d Z ddlZddlZddlZddlZddlmZ ddlZddlm	Z	m
Z
mZmZ ddlmZ ddlmZ ddlmZ G d	d
 d
ejZG dd dejZedddZejddd ejddd ejdddd ejdddddd ejddd d ejd!d"d#d ejd$d%dd&d'd ejd(d)d ejd*ed+d, ejd-d.d ejd/d0d1d2 ejd3d0d4d2 ejd5d0d6d2 ejd7d8d0d9d2 ejd:d0d;d2 ejd<d0d=d2 ejd>d?ed@dA ejdBd0dCd2 ejdDd0dEd2 ejdFdGdHdIdJ ejdKdLedMdA ejdNdOd0dPd2 ejdQdRd0dSd2 ejdTdUd0dVd2 ejdWdXdYe dZd[ ejd\d]edd^d_ ejd`daedbdA ejdgi e	 ddde
fdcddZe j deej 7  _ edfkr]e  dS dS )hz%Command-line interface to WeasyPrint.    N)partial   )DEFAULT_OPTIONSHTMLLOGGER__version__)VARIANTS)pango)default_url_fetcherc                   @   s   e Zd Zdd ZdS )	PrintInfoc                  O   s   t  }td|j td|j td|j td|j t  tdt tdtj	 d  tdt
j td	t  t  d S )
NzSystem:zMachine:zVersion:zRelease:zWeasyPrint version:zPython version:r   zPydyf version:zPango version:)platformunameprintsystemmachineversionreleaser   syssplitpydyfr	   pango_versionexit)___r    r   I/var/www/html/rh/venv/lib/python3.10/site-packages/weasyprint/__main__.py__call__   s   
zPrintInfo.__call__N)__name__
__module____qualname__r   r   r   r   r   r      s    r   c                       s4   e Zd Z fddZ fddZedd Z  ZS )Parserc                    s   i | _ t j|i | d S )N)
_argumentssuper__init__)selfargskwargs	__class__r   r   r#   !   s   zParser.__init__c                    sJ   t  j|i | |d d}||d< |d d dk|d< || j|< d S )N-flagsr   
positional)r"   add_argumentlstripr!   )r$   r%   r&   keyr'   r   r   r-   %   s
   zParser.add_argumentc                 C   s   | j d| j d< g }| j  D ]i\}}|d |dd}|d D ]}|| |d s;|dv r;|d| d	 |d
 q#d|d< |d|d d   |d dd   d d|v rpd
|d }|d| d |dkry|d qd|S )Nhelpz.. option:: actionstorer+   r,   )r2   appendz <>z, 

r)   z  r   r   z.

choicesz  Possible choices: r3   z-  This option can be passed multiple times.

 )r!   popitemsr3   getupperjoin)r$   datar/   r%   r1   flagr6   r   r   r   	docstring,   s&   

.

zParser.docstring)r   r   r   r#   r-   propertyr?   __classcell__r   r   r'   r   r        s
    r    
weasyprintzRender web pages to PDF.)progdescriptioninputz1URL or filename of the HTML input, or - for stdin)r0   outputz1filename where output is written, or - for stdoutz-ez
--encodingz"force the input character encodingz-sz--stylesheetr3   stylesheetsz)URL or filename for a user CSS stylesheet)r1   destr0   z-mz--media-typez/media type to use for @media, defaults to printz-uz
--base-urluz   base for relative URLs in the HTML input, defaults to the input’s own filename or URL or the current directory for stdinz-az--attachmentattachmentsz7URL or filename of a file to attach to the PDF documentz--pdf-identifierzPDF file identifierz--pdf-variantzPDF variant to generate)r6   r0   z--pdf-versionzPDF version numberz--pdf-forms
store_truezinclude PDF forms)r1   r0   z--uncompressed-pdfz9do not compress PDF content, mainly for debugging purposez--custom-metadataz-include custom HTML meta tags in PDF metadataz-pz--presentational-hintsz follow HTML presentational hintsz--srgbzinclude sRGB color profilez--optimize-imagesz5optimize size of embedded images with no quality lossz-jz--jpeg-qualityz+JPEG quality between 0 (worst) to 95 (best))typer0   z--full-fontsz)embed unmodified font files when possiblez	--hintingz*keep hinting information in embedded fontsz-cz--cache-foldercachezistore cache on disk instead of memory, folder is created if needed and cleaned after the PDF is generated)rH   r0   z-Dz--dpiz4set maximum resolution of images embedded in the PDFz-vz	--verbosez&show warnings and information messagesz-dz--debugzshow debugging messagesz-qz--quietzhide logging messagesz	--versionr   zWeasyPrint version u,   print WeasyPrint’s version number and exit)r1   r   r0   z-iz--infoz!print system information and exit)r1   nargsr0   z-tz	--timeoutz(Set timeout in seconds for HTTP requestsc                 C   s.  t | }|jdkr"|ptjj}|jdu rd|_n|jdkr!d|_n|j}|jdkr1|p/tjj}n|j}t	}|j
durBtt	|j
d}dd t| D }|jrWttj n	|jr`ttj |jst }	|jrs|	td n|	td	 t|	 |||j|j|j|d
}
|
j|fi | dS )zThe ``weasyprint`` program takes at least two arguments:

    .. code-block:: sh

        weasyprint [options] <input> <output>

    r*   N.r7   )timeoutc                 S   s   i | ]\}}|t v r||qS r   )r   ).0r/   valuer   r   r   
<dictcomp>   s    zmain.<locals>.<dictcomp>zB%(levelname)s: %(filename)s:%(lineno)d (%(funcName)s): %(message)sz%(levelname)s: %(message)s)base_urlencoding
media_typeurl_fetcher)PARSER
parse_argsrE   r   stdinbufferrS   rF   stdoutr
   rO   r   varsr9   debugr   setLevelloggingDEBUGverboseINFOquietStreamHandlersetFormatter	Formatter
addHandlerrT   rU   	write_pdf)argvr[   rY   r   r%   sourcerF   rV   optionshandlerhtmlr   r   r   main   sJ   








rn   r5   __main__r   )__doc__argparser_   r   r   	functoolsr   r   r7   r   r   r   r   pdfr   text.ffir	   urlsr
   Actionr   ArgumentParserr    rW   r-   intset_defaultsrn   r?   r   r   r   r   r   <module>   s    "6

