
    Xwg/                    4   d dl mZ d dl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
mZ d dlmZ d dlmZ d dlmZ d dlmZ  ej(                  e      ZeZdj1                         Zd	Zd
ZdZd Z G d d      Zd Zd Z d Z!dddZ"ddZ#d Z$edk(  r e        yy)    )annotationsN)__version__)
httpConfig)DEFAULT_CSS)pisaDocument)getFilea	  

USAGE: pisa [options] SRC [DEST]

SRC
  Name of a HTML file or a file pattern using * placeholder.
  If you want to read from stdin use "-" as file name.
  You may also load an URL over HTTP. Take care of putting
  the <src> in quotes if it contains characters like "?".

DEST
  Name of the generated PDF file or "-" if you like
  to send the result to stdout. Take care that the
  destination file is not already opened by an other
  application like the Adobe Reader. If the destination is
  not writeable a similar name will be calculated automatically.

[options]
  --base, -b:
    Specify a base path if input come via STDIN
  --css, -c:
    Path to default CSS file
  --css-dump:
    Dumps the default CSS definitions to STDOUT
  --debug, -d:
    Show debugging informations
  --encoding:
    the character encoding of SRC. If left empty (default) this
    information will be extracted from the HTML header data
  --help, -h:
    Show this help text
  --quiet, -q:
    Show no messages
  --start-viewer, -s:
    Start PDF default viewer on Windows and MacOSX
    (e.g. AcrobatReader)
  --version:
    Show version information
  --warn, -w:
    Show warnings
  --xml, --xhtml, -x:
    Force parsing in XML Mode
    (automatically used if file ends with ".xml")
  --html:
    Force parsing in HTML Mode (default)

[HTTP Connection options]

  --http_nosslcheck:
    No check ssl certificate.

See http.client.HTTPSConnection documentation for this parameters

  --http_key_file
  --http_cert_file
  --http_source_address
  --http_timeout
a6  
Copyright 2010 Dirk Holtwick, holtwick.it

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.z$%(levelname)s [%(name)s] %(message)szB%(levelname)s [%(name)s] %(pathname)s line %(lineno)d: %(message)sc                 "    t        t               y N)printUSAGE     E/var/www/horilla/myenv/lib/python3.12/site-packages/xhtml2pdf/pisa.pyusager   p   s	    	%Lr   c                  .    e Zd ZdZddddZddZd	dZy)
pisaLinkLoaderz
    Helper to load page from an URL and load corresponding
    files to temporary files. If getFileName is called it
    returns the temporary filename and takes care to delete
    it when pisaLinkLoader is unloaded.
    T)quietc               .    || _         || _        g | _        y r
   )r   src	tfileList)selfr   r   s      r   __init__zpisaLinkLoader.__init__|   s    
$&r   c                P    | j                   D ]  }t        j                  |        y r
   )r   osremove)r   paths     r   __del__zpisaLinkLoader.__del__   s     NN 	DIIdO	r   Nc                   t        j                  |xs | j                  |      }t        |      }|j	                         }|j
                  }| j                  j                  |       | j                  st        d| d|        |S )Nz
  Loading  to )
urlparseurljoinr   r   getNamedFilenamer   appendr   r   )r   r#   relativeurlinstancefiletmpdownloadedr   s          r   getFileNamezpisaLinkLoader.getFileName   ss    x3488T:3<$113 %%d#zzJse4v./r   )returnNoner
   )__name__
__module____qualname____doc__r   r   r)   r   r   r   r   r   t   s     &* '

r   r   c                 &   dt         j                  v rut        d       dd l} dd l}| j                         }|j                  t               |j                  |      j                         j                  d      j                          y t                y )Nz	--profilez*** PROFILING ENABLEDr   
cumulative)sysargvr   cProfilepstatsProfileruncallexecuteStats
strip_dirs
sort_statsprint_stats)r4   r5   profs      r   commandr>      se    chh%&!WT%%'22<@LLN	r   c                 t   	 t        j                   t        j                  dd  dg d      \  } }d}d}d}d}d }d}d }d }	d }
d }d }t        j                  }t        } D ]  \  }}|dv rt	                t        j
                          *|dv r%t        t               t        j
                  d       S|d	v r%t        t               t        j
                  d       ||d
v rt        t               t                t        d       t        d       t        dt        j                  z         t        dt        j                  z         t        d       dd l}t        d|j                  z         t        j
                  d       %|dv rd}-|dv rd}5|dv rt!        |t        j"                        }U|dv r't        j$                  }t&        }|sst)        |      }|dv r|}|dv r|}|dv r|r|}
|dv r&t+        |      5 }|j-                         }d d d        |dv rt        t.                y |dv rt        j0                  }|dv rd}	|dv rd}	t3        j4                  ||      s |st        j6                  ||       t9              d vrt	                t        j
                  d       t9        |      dk(  r|\  }}n|d   }d }d!|v rt;        j:                  |      n|g}|D ]  }|	|j=                         j?                  d"      }	d }|d#k(  s|)t        j@                  }tC        jD                         }|r|}n|jG                  d$      rS|}tI        |      jK                         }d%jM                  tO        jP                  |      dd&       jS                  d'd#      }nFtB        jT                  jW                  |      x}}t+        |d(      5 }|j-                         }d d d        ||}|j=                         j?                  d)      s|j=                         j?                  d*      r#d+jM                  |jY                  d+      d d,       }|d+z   |j=                         z   }t[        d-      D ])  }	 t+        |d.      5 }|j]                          d d d         n n|}d}|d#k(  s|rft        j                  d0k(  r@dd l0}|jc                  t        j0                  je                         tB        jf                         t        j0                  }d}nStB        jT                  jW                  |      }	 t+        |d.      5 }|j]                          d d d        t+        |d.      }d}|st        d2| d3| d4       ti        ||||t        j0                  |||||	|
