o
    Ýîiê  ã                   @   sL   d dl Z d dlmZ dZG dd„ deƒZG dd„ deƒZG dd	„ d	eƒZdS )
é    N)ÚIterator)Ú	FileProxyÚReusableFileProxyÚSeekableFileProxyc                   @   sz   e Zd ZdZdd„ Zdd„ Zdd„ ZeZdd	d
„Zddd„Z	ddd„Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )r   z™The complete proxy for ``wrapped`` file-like object.

    :param wrapped: the file object to wrap
    :type wrapped: :class:`file`, file-like object
    c                 C   s   || _ d | _d S ©N)ÚwrappedÚmmap)Úselfr   © r
   úT/var/www/html/LicenciasMIG/venv/lib/python3.10/site-packages/spyne/util/fileproxy.pyÚ__init__&   s   
zFileProxy.__init__c                 C   s$   | j }t|dd ƒ}t|ƒr|ƒ S | S )NÚ__iter__)r   ÚgetattrÚcallable)r	   ÚfÚitr
   r
   r   r   *   s
   zFileProxy.__iter__c                 C   s   |   ¡ }|s
tdƒ‚|S )z9Implementation of :class:`collections.Iterator` protocol.zhit eof)ÚreadlineÚStopIteration)r	   Úliner
   r
   r   Ú__next__1   s   zFileProxy.__next__éÿÿÿÿc                 C   ó   | j  |¡S )a’  Reads at the most ``size`` bytes from the file.
        It maybe less if the read hits EOF before obtaining ``size`` bytes.

        :param size: bytes to read.  if it is negative or omitted,
                     read all data until EOF is reached.  default is -1
        :returns: read bytes.  an empty string when EOF is encountered
                  immediately
        :rtype: :class:`str`
        )r   Úread©r	   Úsizer
   r
   r   r   :   s   
zFileProxy.readNc                 C   r   )a†  Reads an entire line from the file.  A trailing newline
        character is kept in the string (but maybe absent when a file
        ends with an incomplete line).

        :param size: if it's present and non-negative, it is maximum
                     byte count (including trailing newline) and
                     an incomplete line maybe returned
        :type size: :class:`numbers.Integral`
        :returns: read bytes
        :rtype: :class:`str`

        .. note::

           Unlike ``stdio``'s :c:func:`fgets()`, the returned string
           contains null characters (``'\0'``) if they occurred in
           the input.

        )r   r   r   r
   r
   r   r   F   s   zFileProxy.readlinec                 C   s`   | j }z|j}W n ty$   g }	 | ¡ }|r| |¡ n	 | Y S qw |du r,|ƒ S ||ƒS )a“  Reads until EOF using :meth:`readline()`.

        :param sizehint: if it's present, instead of reading up to EOF,
                         whole lines totalling approximately ``sizehint``
                         bytes (or more to accommodate a final whole line)
        :type sizehint: :class:`numbers.Integral`
        :returns: a list containing the lines read
        :rtype: :class:`list`
        é   N)r   Ú	readlinesÚAttributeErrorr   Úappend)r	   Úsizehintr   r   Úlinesr   r
   r
   r   r   [   s   

úþ	zFileProxy.readlinesc                 C   s   t | ƒS )z~The same to ``iter(file)``.  Use that.

        .. deprecated:: long time ago

           Use :func:`iter()` instead.
        )Úiter©r	   r
   r
   r   Ú
xreadliness   s   zFileProxy.xreadlinesc                 C   s,   z| j j}W n
 ty   Y dS w |ƒ  dS )zÑCloses the file.  It's a context manager as well,
        so prefer :keyword:`with` statement than direct call of
        this::

            with FileProxy(file_) as f:
                print f.read()
        N)r   Úcloser   )r	   r$   r
   r
   r   r$   |   s   ÿ
zFileProxy.closec                 C   s   | j S r   )r   r"   r
   r
   r   Ú	__enter__‹   s   zFileProxy.__enter__c                 C   s   |   ¡  d S r   )r$   ©r	   Úexc_typeÚvalueÚ	tracebackr
   r
   r   Ú__exit__Ž   s   zFileProxy.__exit__c                 C   s"   | j d ur
| j  ¡  | j ¡  d S r   )r   r$   r   r"   r
   r
   r   Ú__del__‘   ó   

zFileProxy.__del__c                 C   ó
   | j  ¡ S r   )r   Úfilenor"   r
   r
   r   r.   –   s   
zFileProxy.fileno)r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   Únextr   r   r   r#   r$   r%   r*   r+   r.   r
   r
   r
   r   r      s    


	r   c                   @   s&   e Zd ZdZejfdd„Zdd„ ZdS )r   zsThe almost same to :class:`FileProxy` except it has
    :meth:`seek()` and :meth:`tell()` methods in addition.
    c                 C   s   | j  ||¡ dS )z÷Sets the file's current position.

        :param offset: the offset to set
        :type offset: :class:`numbers.Integral`
        :param whence: see the docs of :meth:`file.seek()`.
                       default is :const:`os.SEEK_SET`
        N)r   Úseek)r	   ÚoffsetÚwhencer
   r
   r   r4   Ÿ   s   zSeekableFileProxy.seekc                 C   r-   )zƒGets the file's current position.

        :returns: the file's current position
        :rtype: :class:`numbers.Integral`
        )r   Útellr"   r
   r
   r   r7   ©   s   
zSeekableFileProxy.tellN)r/   r0   r1   r2   ÚosÚSEEK_SETr4   r7   r
   r
   r
   r   r   š   s    
r   c                       s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )r   z¾It memorizes the current position (:meth:`tell()`) when the context
    enters and then rewinds (:meth:`seek()`) back to the memorized
    :attr:`initial_offset` when the context exits.
    c                    s"   |   ¡ | _|  d¡ tt| ƒ ¡ S )Nr   )r7   Úinitial_offsetr4   Úsuperr   r%   r"   ©Ú	__class__r
   r   r%   ¸   r,   zReusableFileProxy.__enter__c                 C   s   |   | j¡ d S r   )r4   r:   r&   r
   r
   r   r*   ½   s   zReusableFileProxy.__exit__)r/   r0   r1   r2   r%   r*   Ú__classcell__r
   r
   r<   r   r   ²   s    r   )r8   Ú$spyne.util.six.moves.collections_abcr   Ú__all__r   r   r   r
   r
   r
   r   Ú<module>   s   {