
    PhF                     H   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlmZm	Z	m
Z
 d dlmZ d dlZg dZdZ ee j"                  e j$                  e j&                  f      Z ed e j*                  f      Zej.                  dd dk(  rej1                  e j2                         ej4                  rej6                  Zej:                  j=                  d      j                  Zej@                  d	k\  rejB                  Z"n%ejB                  jG                  ejB                        Z"d
 Z$d Z%d Z&ej.                  dd dk(  rH ee jN                  e j&                  f      Z( ee jR                  e jT                  e jV                  f      Z,nR ee jN                  e j&                  e jT                  f      Z( ee jR                  e jV                  e jZ                  f      Z,d Z.	 d dlm/Z/  G d de1      Z2d Z3dZ4	 d dl5m6Z6 d Z7y# e0$ r
  e1       Z/Y )w xY w# e0$ r  G d de1      Z6Y d Z7yw xY w)    N)
trampolinenotify_openedIOClosed)	get_errno)
GreenSocket_GLOBAL_DEFAULT_TIMEOUTset_nonblockingSOCKET_BLOCKINGSOCKET_CLOSEDCONNECT_ERRCONNECT_SUCCESSshutdown_safeSSLsocket_timeouti      winsocket)r   
   c                     | j                  |      }|t        v ry|t        vr't        j                  |t
        j                  |         | S )z
    Attempts to connect to the address, returns the descriptor if it succeeds,
    returns None if it needs to trampoline, and raises any exceptions.
    N)