|5       |r|jk                          |r|j]                          |r|s|st        d6|z         tm        |        y # t         j                  $ r# t	                t        j
                  d       Y w xY w# 1 sw Y   xY w# 1 sw Y   KxY w# 1 sw Y   xY w# t^        $ r Y nw xY w|d/||j=                         fz  z   }# 1 sw Y   %xY w# t^        $ r' t        d1|z         t        j
                  d       Y Ww xY w)7N   	dhqstwcxb)r   helpzstart-viewerstartzdebug=	copyrightversionwarnztempdir=zformat=zcss=zbase=zcss-dumpzxml-dumpxhtmlxmlhtmlz	encoding=systemprofilehttp_nosslcheckhttp_key_filehttp_cert_filehttp_source_addresshttp_timeout   r   pdf)z-hz--help)z	--versionz--copyright)z--systemzSYSTEM INFORMATIONSz,--------------------------------------------zOS:                %szPython:            %szhtml5lib:          ?zReportlab:         %s)z-sz--start-viewerz--start)z-qz--quiet)z-wz--warn)z-dz--debug)z-tz--format)z-bz--base)z
--encoding)z-cz--css)z
--css-dump)z
--xml-dump)z-xz--xmlz--xhtmlT)z--htmlFlevelformat)r@   rQ   *z.xml-)zhttp:zhttps:    /rbz.htmlz.htm.
   wbz-%d.%swin32z4File '%s' seems to be in use of another application.zConverting r   z...)
debugr   errouttempdirrU   link_callbackdefault_cssrG   encoding
xml_outputzOpen viewer for file %s)7getoptr2   r3   GetoptErrorr   exitloggingERROR
LOG_FORMATr   r   	COPYRIGHTplatformrE   	reportlabVersionminWARNINGDEBUGLOG_FORMAT_DEBUGintopenreadr   stdoutr   is_http_configbasicConfiglengloblowerendswithstdinr   getcwd
startswithr   getFileContentjoinr    urlsplitreplacer   abspathsplitrangeclose	ExceptionmsvcrtsetmodefilenoO_BINARYr   getvaluestartViewer) optsargserrorsstartviewerr   ra   rc   file_formatcssrG   rf   rg   base_dir	log_level
log_formatoarp   file_handlera_srca_destr   lcfsrcwpath	dest_partdestifile
fdestcloser   fdests                                    r   r8   r8      s   "]]HHQRL

dF FKEEGK
CEHJHIJ N1  GHHJ. +HHQK=!)HHQK-)G'(@A)CLL89)CKK78())I,=,==>HHQK55K##E""Iw7I##I)JF	$$K""H/!aH/!a *L"'')* * /!+/!J,,E+E&&q!,]N` )J?
4y
4yA~vQ #uDIIe5'E Y =IIK((0E#:-99DIIKE ^^/0E3<..0D''(++C0156>>sCHC77??3//D5dD! +\#((*+ >I ))'2ioo6G6P6P7  HHSYYs^CR%89	s?[%6%6%88D2Y GdD) %T

%	G D
3;(||w&szz002BKK@JJEK77??4(D$% !JJL!
 t$EJKuDc23::!	
 !KKMK/$67sYe  ^* *n+ +% % !  8q+2C2C2E.F#FF"! ! LtSTs}   -W1 X*X7 YYY:ZY:Z12X'&X'*X4	7Y	Y	Y	YY:Z	?Z,Z76Z7c                    | r	 t        j                  |        yy# t        $ r t        j                  d| z         Y yw xY w)zHelper for opening a PDF file.z	open "%s"N)r   	startfiler   rJ   filenames    r   r   r     s=    	.LL"   	.IIkH,-	.s    !??F)ra   c                    	 t         j                  }t        }| rt         j                  }t        j                  ||       y# t
        $ r t        j                          Y yw xY w)zShortcut for enabling log dump.rS   N)rk   rs   ru   rt   r{   r   )ra   r   r   s      r   showLoggingr     sL    OO	%
I)J? s   ?A A"!A"c                    dd l }|s:|r+dd l}|j                  |      d   j                  d      d   }nd}t	        |      |j                  |       j                         }d|z   dz   dj                  |      z   S )Nr   ;z<You need to provide a mimetype or a filename for makeDataURIzdata:z;base64,rX   )base64	mimetypes
guess_typer   RuntimeErrorencodebytesr   )datamimetyper   r   r   msgencoded_datas          r   makeDataURIr     sz     ++H5a8>>sCAFHPCs##%%d+113LX
*RWW\-BBBr   c                ~    t        | d      5 }|j                         }d d d        t        |       S # 1 sw Y   xY w)Nr[   r   )rw   rx   r   )r   r   r   s      r   makeDataURIFromFiler     s>    	h	 #  "#th//# #s   3<__main__)NNN)%
__future__r   rh   r}   rk   r   r2   urllib.parseparser    	xhtml2pdfr   xhtml2pdf.config.httpconfigr   xhtml2pdf.defaultr   xhtml2pdf.documentr   xhtml2pdf.filesr   	getLoggerr,   log	CreatePDFstripr   rn   rm   ru   r   r   r>   r8   r   r   r   r   r   r   r   <module>r      s    #    	 
  ! 2 ) + #g! 	9
r UWs v"	 4
W  <
l^.  	 C"0 zI r   