3
0Wd7              
   @   s  d Z ddlmZmZ ddlZddlZdZeZde Zdddd	d
ddgZ	ddl
mZmZmZmZmZ ddlmZ ddlmZ G dd deZG dd deZG dd deZejdddddddedf	ddZddlmZmZ ddlmZmZm Z  ddl!m"Z"m#Z# dS )a2  
    WeasyPrint
    ==========

    WeasyPrint converts web documents to PDF.

    The public API is what is accessible from this "root" packages
    without importing sub-modules.

    :copyright: Copyright 2011-2014 Simon Sapin and contributors, see AUTHORS.
    :license: BSD, see LICENSE for details.

    )divisionunicode_literalsNz0.31z&WeasyPrint %s (http://weasyprint.org/)HTMLCSS
AttachmentDocumentPagedefault_url_fetcherVERSION   )fetchr	   path2url
ensure_urlurl_is_absolute)unicode)LOGGERc            
   @   sf   e Zd ZdZddddddddedf
ddZdd Zdd	 ZdddZdddZ	dddZ
dddZdS )r   a  Represents an HTML document parsed by `lxml <http://lxml.de/>`_.

    You can just create an instance with a positional argument:
    ``doc = HTML(something)``
    The class will try to guess if the input is a filename, an absolute URL,
    or a file-like object.

    Alternatively, use **one** named argument so that no guessing is involved:

    :param filename: A filename, relative to the current directory or absolute.
    :param url: An absolute, fully qualified URL.
    :param file_obj: a file-like: any object with a :meth:`~file.read` method.
    :param string: a string of HTML source. (This argument must be named.)
    :param tree: a parsed lxml tree. (This argument must be named.)

    Specifying multiple inputs is an error: ``HTML(filename=foo, url=bar)``
    will raise.

    You can also pass optional named arguments:

    :param encoding: Force the source character encoding.
    :param base_url: The base used to resolve relative URLs
        (eg. in ``<img src="../foo.png">``). If not provided, try to use
        the input filename, URL, or ``name`` attribute of file-like objects.
    :param url_fetcher: a function or other callable
        with the same signature as :func:`default_url_fetcher` called to
        fetch external resources such as stylesheets and images.
        (See :ref:`url-fetchers`.)
    :param media_type: The media type to use for ``@media``.
        Defaults to ``'print'``. **Note:** In some cases like
        ``HTML(string=foo)`` relative URLs will be invalid if ``base_url``
        is not provided.

    Nprintc             C   s   t ||||||||	}|T\}}}}|dkr2|}n8t|trNtj|ddd}ntj|d||dd}|sjtW d Q R X t||}t|dr||j_	|j
 }n||j j_	|| _|| _|	| _|
| _d S )NtreeZlxmlF)treebuildernamespaceHTMLElements)r   Zoverride_encodingZtransport_encodingr   getroot)_select_source
isinstancer   html5libparseAssertionErrorfind_base_urlhasattrZdocinfoURLr   Zgetroottreeroot_elementbase_urlurl_fetcher
media_type)selfguessfilenameurlfile_objstringr   encodingr    r!   r"   resultsource_typesourceprotocol_encoding r.   S/var/www/html/enquirykeeper_venv/lib/python3.6/site-packages/weasyprint/__init__.py__init__L   s0    




zHTML.__init__c             C   s   t gS )N)HTML5_UA_STYLESHEET)r#   r.   r.   r/   _ua_stylesheetsk   s    zHTML._ua_stylesheetsc             C   s
   t | jS )N)get_html_metadatar   )r#   r.   r.   r/   _get_metadatan   s    zHTML._get_metadataFc             C   s   t j| ||S )ap  Lay out and paginate the document, but do not (yet) export it
        to PDF or another format.

        This returns a :class:`~document.Document` object which provides
        access to individual pages and various meta-data.
        See :meth:`write_pdf` to get a PDF directly.

        .. versionadded:: 0.15

        :param stylesheets:
            An optional list of user stylesheets. (See
            :ref:`stylesheet-origins`\.) List elements are :class:`CSS`
            objects, filenames, URLs, or file-like objects.
        :type enable_hinting: bool
        :param enable_hinting:
            Whether text, borders and background should be *hinted* to fall
            at device pixel boundaries. Should be enabled for pixel-based
            output (like PNG) but not vector based output (like PDF).
        :returns: A :class:`~document.Document` object.

        )r   Z_render)r#   stylesheetsenable_hintingr.   r.   r/   renderq   s    zHTML.renderr   c             C   s   | j |j|||S )u  Render the document to a PDF file.

        This is a shortcut for calling :meth:`render`, then
        :meth:`Document.write_pdf() <document.Document.write_pdf>`.

        :param target:
            A filename, file-like object, or :obj:`None`.
        :param stylesheets:
            An optional list of user stylesheets. (See
            :ref:`stylesheet-origins`\.) The list’s elements are
            :class:`CSS` objects, filenames, URLs, or file-like objects.
        :type zoom: float
        :param zoom:
            The zoom factor in PDF units per CSS units.
            **Warning**: All CSS units (even physical, like ``cm``)
            are affected.
            For values other than 1, physical CSS units will thus be “wrong”.
            Page size declarations are affected too, even with keyword values
            like ``@page { size: A3 landscape; }``
        :param attachments: A list of additional file attachments for the
            generated PDF document or :obj:`None`. The list's elements are
            :class:`Attachment` objects, filenames, URLs or file-like objects.
        :returns:
            The PDF as byte string if :obj:`target` is not provided or
            :obj:`None`, otherwise :obj:`None` (the PDF is written to
            :obj:`target`.)

        )r7   	write_pdf)r#   targetr5   Zzoomattachmentsr.   r.   r/   r8      s    zHTML.write_pdf`   c             C   s   | j |ddj|\}}}|S )NT)r6   )r7   write_image_surface)r#   r5   