connect_exr   r   r   errorerrno	errorcode)
descriptoraddresserrs      `C:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\eventlet/greenio/base.pysocket_connectr   &   sG    
 


(C
k
/!ll3 455    c                     | j                  t        j                  t        j                        }|t        vr't        j
                  |t        j                  |         y N)
getsockoptr   
SOL_SOCKETSO_ERRORr   r   r   r   )r   r   s     r   socket_checkerrr%   3   sE    


 1 16??
CC
/!ll3 455 "r   c                     	 | j                         S # t        j                  $ r'}t        |      t        j
                  k(  rY d}~y d}~ww xY w)z
    Attempts to accept() on the descriptor, returns a client,address tuple
    if it succeeds; returns None if it needs to trampoline, and raises
    any exceptions.
    N)acceptr   r   r   r   EWOULDBLOCK)r   es     r   socket_acceptr*   9   sB      ""<< Q<5,,,s    AAAAc                 N   	 | j                   } |d       y# t        $ r 	 ddl}n# t        $ r t	        d      w xY w| j                         }|j                  ||j                        }|t        j                  z  }||k7  r|j                  ||j                  |       Y yY yw xY w)z
    Sets the descriptor to be nonblocking.  Works on many file-like
    objects as well as sockets.  Only sockets can be nonblocking on
    Windows, however.
    r   Nznset_nonblocking() on a file object with no setblocking() method (Windows pipes don't support non-blocking I/O))
setblockingAttributeErrorfcntlImportErrorNotImplementedErrorfilenoF_GETFLos
O_NONBLOCKF_SETFL)fdr,   r.   r1   
orig_flags	new_flagss         r   r	   r	   R   s    nn2 	A1  :

	X 	X & 'W X X	X [[7
.	
"KKy9 #):s"    	B$&B$;A$B$#B$)r   c                   f   e Zd ZdZdZej                  fdZed        Z	e
j                  rd Zd Z eee      Zd Zd$dZd	 Zd
 Zd Zd Zd Zd Ze
j                  rd Znd Zd Zd Zd Zd%dZd%dZd&dZd&dZd Zd%dZ d Z!d%dZ"d Z#d Z$d Z%d Z&d  Z'd!e(jR                  v rd" Z*d# Z+yy)'r   a  
    Green version of socket.socket class, that is intended to be 100%
    API-compatible.

    It also recognizes the keyword parameter, 'set_nonblocking=True'.
    Pass False to indicate that socket is already in non-blocking mode
    to save syscalls.
    Nc                    |j                  dd      }t        |t        j                        r)t	        |g|i |}t        |j                                n|}	 |j                         xs t        j                         | _
        |r|j                         dk7  rt        |       || _        d| _        |j                  | _        |j                   | _        |j                  | _        |j"                  | _        |j$                  | _        |j&                  | _        |j(                  | _        |j*                  | _        d| _        y # t        $ r t        j                         | _
        Y w xY w)Nr	   TF)pop
isinstancesixinteger_types_original_socketr   r1   
gettimeoutr   getdefaulttimeout_timeoutr-   r	   r6   act_non_blockingbindclosegetsocknamer"   listen
setsockoptshutdown_closed)selffamilyargskwargsshould_set_nonblockingr6   s         r   __init__zGreenSocket.__init__   s   !',=t!Dfc//0!&:4:6:B"))+&B	7MMOIv/G/G/IDM "biikR&7B !& GG	XX
ii>>--ii--3  	7"446DM	7s   +E "E'&E'c                     | S r!    rL   s    r   _sockzGreenSocket._sock   s    r   c                 .    | j                   j                  S r!   r6   _io_refsrT   s    r   _get_io_refszGreenSocket._get_io_refs   s    77###r   c                 &    || j                   _        y r!   rW   )rL   values     r   _set_io_refszGreenSocket._set_io_refs   s    $DGGr   c                 z    | j                   t        |      t        | j                   |      }t        | ||       |S r!   )r6   r-   getattrsetattr)rL   nameattrs      r   __getattr__zGreenSocket.__getattr__   s7    77? &&tww%dD!r   c                     | j                   r
t               	 t        |||||| j                        S # t        $ r | j                           w xY w)z We need to trampoline via the event hub.
            We catch any signal back from the hub indicating that the operation we
            were waiting on was associated with a filehandle that's since been
            invalidated.
        )readwritetimeouttimeout_excmark_as_closed)rK   r   r   _mark_as_closed)rL   r6   rd   re   rf   rg   s         r   _trampolinezGreenSocket._trampoline   s]     << *	bt5'*5-1-A-AC C  	  "	s	   3 Ac                    | j                   r8| j                  j                         }t        |d   j	                                |S | j                  }t        d      }	 t        |      }|<|\  }}t        |j	                                t        |        t        |       |      |fS | j                  |d| j                         |       m)Nr   	timed outTrd   rf   rg   )rD   r6   r'   r   r1   r   r*   r	   typerj   rA   )rL   resr6   _timeout_excclientaddrs         r   r'   zGreenSocket.accept   s      ''.."C#a&--/*JWW%k2#C"fmmo.'!tDz&)4//RdDOO4ES_` r   c                     d| _         y)z" Mark this socket as being closed TN)rK   rT   s    r   ri   zGreenSocket._mark_as_closed   s	    r   c                 2    t        | dd       }| |        y y )NrF   )r^   )rL   rF   s     r   __del__zGreenSocket.__del__   s     gt,G r   c                    | j                   r| j                  j                  |      S | j                  }t        d      }| j	                         :t        ||      s-	 | j                  |d       t        |       t        ||      s,y y t        j                         | j	                         z   }	 t        ||      ry t        j                         |k\  r||t        j                         z
  }	 | j                  |d||       t        |       _# t        $ r$ t        j                  t        j                        w xY w# t        $ r$ t        j                  t        j                        w xY w)Nrl   Tre   re   rf   rg   )rD   r6   connectr   rA   r   rj   r   r   r   r   EBADFDr%   time)rL   r   r6   rp   endrf   s         r   ry   zGreenSocket.connect   s6     77??7++WW%k2??$$R15$$Rt$4  # %R1 ))+ 11C!"g.99;#%&&		+5$$RtWR^$_  #    5 ,,u||445   5 ,,u||445s   D -D> -D;>-E+c                 B   | j                   r| j                  j                  |      S | j                  }| j                         -t	        ||      s 	 | j                  |d       t        |       yy t        j                         | j                         z   }t        j                  t        j                        }	 	 t	        ||      ryt        j                         |k\  r|| j                  |d|t        j                         z
  |       t        |       y# t        j                  $ r}t        |      cY d }~S d }~wt        $ r t        j                  cY S w xY w# t        j                  $ r}t        |      cY d }~S d }~wt        $ r t        j                  cY S w xY w)NTrw   r   rx   )rD   r6   r   rA   r   rj   r%   r   r   r   r   r   rz   r{   rf   EAGAIN)rL   r   r6   exr|   rg   s         r   r   zGreenSocket.connect_ex  sU     77%%g..WW??$$R1($$Rt$4#B'
  2 ))+ 11C ..6K(%b'2 yy{c)))$$RtS499;=N1< % >#B'
 + || )$R=( ( <<'( || )$R=( ( <<'(sO   D ;E AE E*
D:4E:EEF/
E?9F?FFc                      | j                   j                  |i |} t        |       |d      }|j                  | j	                                |S )NF)r	   )r6   duprn   
settimeoutrA   )rL   rN   kwsocknewsocks        r   r   zGreenSocket.dup0  sG    tww{{D'B'$t*T594??,-r   c                 4    t        j                  | g|i |S r!   )r@   makefile)rL   rN   rO   s      r   r   zGreenSocket.makefile7  s    #,,TCDCFCCr   c                     | j                         }t        |g|i |}t        |d      r|j                          d |_        |S )N_drop)r   _python2_fileobjecthasattrr   rF   )rL   rN   rO   duppedro   s        r   r   zGreenSocket.makefile:  sB    XXZF%f>t>v>Cvw'
  $Jr   c                 ^    t        j                  dt        d        | j                  |i |S )Nz>makeGreenFile has been deprecated, please use makefile instead   )
