ó
ÐH/\c           @` s6  d  d l  m Z m Z m Z y d  d l m Z Wn e k
 rI d Z n Xd  d l Z d  d l m	 Z	 d  d l
 Z
 d  d l Z d  d l m Z d  d l m Z d  d l m Z d  d	 l m Z m Z d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   i    (   t   absolute_importt   print_functiont   division(   t   EBADFi	   N(   t   TextIOWrapper(   t   _get_hub_noargs(   t   integer_types(   t   reraise(   t	   Semaphoret   DummySemaphoret   cancel_wait_exc           B` s   e  Z d  „  Z RS(   c         C` s   t  t |  ƒ j t d ƒ d  S(   Ns.   File descriptor was closed in another greenlet(   t   superR
   t   __init__R   (   t   self(    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyR      s    (   t   __name__t
   __module__R   (    (    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyR
      s   t   FileObjectClosedc           B` s   e  Z d  „  Z RS(   c         C` s   t  t |  ƒ j t d ƒ d  S(   Ns+   Bad file descriptor (FileObject was closed)(   R   R   R   R   (   R   (    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyR      s    (   R   R   R   (    (    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyR      s   t   FileObjectBasec           B` s­   e  Z d  Z d Z e Z d Z d Z d „  Z	 e
 d „  d „  ƒ Z d „  Z d „  Z d „  Z e
 d „  ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   so   
    Internal base class to ensure a level of consistency
    between FileObjectPosix and FileObjectThread
    t   flusht   filenot   writablet   readablet   seekt   seekablet   tellt   readt   readlinet	   readlinest   read1t   writet
   writelinest   truncatec         C` sE   | |  _  | |  _ |  j r7 |  j d |  j |  j ƒ n
 |  j ƒ  d S(   s6   
        :param io: An io.IOBase-like object.
        N(   t   _iot   _closet
   _translatet   translate_newlinest   Nonet   _translate_encodingt   _translate_errorst   _do_delegate_methods(   R   t   iot   closefd(    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyR   E   s
    			c         C` s   |  j  S(   N(   R    (   t   s(    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyt   <lambda>V   s    c         C` s   t  |  d | ƒ p |  j ƒ  S(   NR    (   t   setattrR'   (   R*   t   nv(    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyR+   \   s    c         C` s‘   xŠ |  j  D] } t |  j | d  ƒ } t t |  ƒ | ƒ } | rc | rc t |  | |  j | ƒ ƒ q
 t |  | ƒ r
 | r
 t |  | ƒ q
 q
 Wd  S(   N(	   t   _delegate_methodst   getattrR    R$   t   hasattrt   typeR,   t   _wrap_methodt   delattr(   R   t	   meth_namet   metht   implemented_by_class(    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyR'   ^   s    c         C` s   | S(   s›   
        Wrap a method we're copying into our dictionary from the underlying
        io object to do something special or different, if necessary.
        (    (   R   t   method(    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyR2   g   s    c         O` s=   t  |  j | | Ž } | r' | | _ n  | |  _ t |  _ d  S(   N(   R   R    t   modeR(   t   TrueR"   (   R   R8   t	   text_argst   text_kwargst   wrapper(    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyR#   n   s
    	c         C` s   |  j  d k S(   s   True if the file is closedN(   R    R$   (   R   (    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyt   closedu   s    c         C` s<   |  j  d  k r d  S|  j  } d  |  _  |  j | |  j ƒ d  S(   N(   R    R$   t	   _do_closeR!   (   R   R(   (    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyt   closez   s
    		c         C` s   t  ƒ  ‚ d  S(   N(   t   NotImplementedError(   R   t   fobjR)   (    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyR>   ‚   s    c         C` s+   |  j  d  k r t ƒ  ‚ n  t |  j  | ƒ S(   N(   R    R$   R   R/   (   R   t   name(    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyt   __getattr__…   s    c         C` s    d |  j  j |  j |  j ƒ  f S(   Ns   <%s _fobj=%r%s>(   t	   __class__R   R(   t   _extra_repr(   R   (    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyt   __repr__Š   s    c         C` s   d S(   Nt    (    (   R   (    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyRE      s    c         C` s   |  S(   N(    (   R   (    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyt	   __enter__   s    c         G` s   |  j  ƒ  d  S(   N(   R?   (   R   t   args(    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyt   __exit__“   s    (   R   R   R   R   R   R   R   R   R   R   R   R   R   R   N(   R   R   t   __doc__R.   t   FalseR"   R$   R%   R&   R   t   propertyR(   R'   R2   R#   R=   R?   R>   RC   RF   RE   RH   RJ   (    (    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyR       s@                												t   FileObjectBlockc           B` s   e  Z d  „  Z d „  Z RS(   c         O` s‡   | j  d t ƒ } | r1 t d | j ƒ  ƒ ‚ n  t | t ƒ rj | sU t d ƒ ‚ n  t j | | Œ } n  t t	 |  ƒ j
 | | ƒ d  S(   NR?   s   Unexpected arguments: %rs6   FileObjectBlock does not support close=False on an fd.(   t   popR9   t	   TypeErrort   keyst
   isinstanceR   t   ost   fdopenR   RN   R   (   R   RA   RI   t   kwargsR)   (    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyR   ˜   s    c         C` s   | j  ƒ  d  S(   N(   R?   (   R   RA   R)   (    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyR>   £   s    (   R   R   R   R>   (    (    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyRN   –   s   	t   FileObjectThreadc           B` sb   e  Z d  Z d	 d e d	 e d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 e
 Z d „  Z RS(
   sÌ  
    A file-like object wrapping another file-like object, performing all blocking
    operations on that object in a background thread.

    .. caution::
        Attempting to change the threadpool or lock of an existing FileObjectThread
        has undefined consequences.

    .. versionchanged:: 1.1b1
       The file object is closed using the threadpool. Note that whether or
       not this action is synchronous or asynchronous is not documented.

    iÿÿÿÿc         C` s#  | } | p t  ƒ  j |  _ | |  _ |  j t k rB t ƒ  |  _ n |  j sZ t ƒ  |  _ n  t |  j d ƒ sˆ t d t |  j ƒ ƒ ‚ n  t	 | t
 ƒ rú | s¬ t d ƒ ‚ n  | d k râ | d k sÐ t d ƒ ‚ t j | ƒ } qú t j | | | ƒ } n  | g |  _ t t |  ƒ j | | ƒ d S(   s  
        :param fobj: The underlying file-like object to wrap, or an integer fileno
           that will be pass to :func:`os.fdopen` along with *mode* and *bufsize*.
        :keyword bool lock: If True (the default) then all operations will
           be performed one-by-one. Note that this does not guarantee that, if using
           this file object from multiple threads/greenlets, operations will be performed
           in any particular order, only that no two operations will be attempted at the
           same time. You can also pass your own :class:`gevent.lock.Semaphore` to synchronize
           file operations with an external resource.
        :keyword bool close: If True (the default) then when this object is closed,
           the underlying object is closed as well.
        RH   s'   Expected a Semaphore or boolean, got %rs7   FileObjectThread does not support close=False on an fd.iÿÿÿÿs7   If you use the default mode, you can't choose a bufsizeN(   t   get_hubt
   threadpoolt   lockR9   R   R	   R0   RP   R1   RR   R   R$   t   AssertionErrorRS   RT   t   _FileObjectThread__io_holderR   RV   R   (   R   RA   R8   t   bufsizeR?   RX   RY   R)   (    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyR   µ   s$    		c         C` s|   d  |  j d <z' |  j  |  j j | j ƒ Wd  QXWd  | rw | d „ } ~ |  j j | ƒ } ~ | rw t | Œ  qw n  Xd  S(   Ni    c         S` s1   z# y |  j  ƒ  Wn t j ƒ  SXWd  d  }  Xd  S(   N(   R?   t   syst   exc_infoR$   (   t   _fobj(    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyR?   æ   s     (   R$   R[   RY   RX   t   applyR   R   (   R   RA   R)   R?   R^   (    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyR>   Ø   s    
c         C` sa   t  t |  ƒ j ƒ  t |  d ƒ rM d t |  j d d ƒ k rM |  j |  _ n  |  j |  j d <d  S(   NR   t   rR8   RG   i    (	   R   RV   R'   R0   R/   R    R   R   R[   (   R   (    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyR'   õ   s    +c         C` s   d |  j  f S(   Ns    threadpool=%r(   RX   (   R   (    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyRE   û   s    c         C` s   |  S(   N(    (   R   (    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyt   __iter__þ   s    c         C` s    |  j  ƒ  } | r | St ‚ d  S(   N(   R   t   StopIteration(   R   t   line(    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyt   next  s    c         ` sF   |  j  ‰  |  j ‰ |  j ‰ t j ˆ ƒ ‡  ‡ ‡ ‡ f d †  ƒ } | S(   Nc          ` s@   ˆ  d d  k r t ƒ  ‚ n  ˆ  ˆ j ˆ |  | ƒ SWd  QXd  S(   Ni    (   R$   R   R`   (   RI   RU   (   t	   io_holderRY   R7   RX   (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyt   thread_method  s    (   R[   RY   RX   t	   functoolst   wraps(   R   R7   Rg   (    (   Rf   RY   R7   RX   s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyR2     s
    			'
N(   R   R   RK   R$   R9   R   R>   R'   RE   Rb   Re   t   __next__R2   (    (    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyRV   ¦   s   #					(   t
   __future__R    R   R   t   errnoR   t   ImportErrorRS   R(   R   Rh   R]   t
   gevent.hubR   RW   t   gevent._compatR   R   t   gevent.lockR   R	   t   IOErrorR
   R   t   objectR   RN   RV   (    (    (    s7   lib/python2.7/site-packages/gevent/_fileobjectcommon.pyt   <module>   s"   
v