o
    	ȷeQ                     @   s   d Z dZdZdZdZg dZddlZddlZdd	lm	Z
 e
jZd
d Zdd Ze
jZG dd deZeZdadd Zdd ZdS )zH
ghostscript - A Python interface for the Ghostscript interpreter C-API
z-Hartmut Goebel <h.goebel@crazy-compilers.com>z?Copyright 2010 by Hartmut Goebel <h.goebel@crazy-compilers.com>z-GNU General Public License version 3 (GPL v3)z0.5dev)GhostscriptrevisionGhostscriptErrorPleaseDisplayUsage    N   )_gsprintc                 C   s   dS )z
    This exception is raised when Ghostscript asks the application to
    display the usage. The application should catch the exception an
    print the usage message.
    N )Warningr   r   K/var/www/ideatree/venv/lib/python3.10/site-packages/ghostscript/__init__.pyr   %   s   r   c                      s    t   t fdd jD S )a  
    This function returns the revision numbers and strings of the
    Ghostscript interpreter library as a dict. You should call it
    before any other interpreter library functions to make sure that
    the correct version of the Ghostscript interpreter has been
    loaded.
    c                 3   s"    | ]\}}|t  |fV  qd S N)getattr).0f_revr   r
   	<genexpr>7   s     zrevision.<locals>.<genexpr>)gsr   dict_fields_r   r   r   r
   r   .   s   r   c                   @   sN   e Zd Zedd Zdd Zdd Zdd Zdd
dZdddZ	dddZ
dS )r   c                   C   s   t  S r   )r   r   r   r   r
   r   >   s   zGhostscript.revisionc                 C   sF   d| _ || _t||}|tjkrtd| _ |tjkr!|   d S d S )NFT)_initialized	_instancer   init_with_argse_Infor   e_Quitexit)selfinstanceargsrcr   r   r
   __init__B   s   

zGhostscript.__init__c                 C   s   |    d S r   )r   r   r   r   r
   __del__L   s   zGhostscript.__del__c                 C   s    | j rt| j d| _ d S d S )NF)r   r   r   r   r!   r   r   r
   r   O   s   
zGhostscript.exitFc                 C   sh   | j }t|tk rt|| dS t| tdt|tD ]}t||||t   qt| dS )z
        Run the string ``str`` by Ghostscript

        This takes care of Ghostscripts size-limitations and passes
        the string in pieces if necessary.
        r   N)	r   lenMAX_STRING_LENGTHr   
run_stringrun_string_beginrangerun_string_continuerun_string_end)r   struser_errorsr   startr   r   r
   r%   U   s   
zGhostscript.run_stringc                 C   s   t | j||S )zC
        Run the file named by ``filename`` by Ghostscript
        )r   run_filer   )r   filenamer+   r   r   r
   run_filenameg   s   zGhostscript.run_filenamec                 C   s>   | j }t| 	 |t}|snt|| q	t| dS )z
        Read ``file`` and run the content by Ghostscript.

        ``file`` must already by opened and may by any file-like
        object supporting the ``read()`` method.
        TN)r   r   r&   readr$   r(   r)   )r   filer+   r   r*   r   r   r
   r-   n   s   

zGhostscript.run_fileN)F)__name__
__module____qualname__staticmethodr   r    r"   r   r%   r/   r-   r   r   r   r
   r   =   s    



r   c                  G   s   t du rt a tt | S )z@
    Factory function for setting up a Ghostscript instance
    N)__instance__r   new_instance__Ghostscript)r   r   r   r
   r      s   
c                   C   s   t d urtt  d a d S d S r   )r6   r   delete_instancer   r   r   r
   cleanup   s   
r:   )__doc__
__author____copyright____licence____version____all__atexitsys r   r   r   r   r   r$   objectr   r8   r6   r:   r   r   r   r
   <module>   s$   	A