stacklevel)warningswarnDeprecationWarningr   )rL   rN   r   s      r   makeGreenFilezGreenSocket.makeGreenFileF  s/     )*<	Lt}}d)b))r   c                 p    | j                  | j                  d| j                         t        d             y )NTrl   rm   )rj   r6   rA   r   rT   s    r   _read_trampolinezGreenSocket._read_trampolineK  s1    GGOO%&{3	 	 	5r   c                 N   | j                   r || S 	 	 |d   s| j                           || S # t        j                  $ r5}t	        |      t
        v rnt	        |      t        v r|cY d }~S  Y d }~nd }~ww xY w	 | j                          n# t        $ r}t               d }~ww xY wNr   )	rD   r   r   r   r   r
   r   r   EOFError)rL   	recv_meth	empty_valrN   r)   s        r   
_recv_loopzGreenSocket._recv_loopR  s      d## Aw))+ $''<< Q<?2q\]2$$	 !%%' !j !/ s9   . A6$A1%A6+A11A6:B 	B#
BB#c                 R    | j                  | j                  j                  d||      S Nr   )r   r6   recvrL   bufsizeflagss      r   r   zGreenSocket.recvq  s    tww||S'5AAr   c                 R    | j                  | j                  j                  d||      S r   )r   r6   recvfromr   s      r   r   zGreenSocket.recvfromt  s!    tww//guEEr   c                 T    | j                  | j                  j                  d|||      S r   )r   r6   	recv_intorL   buffernbytesr   s       r   r   zGreenSocket.recv_intow  s#    tww00!VVUKKr   c                 T    | j                  | j                  j                  d|||      S r   )r   r6   recvfrom_intor   s       r   r   zGreenSocket.recvfrom_intoz  s#    tww44aOOr   c                    | j                   r	 ||g| S t        d      }	 	  ||g| S # t        j                  $ r1}t	        |      }|t
        j                  k(  s|t        vr Y d }~nd }~ww xY w	 | j                  | j                  d| j                         |       n1# t        $ r% t        j                  t
        j                  d      w xY w)Nrl   Trx   z#Connection closed by another thread)rD   r   r   r   r   r   ENOTCONNr
   rj   r6   rA   r   
ECONNRESET)rL   send_methoddatarN   rp   r)   enos          r   
_send_loopzGreenSocket._send_loop}  s      t+d++%k2"4/$//<< l%..(C,F -G
\  doo>O-9 ! ; \ll5#3#35Z[[\ s    , A0'A++A04-B" ".Cc                 P    | j                  | j                  j                  ||      S r!   )r   r6   send)rL   r   r   s      r   r   zGreenSocket.send  s    tww||T599r   c                 R     | j                   | j                  j                  |g| S r!   )r   r6   sendto)rL   r   rN   s      r   r   zGreenSocket.sendto  s"    ttww~~t;d;;r   c                     | j                  ||      }t        |      }||k  r|| j                  ||d  |      z  }||k  ry y r!   )r   len)rL   r   r   taillen_datas        r   sendallzGreenSocket.sendall  sF    yyu%t9XoDIId45k511D Xor   c                 B    |rd| _         d | _        y d| _         d| _        y )NFT        )rD   rC   )rL   flags     r   r,   zGreenSocket.setblocking  s#    $)D! DM$(D!DMr   c                     |	|t         k(  r| j                  d       y 	 |j                  } |       }|dk  rt        d      |dk(  rd| _        d| _        y d| _        || _        y # t        $ r t	        d      w xY w)NTza float is requiredr   zTimeout value out of rangeF)r   r,   	__float__r-   	TypeError
ValueErrorrD   rC   )rL   howlongfs      r   r   zGreenSocket.settimeout  s    ?g)@@T"	3!!A #S=9::c>$(D!DM$)D!#DM  	3122	3s   A% %A:c                     | j                   S r!   )rC   rT   s    r   rA   zGreenSocket.gettimeout  s    }}r   c                     | S r!   rS   rT   s    r   	__enter__zGreenSocket.__enter__  s    r   c                 $    | j                          y r!   )rF   )rL   rN   s     r   __exit__zGreenSocket.__exit__  s    