resolutionZsurface_width_heightr.   r.   r/   r<      s    zHTML.write_image_surfacec             C   s    | j |ddj||\}}}|S )uP  Paint the pages vertically to a single PNG image.

        There is no decoration around pages other than those specified in CSS
        with ``@page`` rules. The final image is as wide as the widest page.
        Each page is below the previous one, centered horizontally.

        This is a shortcut for calling :meth:`render`, then
        :meth:`Document.write_png() <document.Document.write_png>`.

        :param target:
            A filename, file-like object, or :obj:`None`.
        :param stylesheets:
            An optional list of user stylesheets. (See
            :ref:`stylesheet-origins`\.) The list’s elements are
            :class:`CSS` objects, filenames, URLs, or file-like objects.
        :type resolution: float
        :param resolution:
            The output resolution in PNG pixels per CSS inch. At 96 dpi
            (the default), PNG pixels match the CSS ``px`` unit.
        :returns:
            The image as byte string if :obj:`target` is not provided or
            :obj:`None`, otherwise :obj:`None` (the image is written to
            :obj:`target`.)

        T)r6   )r7   	write_png)r#   r9   r5   r=   Z	png_bytesr>   r?   r.   r.   r/   r@      s    zHTML.write_png)NF)NNr   N)Nr;   )NNr;   )__name__
__module____qualname____doc__r	   r0   r2   r4   r7   r8   r<   r@   r.   r.   r.   r/   r   )   s   "
 

c            
   @   s.   e Zd ZdZdddddddeddf
ddZdS )r   a  Represents a CSS stylesheet parsed by tinycss.

    An instance is created in the same way as :class:`HTML`, except that
    the ``tree`` parameter is not available. All other parameters are the same.

    ``CSS`` objects have no public attribute or method. They are only meant to
    be used in the :meth:`~HTML.write_pdf`, :meth:`~HTML.write_png` and
    :meth:`~HTML.render` methods of :class:`HTML` objects.

    NFr   c             C   s   t |||||d |||	d	}|N\}}}}|dkrHt|t rHtj|}n |dkrX|j }tj|||d}W d Q R X || _tt	|
||j
|| _
|| _x| jjD ]}tj| qW d S )N)r   r    r!   check_css_mime_typer(   r'   )Zlinking_encodingr-   )r   r   bytesPARSERZparse_stylesheetreadZparse_stylesheet_bytesr    listpreprocess_stylesheetZrules
stylesheeterrorsr   warning)r#   r$   r%   r&   r'   r(   r)   r    r!   Z_check_mime_typer"   r*   r+   r,   r-   rK   errorr.   r.   r/   r0      s$    zCSS.__init__)rA   rB   rC   rD   r	   r0   r.   r.   r.   r/   r      s
   
c               @   s*   e Zd ZdZddddddedfddZdS )r   a|  Represents a file attachment for a PDF document.

    An instance is created in the same way as :class:`HTML`, except that
    the HTML specific parameters are not supported. An optional description can
    be provided with the ``description`` parameter.

    :param description: A description of the attachment to be included in the
        PDF document. May be :obj:`None`

    Nc	       	   
   C   s$   t |||||d ||d| _|| _d S )N)r   r    r!   )r   r,   description)	r#   r$   r%   r&   r'   r(   r    r!   rO   r.   r.   r/   r0      s    zAttachment.__init__)rA   rB   rC   rD   r	   r0   r.   r.   r.   r/   r      s   
Fc	             #   s  |dk	rt |}| dk|dk|dk|dk|dk|dkg  ddddddgkrt| dr\d}	nt| rjd}	nd}	tf |||dt|	| i}
|
}
|
V  W dQ R X nֈ ddddddgkr|dkrt|}t|d	}d||dfV  W dQ R X n ddddddgkrt||}
|rN|
d
 dkrNtj	d|
d
 |
d  dd|dfV  nP|
j
d}|dkrn|
j
d|}d|
krd|
d ||fV  nd|
d ||fV  W dQ R X n҈ ddddddgkr|dkrt|dd}|r|jd rt |}d||dfV  nz ddddddgkr(d||dfV  nT ddddddgkrNd||dfV  n.tddj fddtdj D pvd dS )ze
    Check that only one input is not None, and return it with the
    normalized ``base_url``.

    NFTrH   r'   r&   r%   )r    r!   rE   rbZ	mime_typeztext/cssz%Unsupported stylesheet type %s for %sZredirected_urlr(    r)   name<r   z!Expected exactly one source, got z, c             3   s   | ]\}} | s|V  qd S )Nr.   ).0irR   )nonesr.   r/   	<genexpr>K  s    z!_select_source.<locals>.<genexpr>z'guess filename url file_obj string treeZnothing)r   r   r   r   strr   openr   r   rM   getgetattr
startswith	TypeErrorjoin	enumeratesplit)r$   r%   r&   r'   r(   r   r    r!   rE   type_r*   Zproto_encodingrR   r.   )rV   r/   r   	  sd    	





r   )rG   rJ   )r   r1   r3   )r   r   )$rD   
__future__r   r   
contextlibr   r
   __version__ZVERSION_STRING__all__Zurlsr   r	   r   r   r   compatr   loggerr   objectr   r   r   contextmanagerr   cssrG   rJ   htmlr   r1   r3   Zdocumentr   r   r.   r.   r.   r/   <module>   s,   
 '&F