ó
čžbc           @   sf   d  Z  d d l Z e j d e d  d d d     YZ d d d  Z d	   Z d
 Z d Z d Z	 d S(   s:  Extended file operations available in POSIX.

f = posixfile.open(filename, [mode, [bufsize]])
      will create a new posixfile object

f = posixfile.fileopen(fileobject)
      will create a posixfile object from a builtin file object

f.file()
      will return the original builtin file object

f.dup()
      will return a new file object based on a new filedescriptor

f.dup2(fd)
      will return a new file object based on the given filedescriptor

f.flags(mode)
      will turn on the associated flag (merge)
      mode can contain the following characters:

  (character representing a flag)
      a       append only flag
      c       close on exec flag
      n       no delay flag
      s       synchronization flag
  (modifiers)
      !       turn flags 'off' instead of default 'on'
      =       copy flags 'as is' instead of default 'merge'
      ?       return a string in which the characters represent the flags
              that are set

      note: - the '!' and '=' modifiers are mutually exclusive.
            - the '?' modifier will return the status of the flags after they
              have been changed by other characters in the mode string

f.lock(mode [, len [, start [, whence]]])
      will (un)lock a region
      mode can contain the following characters:

  (character representing type of lock)
      u       unlock
      r       read lock
      w       write lock
  (modifiers)
      |       wait until the lock can be granted
      ?       return the first lock conflicting with the requested lock
              or 'None' if there is no conflict. The lock returned is in the
              format (mode, len, start, whence, pid) where mode is a
              character representing the type of lock ('r' or 'w')

      note: - the '?' modifier prevents a region from being locked; it is
              query only
i˙˙˙˙NsI   The posixfile module is deprecated; fcntl.lockf() provides better lockingi   t   _posixfile_c           B   sh   e  Z d  Z d d g Z d   Z d d d  Z d   Z d   Z d	   Z d
   Z	 d   Z
 d   Z RS(   s;   File wrapper class that provides extra POSIX file routines.t   opent   closedc         C   s=   |  j  } d |  j | j | j | j t t |    d f S(   Ns$   <%s posixfile '%s', mode '%s' at %s>i   (   t   _file_t   statesR   t   namet   modet   hext   id(   t   selft   file(    (    s   /usr/lib/python2.7/posixfile.pyt   __repr__C   s    	t   ri˙˙˙˙c         C   s(   d d  l  } |  j | j | | |   S(   Ni˙˙˙˙(   t   __builtin__t   fileopenR   (   R	   R   R   t   bufsizeR   (    (    s   /usr/lib/python2.7/posixfile.pyR   L   s    c         C   s   d d  l  } t t |   d k r0 t d  n  | |  _ xZ t |  D]L } | j d  sF t | |  } t | | j	  r t
 |  | |  q qF qF W|  S(   Ni˙˙˙˙s   <type 'file'>s,   posixfile.fileopen() arg must be file objectt   _(   t   typest   reprt   typet	   TypeErrorR   t   dirt
   startswitht   getattrt
   isinstancet   BuiltinMethodTypet   setattr(   R	   R
   R   t   maybemethodt   attr(    (    s   /usr/lib/python2.7/posixfile.pyR   P   s    	c         C   s   |  j  S(   N(   R   (   R	   (    (    s   /usr/lib/python2.7/posixfile.pyR
   `   s    c         C   sO   d d  l  } t | d  s' t d  n  | j | j |  j j    |  j j  S(   Ni˙˙˙˙t   fdopens   dup() method unavailable(   t   posixt   hasattrt   AttributeErrorR   t   dupR   t   filenoR   (   R	   R   (    (    s   /usr/lib/python2.7/posixfile.pyR!   c   s    c         C   sV   d d  l  } t | d  s' t d  n  | j |  j j   |  | j | |  j j  S(   Ni˙˙˙˙R   s   dup() method unavailable(   R   R   R    t   dup2R   R"   R   R   (   R	   t   fdR   (    (    s   /usr/lib/python2.7/posixfile.pyR#   k   s
    c         G   s  d d  l  } d d  l } | rI t |  d k r< t d  n  | d } n d } d } d | k rq | | j B} n  d | k r | | j B} n  d | k rŠ | | j B} n  |  j } d	 | k r| j  | j   | j	 d  } d
 | k rö | | @} q| | B} n  | j  | j   | j
 |  } d | k rZd
 | k } | j  | j   | j |  } n  d | k rd } | j  | j   | j	 d  } | j | @r¤| d } n  | j  | j   | j d  d @rÓ| d } n  | j | @rí| d } n  | j | @r| d } n  | Sd  S(   Ni˙˙˙˙i   s   Too many argumentsi    t   ?t   nt   at   st   =t   !t   ct    (   t   fcntlt   ost   lenR   t   O_NDELAYt   O_APPENDt   O_SYNCR   R"   t   F_GETFLt   F_SETFLt   F_SETFDt   F_GETFD(   R	   t   whichR-   R.   t   l_flagsR
   t   cur_flt   arg(    (    s   /usr/lib/python2.7/posixfile.pyt   flagst   sF       	 ! "  c         G   s  d d  l  } d d  l } d | k r0 | j } n9 d | k rH | j } n! d | k r` | j } n	 t d  d | k r | j } n! d | k r | j } n	 | j } d } d } d }	 t	 |  d	 k rÓ | d }	 nc t	 |  d
 k rô | \ }	 } nB t	 |  d k r| \ }	 } } n t	 |  d k r6t d  n  d d  l
 }
 d d  l } |
 j d k r| j d | |	 | j   | |  } nW |
 j d  k rş| j d | | | |	 d d d  } n! | j d | | | |	 d d  } | j |  j j   | |  } d | k r|
 j d! k r8| j d |  \ } }	 } } } n |
 j d" k rq| j d |  \ } } } }	 } } } nZ |
 j d k r§| j d |  \ } } } }	 } } n$ | j d |  \ } } } }	 } } | | j k r| | j k rüd |	 | | | f Sd |	 | | | f Sqn  d  S(#   Ni˙˙˙˙t   wR   t   us   no type of lock specifiedt   |R%   i    i   i   i   s   too many argumentst   netbsd1t   openbsd2t   freebsd2t   freebsd3t   freebsd4t   freebsd5t   freebsd6t   freebsd7t   freebsd8t   bsdos2t   bsdos3t   bsdos4t   lxxxxlxxxxlhht   aix3t   aix4t   hhllliit   hhllhht   linux2(   R?   R@   RA   RB   RC   RD   RE   RF   RG   RH   RI   RJ   (   RL   RM   (	   R?   R@   RA   RB   RC   RD   RH   RI   RJ   (   RL   RM   (   t   structR-   t   F_WRLCKt   F_RDLCKt   F_UNLCKR   t   F_SETLKWt   F_GETLKt   F_SETLKR/   t   sysR.   t   platformt   packt   getpidR   R"   t   unpack(   R	   t   howt   argsRQ   R-   t   l_typet   cmdt   l_whencet   l_startt   l_lenRX   R.   t   flockt   l_pidt   l_sysidt   l_vfs(    (    s   /usr/lib/python2.7/posixfile.pyt   lock   sj       	  	   				  	$*'$(   t   __name__t
   __module__t   __doc__R   R   R   R   R
   R!   R#   R;   Rh   (    (    (    s   /usr/lib/python2.7/posixfile.pyR    ;   s   								%R   c         C   s   t    j |  | |  S(   s4   Public routine to open a file as a posixfile object.(   R    R   (   R   R   R   (    (    s   /usr/lib/python2.7/posixfile.pyR   Ü   s    c         C   s   t    j |   S(   sC   Public routine to get a posixfile object from a Python file object.(   R    R   (   R
   (    (    s   /usr/lib/python2.7/posixfile.pyR   ŕ   s    i    i   (    (
   Rk   t   warningst   warnt   DeprecationWarningR    R   R   t   SEEK_SETt   SEEK_CURt   SEEK_END(    (    (    s   /usr/lib/python2.7/posixfile.pyt   <module>6   s   	
Ą	