
    Dh;                     |    d dl Z d dlZd dlmZmZmZ  e j
                  e      Z G d dej                        Z	dgZ
y)    N)ffivips_libat_least_libvipsc                   @     e Zd ZdZ fdZd Zd Zd Zd Zd Z	 xZ
S )TargetCustomzTAn output target you can connect action signals to to implement
    behaviour.

    c                 |    t        j                  dt        j                               }t        t
        |   |       y)zzMake a new target you can customise.

        You can pass this target to (for example) :meth:`write_to_target`.

        zVipsTarget*N)r   castr   vips_target_custom_newsuperr   __init__)selftarget	__class__s     v/var/www/fastuser/data/www/generator.snapmosaic.io/flask_app/venv/lib/python3.12/site-packages/pyvips/vtargetcustom.pyr   zTargetCustom.__init__   s-     -)H)H)JKlD*62    c                 4    fd}| j                  d|       y)zAttach a write handler.

        The interface is exactly as io.write(). The handler is given a
        bytes-like object to write, and should return the number of bytes
        written.

        c                      |       S )N )bufhandlers    r   interface_handlerz0TargetCustom.on_write.<locals>.interface_handler"   s    3<r   writeNsignal_connectr   r   r   s    ` r   on_writezTargetCustom.on_write   s    	  	G%67r   c                 N    fd}t        dd      r| j                  d|       yy)a  Attach a read handler.

        The interface is exactly as io.read(). The handler is given a number
        of bytes to fetch, and should return a bytes-like object containing up
        to that number of bytes. If there is no more data available, it should
        return None.

        Read handlers are optional for targets. If you do not set one, your
        target will be treated as unreadable and libvips will be unable to
        write some file types (just TIFF, as of the time of writing).

        c                 P     t        |             }|yt        |      }|| d | |S )Nr   )len)r   chunk
bytes_readr   s      r   r   z/TargetCustom.on_read.<locals>.interface_handler5   s4    CH%E}UJ$Cr         readNr   r   r   s    ` r   on_readzTargetCustom.on_read'   s*    	 Ar"(9: #r   c                 B    t        dd      r| j                  d|       yy)a  Attach a seek handler.

        The interface is the same as io.seek(), so the handler is passed
        parameters for offset and whence with the same meanings.

        However, the handler MUST return the new seek position. A simple way
        to do this is to call io.tell() and return that result.

        Seek handlers are optional. If you do not set one, your target will be
        treated as unseekable and libvips will be unable to write some file
        types (just TIFF, as of the time of writing).

        r"   r#   seekNr%   r   r   s     r   on_seekzTargetCustom.on_seekB   s#     Ar"0 #r   c                 d    t        dd      s| j                  |       y| j                  d|       y)zAttach an end handler.

        This optional handler is called at the end of write. It should do any
        cleaning up necessary, and return 0 on success and -1 on error.

        r"   r#   endN)r   	on_finishr   r)   s     r   on_endzTargetCustom.on_endT   s*      2&NN7#w/r   c                 (    | j                  d|       y)zAttach a finish handler.

        For libvips 8.13 and later, this method is deprecated in favour of
        :meth:`on_end`.

        finishNr   r)   s     r   r-   zTargetCustom.on_finishb   s     	Hg.r   )__name__
__module____qualname____doc__r   r   r&   r*   r.   r-   __classcell__)r   s   @r   r   r   	   s&    
38;61$0/r   r   )loggingpyvipsr   r   r   	getLoggerr1   loggerTargetr   __all__r   r   r   <module>r<      s@      2 2			8	$a/6== a/H 
r   