%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib64/python2.7/site-packages/tornado/
Upload File :
Create Path :
Current File : //lib64/python2.7/site-packages/tornado/iostream.pyc

�
��L]c@�s�dZddlmZmZmZmZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZddlmZddlmZmZddlmZmZmZmZmZddlmZdd	lmZydd
lmZWnek
r'e ZnXyddl!Z!Wnek
rQe Z!nXej"ej#fZ$e%ed�r�e$ej&f7Z$nej'ej(ej)ej*fZ+e%ed�r�e+ej,ej-ej.f7Z+nej/d
kr�e+ej0f7Z+nej1fZ2e%ed�r"e2ej3f7Z2nde4fd��YZ5de6fd��YZ7de6fd��YZ8de9fd��YZ:de:fd��YZ;de;fd��YZ<de:fd��YZ=d�Z>d�Z?d�Z@dS( sBUtility classes to write to and read from non-blocking files and sockets.

Contents:

* `BaseIOStream`: Generic interface for reading and writing.
* `IOStream`: Implementation of BaseIOStream using non-blocking sockets.
* `SSLIOStream`: SSL-aware version of IOStream.
* `PipeIOStream`: Pipe-based IOStream implementation.
i(tabsolute_importtdivisiontprint_functiontwith_statementN(tTracebackFuture(tioloop(tgen_logtapp_log(tssl_wrap_sockettssl_match_hostnametSSLCertificateErrort_client_ssl_defaultst_server_ssl_defaults(t
stack_context(terrno_from_exception(t_set_nonblockingtWSAEWOULDBLOCKt
WSAECONNRESETtdarwintWSAEINPROGRESStStreamClosedErrorcB�seZdZRS(sException raised by `IOStream` methods when the stream is closed.

    Note that the close callback is scheduled to run *after* other
    callbacks on the stream (to allow for buffered data to be processed),
    so you may see this error before you see the close callback.
    (t__name__t
__module__t__doc__(((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRUstUnsatisfiableReadErrorcB�seZdZRS(s�Exception raised when a read cannot be satisfied.

    Raised by ``read_until`` and ``read_until_regex`` with a ``max_bytes``
    argument.
    (RRR(((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR_stStreamBufferFullErrorcB�seZdZRS(sDException raised by `IOStream` methods when the buffer is full.
    (RRR(((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRhstBaseIOStreamcB�seZdZd%d%d%d%d�Zd�Zd�Zd�Zd�Zd�Z	d%d%d�Z
d%d%d�Zd%d%ed	�Z
d%d%d
�Zd%d�Zd�Zed
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#d �Z$d!�Z%d"�Z&d#�Z'd$�Z(RS(&s]A utility class to write to and read from a non-blocking file or socket.

    We support a non-blocking ``write()`` and a family of ``read_*()`` methods.
    All of the methods take an optional ``callback`` argument and return a
    `.Future` only if no callback is given.  When the operation completes,
    the callback will be run or the `.Future` will resolve with the data
    read (or ``None`` for ``write()``).  All outstanding ``Futures`` will
    resolve with a `StreamClosedError` when the stream is closed; users
    of the callback interface will be notified via
    `.BaseIOStream.set_close_callback` instead.

    When a stream is closed due to an error, the IOStream's ``error``
    attribute contains the exception object.

    Subclasses must implement `fileno`, `close_fd`, `write_to_fd`,
    `read_from_fd`, and optionally `get_fd_error`.
    cC�s@|ptjj�|_|p!d|_t|p3d|jd�|_||_d|_	t
j�|_t
j�|_
d|_d|_t|_d|_d|_d|_d|_t|_t|_d|_d|_d|_d|_d|_d|_d|_d|_d|_ t|_!d|_"d|_#t|_$dS(s�`BaseIOStream` constructor.

        :arg io_loop: The `.IOLoop` to use; defaults to `.IOLoop.current`.
                      Deprecated since Tornado 4.1.
        :arg max_buffer_size: Maximum amount of incoming data to buffer;
            defaults to 100MB.
        :arg read_chunk_size: Amount of data to read at one time from the
            underlying transport; defaults to 64KB.
        :arg max_write_buffer_size: Amount of outgoing data to buffer;
            defaults to unlimited.

        .. versionchanged:: 4.0
           Add the ``max_write_buffer_size`` parameter.  Changed default
           ``read_chunk_size`` to 64KB.
        i@iiiN(%RtIOLooptcurrenttio_looptmax_buffer_sizetmintread_chunk_sizetmax_write_buffer_sizetNoneterrortcollectionstdequet_read_buffert
_write_buffert_read_buffer_sizet_write_buffer_sizetFalset_write_buffer_frozent_read_delimitert_read_regext_read_max_bytest_read_bytest
_read_partialt_read_until_closet_read_callbackt_read_futuret_streaming_callbackt_write_callbackt
_write_futuret_close_callbackt_connect_callbackt_connect_futuret_ssl_connect_futuret_connectingt_statet_pending_callbackst_closed(tselfRRR R!((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyt__init__s<																							cC�s
t��dS(s,Returns the file descriptor for this stream.N(tNotImplementedError(R?((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pytfileno�scC�s
t��dS(s�Closes the file underlying this stream.

        ``close_fd`` is called by `BaseIOStream` and should not be called
        elsewhere; other users should call `close` instead.
        N(RA(R?((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pytclose_fd�scC�s
t��dS(siAttempts to write ``data`` to the underlying file.

        Returns the number of bytes written.
        N(RA(R?tdata((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pytwrite_to_fd�scC�s
t��dS(s-Attempts to read from the underlying file.

        Returns ``None`` if there was nothing to read (the socket
        returned `~errno.EWOULDBLOCK` or equivalent), otherwise
        returns the data.  When possible, should return no more than
        ``self.read_chunk_size`` bytes at a time.
        N(RA(R?((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pytread_from_fd�scC�sdS(s>Returns information about any error on the underlying file.

        This method is called after the `.IOLoop` has signaled an error on the
        file descriptor, and should return an Exception (such as `socket.error`
        with additional information, or None if no such information is
        available.
        N(R"(R?((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pytget_fd_error�scC�s�|j|�}tj|�|_||_y|j�Wn]tk
ro}tjd|�|j	dt
�|S|dk	r�|jd��n�nX|S(s�Asynchronously read until we have matched the given regex.

        The result includes the data that matches the regex and anything
        that came before it.  If a callback is given, it will be run
        with the data as an argument; if not, this method returns a
        `.Future`.

        If ``max_bytes`` is not None, the connection will be closed
        if more than ``max_bytes`` bytes have been read and the regex is
        not satisfied.

        .. versionchanged:: 4.0
            Added the ``max_bytes`` argument.  The ``callback`` argument is
            now optional and a `.Future` will be returned if it is omitted.
        s*Unsatisfiable read, closing connection: %stexc_infocS�s
|j�S(N(t	exception(tf((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyt<lambda>�sN(
t_set_read_callbacktretcompileR-R.t_try_inline_readRRtinfotclosetTrueR"tadd_done_callback(R?tregextcallbackt	max_bytestfuturete((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pytread_until_regex�s	cC�s�|j|�}||_||_y|j�Wn]tk
rf}tjd|�|jdt�|S|dk	r�|j
d��n�nX|S(siAsynchronously read until we have found the given delimiter.

        The result includes all the data read including the delimiter.
        If a callback is given, it will be run with the data as an argument;
        if not, this method returns a `.Future`.

        If ``max_bytes`` is not None, the connection will be closed
        if more than ``max_bytes`` bytes have been read and the delimiter
        is not found.

        .. versionchanged:: 4.0
            Added the ``max_bytes`` argument.  The ``callback`` argument is
            now optional and a `.Future` will be returned if it is omitted.
        s*Unsatisfiable read, closing connection: %sRHcS�s
|j�S(N(RI(RJ((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRKsN(RLR,R.RORRRPRQRRR"RS(R?t	delimiterRURVRWRX((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyt
read_until�s		cC�s�|j|�}t|tj�s't�||_||_tj|�|_	y|j
�Wn)|dk	r~|jd��n�nX|S(s�Asynchronously read a number of bytes.

        If a ``streaming_callback`` is given, it will be called with chunks
        of data as they become available, and the final result will be empty.
        Otherwise, the result is all the data that was read.
        If a callback is given, it will be run with the data as an argument;
        if not, this method returns a `.Future`.

        If ``partial`` is true, the callback is run as soon as we have
        any bytes to return (but never more than ``num_bytes``)

        .. versionchanged:: 4.0
            Added the ``partial`` argument.  The callback argument is now
            optional and a `.Future` will be returned if it is omitted.
        cS�s
|j�S(N(RI(RJ((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRK7sN(
RLt
isinstancetnumberstIntegraltAssertionErrorR/R0R
twrapR4ROR"RS(R?t	num_bytesRUtstreaming_callbacktpartialRW((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyt
read_bytess		cC�s�|j|�}tj|�|_|j�ri|jdk	rR|j|jt�n|j|jt	�|St|_
y|j�Wn|jd���nX|S(s{Asynchronously reads all data from the socket until it is closed.

        If a ``streaming_callback`` is given, it will be called with chunks
        of data as they become available, and the final result will be empty.
        Otherwise, the result is all the data that was read.
        If a callback is given, it will be run with the data as an argument;
        if not, this method returns a `.Future`.

        Note that if a ``streaming_callback`` is used, data will be
        read from the socket as quickly as it becomes available; there
        is no way to apply backpressure or cancel the reads. If flow
        control or cancellation are desired, use a loop with
        `read_bytes(partial=True) <.read_bytes>` instead.

        .. versionchanged:: 4.0
            The callback argument is now optional and a `.Future` will
            be returned if it is omitted.

        cS�s
|j�S(N(RI(RJ((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRKZsN(
RLR
R`R4tclosedR"t_run_read_callbackR(RRR*R1RORS(R?RURbRW((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pytread_until_close;s	cC�sEt|t�st�|j�|r�|jdk	r_|jt|�|jkr_td��nd}x;t	dt|�|�D]!}|j
j||||!�q~W|jt|�7_n|dk	r�tj
|�|_d}n t�}|_|jd��|jsA|j�|j
r4|j|jj�n|j�n|S(s�Asynchronously write the given data to this stream.

        If ``callback`` is given, we call it when all of the buffered write
        data has been successfully written to the stream. If there was
        previously buffered write data and an old write callback, that
        callback is simply overwritten with this new callback.

        If no ``callback`` is given, this method returns a `.Future` that
        resolves (with a result of ``None``) when the write has been
        completed.  If `write` is called again before that `.Future` has
        resolved, the previous future will be orphaned and will never resolve.

        .. versionchanged:: 4.0
            Now returns a `.Future` if no callback is given.
        s!Reached maximum write buffer sizei�iicS�s
|j�S(N(RI(RJ((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRK�sNi(R\tbytesR_t
_check_closedR!R"R)tlenRtrangeR'tappendR
R`R5RR6RSR;t
_handle_writet
_add_io_stateRtWRITEt_maybe_add_error_listener(R?RDRUtWRITE_BUFFER_CHUNK_SIZEtiRW((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pytwrite^s*
		
	
cC�s tj|�|_|j�dS(s�Call the given callback when the stream is closed.

        This is not necessary for applications that use the `.Future`
        interface; all outstanding ``Futures`` will resolve with a
        `StreamClosedError` when the stream is closed.
        N(R
R`R7Rp(R?RU((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pytset_close_callback�scC�s�|j�s�|rOt|t�s0tj�}nt|�rO|d|_qOn|jr�|jdk	r�|j
r�|j|j
t�nt
|_|j|j
t
�n|jdk	r�|jj|j��d|_n|j�t|_n|j�dS(s�Close this stream.

        If ``exc_info`` is true, set the ``error`` attribute to the current
        exception from `sys.exc_info` (or if ``exc_info`` is a tuple,
        use that instead of `sys.exc_info`).
        iN(ReR\ttupletsysRHtanyR#R1R4R"R(RfRRR*R<Rtremove_handlerRBRCR>t_maybe_run_close_callback(R?RH((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRQ�s$			
cC�sm|j�ri|jdkrig}|jdk	rL|j|j�d|_n|jdk	rw|j|j�d|_n|jdk	r�|j|j�d|_n|jdk	r�|j|j�d|_nxL|D]D}|j|j	�r�|j
t��q�|j
|j	pt��q�W|jdk	rM|j}d|_|j
|�nd|_|_d|_ndS(Ni(ReR=R3R"RlR6R9R:t
_is_connresetR#t
set_exceptionRR7t
_run_callbackR2R5R'(R?tfuturesRWtcb((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRy�s0
		cC�s|jdk	p|jdk	S(s9Returns true if we are currently reading from the stream.N(R2R"R3(R?((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pytreading�scC�s
t|j�S(s7Returns true if we are currently writing to the stream.(tboolR'(R?((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pytwriting�scC�s|jS(s+Returns true if the stream has been closed.(R>(R?((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRe�scC�sdS(s�Sets the no-delay flag for this stream.

        By default, data written to TCP streams may be held for a time
        to make the most efficient use of bandwidth (according to
        Nagle's algorithm).  The no-delay flag requests that data be
        written as soon as possible, even if doing so would consume
        additional bandwidth.

        This flag is currently defined only for TCP-based ``IOStreams``.

        .. versionadded:: 3.1
        N((R?tvalue((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pytset_nodelay�s
cC�s|j�r tjd|�dSy�|jr9|j�n|j�rIdS||jj@rf|j�n|j�rvdS||jj@r�|j	�n|j�r�dS||jj
@r�|j�|_|jj
|j�dS|jj
}|j�r||jjO}n|j�r#||jjO}n||jj
krW|jdkrW||jjO}n||jkr�|jdk	s�td��||_|jj|j�|j�nWnjtk
r�}tjd|�|jdt�n7tk
rtjddt�|jdt��nXdS(NsGot events for closed stream %sis4shouldn't happen: _handle_events without self._states*Unsatisfiable read, closing connection: %sRHs'Uncaught exception, closing connection.(ReRtwarningR;t_handle_connectRtREADt_handle_readRoRmtERRORRGR#tadd_callbackRQRR�R(R<R"R_tupdate_handlerRBRRPRRt	Exception(R?tfdteventststateRX((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyt_handle_events�sP	


!		#
c�sK���fd�}tj��$�jd7_�jj|�WdQXdS(Nc�sm�jd8_zLy���SWn7tk
rYtjddt��jdt��nXWd�j�XdS(Nis'Uncaught exception, closing connection.RH(R=R�RR#RRRQRp((targsRUR?(s6/usr/lib64/python2.7/site-packages/tornado/iostream.pytwrapper#s
i(R
tNullContextR=RR�(R?RUR�R�((R�RUR?s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR|"s
cC�sz|jdk	r|j}n6|jdk	r9|j}n|j�rNd}nd}d}|jd7_x�|j�s�|j�dkr�Pn|j�|dk	r�|j|kr�Pn|j|krl|j	�}|dk	r�|S|jd}qlqlW|j	�SWd|jd8_XdS(Niii(
R/R"R.RR=Ret_read_to_buffert_run_streaming_callbackR(t_find_read_pos(R?ttarget_bytest
next_find_postpos((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyt_read_to_buffer_loopEs0	
cC�s�y|j�}WnHtk
r&�n5tk
rZtjddt�|jdt�dSX|dk	rx|j|�dS|j	�dS(Ns
error on readRH(
R�RR�RR�RRRQR"t_read_from_bufferRy(R?R�((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR��s


cC�sj|jdkstd��|jdks6td��|dk	rWtj|�|_nt�|_|jS(NsAlready reading(R2R"R_R3R
R`R(R?RU((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRL�scC�s�|r|j}ne|j}d|_|_|jdk	rw|dksLt�|j}d|_|j|j|��n|dk	r�|jdks�|s�t�|j||j|��n
|j�dS(N(	R4R2R"R3R_t
set_resultt_consumeR|Rp(R?tsizet	streamingRURW((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRf�s			cC�s�|j�|j�}|dk	r3|j|�dS|j�y|j�}Wntk
rm|j��nX|dk	r�|j|�dS|j�r�|j�n|j	t
jj�dS(sAttempt to complete the current read operation from buffered data.

        If the read can be completed without blocking, schedules the
        read callback on the next IOLoop iteration; otherwise starts
        listening for reads on the socket.
        N(
R�R�R"R�RiR�R�RyReRnRRR�(R?R�((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRO�s"






cC�s�y|j�}WnUtjttfk
rg}|j|�rQ|jdt�dS|jdt��nX|dkrxdS|j	j
|�|jt|�7_|j|j
kr�tjd�|j�td��nt|�S(sReads from the socket and appends the result to the read buffer.

        Returns the number of bytes read.  Returns 0 if there is nothing
        to read (i.e. the read returns EWOULDBLOCK or equivalent).  On
        error closes the socket and raises an exception.
        RHNis Reached maximum read buffer size(RFtsocketR#tIOErrortOSErrorRzRQRRR"R&RlR(RjRRR(R?tchunkRX((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR��s"

cC�sk|jdk	rg|jrg|j}|jdk	rTt|j|�}|j|8_n|j|t�ndS(N(R4R"R(R/RRfRR(R?tbytes_to_consume((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR��s	cC�s4d|_|_|_t|_|j|t�dS(s�Attempts to complete the currently-pending read from the buffer.

        The argument is either a position in the read buffer or None,
        as returned by _find_read_pos.
        N(R"R/R,R-R*R0Rf(R?R�((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR��s	cC�s�|jdk	rR|j|jks9|jrR|jdkrRt|j|j�}|S|jdk	r|jr�x�tr�|jdj|j�}|dkr�t	|j�}|j
|j||�||St	|j�dkr�Pnt|j�qmW|j
|jt	|jd��q�n�|jdk	r�|jr�xxtr�|jj
|jd�}|dk	r|j
|j|j��|j�St	|j�dkr�Pnt|j�q1W|j
|jt	|jd��q�ndS(s�Attempts to find a position in the read buffer that satisfies
        the currently-pending read.

        Returns a position in the buffer if the current read can be satisfied,
        or None if it cannot.
        ii����iN(R/R"R(R0RR,R&RRtfindRjt_check_max_bytest_double_prefixR-tsearchtend(R?Ratloct
delimiter_lentm((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR��s@					
cC�s>|jdk	r:||jkr:td||jf��ndS(Ns&delimiter %r not found within %d bytes(R.R"R(R?RZR�((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR�,s
cC�s{x|jry�|js+t|jd�n|j|jd�}|dkrZt|_Pnt|_t|j|�|jj�|j|8_Wqtj	t
tfk
r}|jdt
kr�t|_Pq|j|�s�tjd|j�|�n|jdt�dSqXqW|jsw|jrI|j}d|_|j|�n|jrw|j}d|_|jd�qwndS(Ni�iisWrite error on %s: %sRHi(R'R+t
_merge_prefixRERRR*tpopleftR)R�R#R�R�R�t_ERRNO_WOULDBLOCKRzRR�RBRQR5R"R|R6R�(R?RaRXRURW((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRm3s<				
									cC�s<|dkrdSt|j|�|j|8_|jj�S(Nit(R�R&R(R�(R?R�((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR�ds
cC�s|j�rtd��ndS(NsStream is closed(ReR(R?((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRikscC�s�|jdkrdS|jdks7|jtjjkr�|j�rP|j�q�|jdkr�|j	dk	r�|j
tjj�q�ndS(Ni(R=R<R"RRR�ReRyR(R7RnR�(R?((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRpos$
cC�s�|j�rdS|jdkrjtjj|B|_tj��'|jj	|j
�|j|j�WdQXn<|j|@s�|j|B|_|jj|j
�|j�ndS(sJAdds `state` (IOLoop.{READ,WRITE} flags) to our event handler.

        Implementation notes: Reads and writes have a fast path and a
        slow path.  The fast path reads synchronously from socket
        buffers, while the slow path uses `_add_io_state` to schedule
        an IOLoop callback.  Note that in both cases, the callback is
        run asynchronously with `_run_callback`.

        To detect closed connections, we must have called
        `_add_io_state` at some point, but we want to delay this as
        much as possible so we don't have to set an `IOLoop.ERROR`
        listener that will be overwritten by the next slow-path
        operation.  As long as there are callbacks scheduled for
        fast-path ops, those callbacks may do more reads.
        If a sequence of fast-path ops do not end in a slow-path op,
        (e.g. for an @asynchronous long-poll request), we must add
        the error handler.  This is done in `_run_callback` and `write`
        (since the write callback is optional so we can have a
        fast-path write with no `_run_callback`)
        N(
ReR<R"RRR�R
R�Rtadd_handlerRBR�R�(R?R�((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRns
	"
cC�s(t|tjtf�o't|�tkS(sbReturn true if exc is ECONNRESET or equivalent.

        May be overridden in subclasses.
        (R\R�R#R�Rt_ERRNO_CONNRESET(R?texc((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRz�sN()RRRR"R@RBRCRERFRGRYR[R*RdRgRsRtRQRyRR�ReR�R�R|R�R�RLRfROR�R�R�R�R�RmR�RiRpRnRz(((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRmsN5				
	
"#,	
	$					5	#	<					!			
	0		1				!tIOStreamcB�steZdZd�Zd�Zd�Zd�Zd�Zd�Zddd�Z
ddd�Zd	�Zd
�Z
RS(s*Socket-based `IOStream` implementation.

    This class supports the read and write methods from `BaseIOStream`
    plus a `connect` method.

    The ``socket`` parameter may either be connected or unconnected.
    For server operations the socket is the result of calling
    `socket.accept <socket.socket.accept>`.  For client operations the
    socket is created with `socket.socket`, and may either be
    connected before passing it to the `IOStream` or connected with
    `IOStream.connect`.

    A very simple (and broken) HTTP client using this class:

    .. testcode::

        import tornado.ioloop
        import tornado.iostream
        import socket

        def send_request():
            stream.write(b"GET / HTTP/1.0\r\nHost: friendfeed.com\r\n\r\n")
            stream.read_until(b"\r\n\r\n", on_headers)

        def on_headers(data):
            headers = {}
            for line in data.split(b"\r\n"):
               parts = line.split(b":")
               if len(parts) == 2:
                   headers[parts[0].strip()] = parts[1].strip()
            stream.read_bytes(int(headers[b"Content-Length"]), on_body)

        def on_body(data):
            print(data)
            stream.close()
            tornado.ioloop.IOLoop.current().stop()

        if __name__ == '__main__':
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
            stream = tornado.iostream.IOStream(s)
            stream.connect(("friendfeed.com", 80), send_request)
            tornado.ioloop.IOLoop.current().start()

    .. testoutput::
       :hide:

    cO�s6||_|jjt�tt|�j||�dS(N(R�tsetblockingR*tsuperR�R@(R?R�R�tkwargs((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR@�s	cC�s|jS(N(R�(R?((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRB�scC�s|jj�d|_dS(N(R�RQR"(R?((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRC�s
cC�s4|jjtjtj�}tj|tj|��S(N(R�t
getsockoptt
SOL_SOCKETtSO_ERRORR#toststrerror(R?terrno((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRG�scC�sdy|jj|j�}Wn0tjk
rK}|jdtkrEdS�nX|s`|j�dS|S(Ni(R�trecvR R#R�R�R"RQ(R?R�RX((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRF�s
cC�s|jj|�S(N(R�tsend(R?RD((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRE�scC�s�t|_|dk	r0tj|�|_d}nt�}|_y|jj	|�Wnytj
k
r�}t|�tkr�t|�t
kr�|dkr�tjd|jj�|�n|jdt�|SnX|j|jj�|S(s0Connects the socket to a remote address without blocking.

        May only be called if the socket passed to the constructor was
        not previously connected.  The address parameter is in the
        same format as for `socket.connect <socket.socket.connect>` for
        the type of socket passed to the IOStream constructor,
        e.g. an ``(ip, port)`` tuple.  Hostnames are accepted here,
        but will be resolved synchronously and block the IOLoop.
        If you have a hostname instead of an IP address, the `.TCPClient`
        class is recommended instead of calling this method directly.
        `.TCPClient` will do asynchronous DNS resolution and handle
        both IPv4 and IPv6.

        If ``callback`` is specified, it will be called with no
        arguments when the connection is completed; if not this method
        returns a `.Future` (whose result after a successful
        connection will be the stream itself).

        In SSL mode, the ``server_hostname`` parameter will be used
        for certificate validation (unless disabled in the
        ``ssl_options``) and SNI (if supported; requires Python
        2.7.9+).

        Note that it is safe to call `IOStream.write
        <BaseIOStream.write>` while the connection is pending, in
        which case the data will be written as soon as the connection
        is ready.  Calling `IOStream` read methods before the socket is
        connected works on some platforms but is non-portable.

        .. versionchanged:: 4.0
            If no callback is given, returns a `.Future`.

        .. versionchanged:: 4.2
           SSL certificates are validated by default; pass
           ``ssl_options=dict(cert_reqs=ssl.CERT_NONE)`` or a
           suitably-configured `ssl.SSLContext` to the
           `SSLIOStream` constructor to disable.
        sConnect error on fd %s: %sRHN(RRR;R"R
R`R8RR9R�tconnectR#Rt_ERRNO_INPROGRESSR�RR�RBRQRnRRo(R?taddressRUtserver_hostnameRWRX((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR��s"'			c�sY|jsZ|jsZ|jsZ|jsZ|jsZ|jsZ|jsZ|jsZ|jsZ|j	rit
d��n|d	kr�|r�t}q�t
}n|j}|jj|�d	|_t||d|d|dt�}|j�d	|_t��t|d|d|j�����fd�}�j|���fd��_|j�_|j�_�S(
s�Convert this `IOStream` to an `SSLIOStream`.

        This enables protocols that begin in clear-text mode and
        switch to SSL after some initial negotiation (such as the
        ``STARTTLS`` extension to SMTP and IMAP).

        This method cannot be used if there are outstanding reads
        or writes on the stream, or if there is any data in the
        IOStream's buffer (data in the operating system's socket
        buffer is allowed).  This means it must generally be used
        immediately after reading or writing the last clear-text
        data.  It can also be used immediately after connecting,
        before any reads or writes.

        The ``ssl_options`` argument may be either an `ssl.SSLContext`
        object or a dictionary of keyword arguments for the
        `ssl.wrap_socket` function.  The ``server_hostname`` argument
        will be used for certificate validation unless disabled
        in the ``ssl_options``.

        This method returns a `.Future` whose result is the new
        `SSLIOStream`.  After this method has been called,
        any other operation on the original stream is undefined.

        If a close callback is defined on this stream, it will be
        transferred to the new stream.

        .. versionadded:: 4.0

        .. versionchanged:: 4.2
           SSL certificates are validated by default; pass
           ``ssl_options=dict(cert_reqs=ssl.CERT_NONE)`` or a
           suitably-configured `ssl.SSLContext` to disable.
        s+IOStream is not idle; cannot convert to SSLR�tserver_sidetdo_handshake_on_connecttssl_optionsRc�sB�j�s(�j�jp!t��n�dk	r>��ndS(N(tdoneR{R#RR"((RWtorig_close_callbackt
ssl_stream(s6/usr/lib64/python2.7/site-packages/tornado/iostream.pytclose_callback|sc�s
�j��S(N(R�((RWR�(s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRK�sN(R2R3R5R6R8R9R=R>R&R't
ValueErrorR"RRR�RRxRR*R7RtSSLIOStreamRtt_ssl_connect_callbackRR (R?R�R�R�R�R�((RWR�R�s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyt	start_tls;s8#								
cC�s�|jjtjtj�}|dkr�tj|tj|��|_|jdkrzt	j
d|jj�tj
|�n|j�dS|jdk	r�|j}d|_|j|�n|jdk	r�|j}d|_|j|�nt|_dS(NisConnect error on fd %s: %s(R�R�R�R�R#R�R�R9R"RR�RBR�t	errorcodeRQR8R|R�R*R;(R?terrRURW((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR��s"	
				cC�s�|jdk	r�|jjtjtjfkr�y,|jjtjtj|rQdnd�Wq�tjk
r�}|j	t	j
kr�|j|�r��q�q�XndS(Nii(R�R"tfamilytAF_INETtAF_INET6t
setsockopttIPPROTO_TCPtTCP_NODELAYR#R�tEINVALRz(R?R�RX((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR��s"N(RRRR@RBRCRGRFRER"R�R�R�R�(((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR��s/					
	AL	R�cB�s�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
ddd	�Zd
�Z
dd�Zd�Zd
�Zd�ZRS(snA utility class to write to and read from a non-blocking SSL socket.

    If the socket passed to the constructor is already connected,
    it should be wrapped with::

        ssl.wrap_socket(sock, do_handshake_on_connect=False, **kwargs)

    before constructing the `SSLIOStream`.  Unconnected sockets will be
    wrapped when `IOStream.connect` is finished.
    cO�s�|jdt�|_tt|�j||�t|_t|_	t|_
d|_d|_
y|jj�Wntjk
r�nX|j|jj�dS(s�The ``ssl_options`` keyword argument may either be an
        `ssl.SSLContext` object or a dictionary of keywords arguments
        for `ssl.wrap_socket`
        R�N(tpopRt_ssl_optionsR�R�R@RRt_ssl_acceptingR*t_handshake_readingt_handshake_writingR"R�t_server_hostnameR�tgetpeernameR#RnRRo(R?R�R�((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR@�s					cC�s|jptt|�j�S(N(R�R�R�R(R?((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR�scC�s|jptt|�j�S(N(R�R�R�R�(R?((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR��scC�s�y#t|_t|_|jj�Wnjtjk
r%}|jdtjkr[t	|_dS|jdtj
kr~t	|_dS|jdtjtjfkr�|j
dt	�S|jdtjkry|jj�}Wntk
r�d}nXtjd|jj�||�|j
dt	�S�n�tjk
rr}|j|�s\|jdtjkrl|j
dt	�S�nWtk
r�|j
dt	�SXt|_|j|jj��s�|j
�dS|j�dS(NiRHs(not connected)sSSL Error on %s %s: %s(R*R�R�R�tdo_handshaketssltSSLErrorR�tSSL_ERROR_WANT_READRRtSSL_ERROR_WANT_WRITEt
SSL_ERROR_EOFtSSL_ERROR_ZERO_RETURNRQt
SSL_ERROR_SSLR�R�RR�RBR#RzR�tEBADFtAttributeErrorR�t_verify_certtgetpeercertt_run_ssl_connect_callback(R?R�tpeer((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyt_do_ssl_handshake�sD				

	%
	
cC�sf|jdk	r1|j}d|_|j|�n|jdk	rb|j}d|_|j|�ndS(N(R�R"R|R:R�(R?RURW((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR�s				cC�st|jt�r-|jjdtj�}n$t|jtj�rQ|jj}n|tjtjtj	fksut
�|tjks�|jdkr�t
S|jj�}|dkr�|tjkr�tjd�tSyt||j�Wn%tk
r
tjddt
�tSXt
SdS(sReturns True if peercert is valid according to the configured
        validation mode and hostname.

        The ssl handshake already tested the certificate for a valid
        CA signature; the only thing that remains is to check
        the hostname.
        t	cert_reqssNo SSL certificate givensInvalid SSL certificateRHN(R\R�tdicttgetR�t	CERT_NONEt
SSLContexttverify_modet
CERT_REQUIREDt
CERT_OPTIONALR_R�R"RRR�R�RR�R*R	R
(R?tpeercertR�tcert((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR�s"$

cC�s.|jr|j�dStt|�j�dS(N(R�R�R�R�R�(R?((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR�'s	
cC�s.|jr|j�dStt|�j�dS(N(R�R�R�R�Rm(R?((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRm-s	
cC�s5||_tt|�j|dd��|j|�S(NRUcS�sdS(N(R"(((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRK7s(R�R�R�R�twait_for_handshake(R?R�RUR�((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR�3s	cC�s�tt|�j�|j�r#dS|jj|j�|j}d|_t	|j|j
d|jdt�|_|j
|�dS(NR�R�(R�R�R�ReRRxR�R<R"RR�R�R*Rn(R?t	old_state((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR�:s			cC�s~|jdk	s|jdk	r-td��n|dk	rTtj|�|_d}nt�}|_|jsz|j�n|S(s�Wait for the initial SSL handshake to complete.

        If a ``callback`` is given, it will be called with no
        arguments once the handshake is complete; otherwise this
        method returns a `.Future` which will resolve to the
        stream itself after the handshake is complete.

        Once the handshake is complete, information such as
        the peer's certificate and NPN/ALPN selections may be
        accessed on ``self.socket``.

        This method is intended for use on server-side streams
        or after using `IOStream.start_tls`; it should not be used
        with `IOStream.connect` (which already waits for the
        handshake to complete). It may only be called once per stream.

        .. versionadded:: 4.2
        sAlready waitingN(	R�R"R:tRuntimeErrorR
R`RR�R�(R?RURW((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR�Qs		
cC�sNy|jj|�SWn3tjk
rI}|jdtjkrCdS�nXdS(Ni(R�R�R�R�R�R�(R?RDRX((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyREpscC�s�|jr
dSy|jj|j�}Wnbtjk
r[}|jdtjkrUdS�n0tj	k
r�}|jdt
kr�dS�nX|s�|j�dS|S(Ni(R�R"R�treadR R�R�R�R�R#R�RQ(R?R�RX((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRF~s 	
cC�sBt|tj�r,|jdtjkr,tStt|�j|�S(Ni(	R\R�R�R�R�RRR�R�Rz(R?RX((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRz�s(N(RRRR@RR�R�R�R�R�RmR"R�R�R�RERFRz(((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR��s
				-	
						tPipeIOStreamcB�s;eZdZd�Zd�Zd�Zd�Zd�ZRS(sPipe-based `IOStream` implementation.

    The constructor takes an integer file descriptor (such as one returned
    by `os.pipe`) rather than an open file object.  Pipes are generally
    one-way, so a `PipeIOStream` can be used for reading or writing but not
    both.
    cO�s0||_t|�tt|�j||�dS(N(R�RR�R�R@(R?R�R�R�((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR@�s	
cC�s|jS(N(R�(R?((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRB�scC�stj|j�dS(N(R�RQR�(R?((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRC�scC�stj|j|�S(N(R�RsR�(R?RD((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRE�scC�s�ytj|j|j�}Wn[ttfk
ry}t|�tkrJdSt|�t	j
krs|jdt�dS�nX|s�|j�dS|S(NRH(
R�R�R�R R�R�RR�R"R�R�RQRR(R?R�RX((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyRF�s
(RRRR@RBRCRERF(((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR��s				cC�sFtt|d�dt|d�t|d��}t||�dS(s`Grow by doubling, but don't split the second chunk just because the
    first one is small.
    iiiN(tmaxRjR�(R%tnew_len((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR��s!cC�s�t|�dkr,t|d�|kr,dSg}|}xo|r�|dkr�|j�}t|�|kr�|j||�|| }n|j|�|t|�8}q;W|r�|jt|d��j|��n|s�|jd�ndS(sReplace the first entries in a deque of strings with a single
    string of up to size bytes.

    >>> d = collections.deque(['abc', 'de', 'fghi', 'j'])
    >>> _merge_prefix(d, 5); print(d)
    deque(['abcde', 'fghi', 'j'])

    Strings will be split as necessary to reach the desired size.
    >>> _merge_prefix(d, 7); print(d)
    deque(['abcdefg', 'hi', 'j'])

    >>> _merge_prefix(d, 3); print(d)
    deque(['abc', 'defg', 'hi', 'j'])

    >>> _merge_prefix(d, 100); print(d)
    deque(['abcdefghij'])
    iiNR�(RjR�t
appendleftRlttypetjoin(R%R�tprefixt	remainingR�((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyR��s(

&cC�sddl}|j�S(Ni(tdoctesttDocTestSuite(R((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pytdoctests�s(ARt
__future__RRRRR$R�R]R�R�RvRMttornado.concurrentRttornadoRttornado.logRRttornado.netutilRR	R
RRR
ttornado.utilRttornado.platform.posixRtImportErrorR"R�tEWOULDBLOCKtEAGAINR�thasattrRt
ECONNRESETtECONNABORTEDtEPIPEt	ETIMEDOUTR�RtWSAECONNABORTEDtWSAETIMEDOUTtplatformt
EPROTOTYPEtEINPROGRESSR�RR�RR�RRtobjectRR�R�R�R�R�R(((s6/usr/lib64/python2.7/site-packages/tornado/iostream.pyt<module>s`"(




	���?��)			&

Zerion Mini Shell 1.0