3
 (ƒhÑ  ã               @   sJ   d Z ddlT ddlZddlZdgZejZejejfZG dd„ dej	ƒZ
dS )z}
SocketIO imported from socket module in Python 3.

Copyright (c) 2001-2013 Python Software Foundation; All Rights Reserved.
é    )Ú*NÚSocketIOc                   sp   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Z‡ fdd„Z	dd„ Z
edd„ ƒZedd„ ƒZdd„ Z‡  ZS )r   z¬Raw I/O implementation for stream sockets.

    This class supports the makefile() method on sockets.  It provides
    the raw I/O interface on top of a socket object.
    c             C   sZ   |d
krt d| ƒ‚tjj| ƒ || _d|kr6|d7 }|| _d|k| _d|k| _d	| _d S )NÚrÚwÚrwÚrbÚwbÚrwbzinvalid mode: %rÚbF)r   r   r   r   r   r	   )	Ú
ValueErrorÚioÚ	RawIOBaseÚ__init__Ú_sockÚ_modeÚ_readingÚ_writingÚ_timeout_occurred)ÚselfÚsockÚmode© r   ú6/tmp/pip-install-q3hcpn_q/PyMySQL/pymysql/_socketio.pyr   !   s    

zSocketIO.__init__c             C   s”   | j ƒ  | jƒ  | jrtdƒ‚xpy| jj|ƒS  tk
rH   d| _‚ Y q  tk
rŠ } z(|jd }|t	krlw |t
krxdS ‚ W Y dd}~X q X q W dS )a3  Read up to len(b) bytes into the writable buffer *b* and return
        the number of bytes read.  If the socket is non-blocking and no bytes
        are available, None is returned.

        If *b* is non-empty, a 0 return value indicates that the connection
        was shutdown at the other end.
        z!cannot read from timed out objectTr   N)Ú_checkClosedÚ_checkReadabler   ÚIOErrorr   Ú	recv_intoÚtimeoutÚerrorÚargsÚEINTRÚ_blocking_errnos)r   r
   ÚeÚnr   r   r   Úreadinto-   s"    
zSocketIO.readintoc             C   sX   | j ƒ  | jƒ  y| jj|ƒS  tk
rR } z|jd tkr@dS ‚ W Y dd}~X nX dS )a  Write the given bytes or bytearray object *b* to the socket
        and return the number of bytes written.  This can be less than
        len(b) if not all data could be written.  If the socket is
        non-blocking and no bytes could be written None is returned.
        r   N)r   Ú_checkWritabler   Úsendr   r   r!   )r   r
   r"   r   r   r   ÚwriteG   s    zSocketIO.writec             C   s   | j rtdƒ‚| jS )z2True if the SocketIO is open for reading.
        zI/O operation on closed socket.)Úclosedr   r   )r   r   r   r   ÚreadableW   s    zSocketIO.readablec             C   s   | j rtdƒ‚| jS )z2True if the SocketIO is open for writing.
        zI/O operation on closed socket.)r(   r   r   )r   r   r   r   Úwritable^   s    zSocketIO.writablec                s   | j rtdƒ‚tƒ jƒ S )z2True if the SocketIO is open for seeking.
        zI/O operation on closed socket.)r(   r   ÚsuperÚseekable)r   )Ú	__class__r   r   r,   e   s    zSocketIO.seekablec             C   s   | j ƒ  | jjƒ S )z=Return the file descriptor of the underlying socket.
        )r   r   Úfileno)r   r   r   r   r.   l   s    zSocketIO.filenoc             C   s   | j s| jƒ S dS d S )Né   éÿÿÿÿ)r(   r.   )r   r   r   r   Únamer   s    zSocketIO.namec             C   s   | j S )N)r   )r   r   r   r   r   y   s    zSocketIO.modec             C   s*   | j r
dS tjj| ƒ | jjƒ  d| _dS )z‡Close the SocketIO object.  This doesn't close the underlying
        socket, except if all references to it have disappeared.
        N)r(   r   r   Úcloser   Ú_decref_socketios)r   r   r   r   r2   }   s
    
zSocketIO.close)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r$   r'   r)   r*   r,   r.   Úpropertyr1   r   r2   Ú__classcell__r   r   )r-   r   r      s   )r7   Úsocketr   ÚerrnoÚ__all__r    ÚEAGAINÚEWOULDBLOCKr!   r   r   r   r   r   r   Ú<module>   s   