r   __pypy__c                 b    t        | j                  d| j                        j                          y NrU   )r^   r6   _reuserT   s    r   r   zGreenSocket._reuse  s    DGGWdgg.557r   c                 b    t        | j                  d| j                        j                          y r   )r^   r6   r   rT   s    r   r   zGreenSocket._drop  s    DGGWdgg.446r   )FFNN)r   )r   r   ),__name__
__module____qualname____doc__r6   r   AF_INETrQ   propertyrU   r>   PY3rY   r\   rX   rb   rj   r'   ri   ru   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r,   r   rA   r   r   sysbuiltin_module_namesr   r   rS   r   r   r   r   {   s    
B$nn %N   ww	$	% L,7&a $6@ ww	D
	*
5!>BFLP\&:<2 $$ S---	8	7	 .r   r   c                      t        d      )NzI/O operation on closed file)r   )rN   rO   s     r   _operation_on_closed_filer     s    
3
44r   a  
    GreenPipe is a cooperative replacement for file class.
    It will cooperate on pipes. It will block on regular file.
    Differences from file class:
    - mode is r/w property. Should re r/o
    - encoding property not implemented
    - write/writelines will not raise TypeError exception when non-string data is written
      it will write str(data) instead
    - Universal new lines are not supported and newlines property not implementeded
    - file argument can be descriptor, file name or file object.
    )r   c                   d    e Zd Z G d de      Z G d de      Z G d de      Z G d de      Zy	)
r   c                       e Zd Zy)SSL.WantWriteErrorNr   r   r   rS   r   r   WantWriteErrorr         r   r   c                       e Zd Zy)SSL.WantReadErrorNr   rS   r   r   WantReadErrorr     r   r   r   c                       e Zd Zy)SSL.ZeroReturnErrorNr   rS   r   r   ZeroReturnErrorr     r   r   r   c                       e Zd Zy)SSL.SysCallErrorNr   rS   r   r   SysCallErrorr     r   r   r   N)r   r   r   	Exceptionr   r   r   r   rS   r   r   r   r     s2    	Y 		I 		i 		9 	r   r   c                 8   	 	 | j                  t        j                        S # t        $ r | j                         cY S w xY w# t        j                  $ rE}t        |      t        j                  t        j                  t        j                  fvr Y d}~yd}~ww xY w)a  Shuts down the socket. This is a convenience method for
    code that wants to gracefully handle regular sockets, SSL.Connection
    sockets from PyOpenSSL and ssl.SSLSocket objects from Python 2.7 interchangeably.
    Both types of ssl socket require a shutdown() before close,
    but they have different arity on their shutdown method.

    Regular sockets don't need a shutdown before close, but it doesn't hurt.
    N)
rJ   r   	SHUT_RDWRr   r   r   r   r   EBADFENOTSOCK)r   r)   s     r   r   r     s{    	#==!1!122 	#==?"	# <<  Q<U^^LL Ms(   " >A >A B;BB)8r   r3   r   r   r{   r   eventleteventlet.hubsr   r   r   eventlet.supportr   r>   __all__BUFFER_SIZEsetEINPROGRESSEALREADYr(   r   EISCONNr   platformadd	WSAEINVALPY2_fileobjectr   patcheroriginalr@   version_inforf   r   wrap_is_timeoutr   r%   r*   r~   r
   r   r   	ESHUTDOWNr   EPIPEr	   r   r/   objectr   r   greenpipe_docOpenSSLr   r   rS   r   r   <module>r     s    	  
    = = & 
 5$$enne6G6GHIq%--()<<uOOEOO$77 ,,##,,X6==  w^^N%%55fnnEN
6 <<u5<<):):<=O))5>>5??KLM 5<<):):ENNKLO))5??EKKHIM F'.
I7& I7X
5
"g  '$h'F  f !s$   G9 /H 9HHH! H!