σ
ζNXc           @@ sX  d  Z  d d l m Z d d l m Z d d l Z d d l Z d d l Z d d l m Z d d l	 m
 Z
 m Z d d l m Z m Z m Z d	 d d
     YZ e e j d  Z e e j d e Z e e j d e Z e e j d e Z d e f d     YZ d d d  Z d d  Z d   Z d   Z d   Z e Z e Z d d  Z  d S(   s   
IO related utilities.
i    (   t   print_function(   t   absolute_importN(   t   warni   (   t
   CapturedIOt   capture_output(   t   string_typest   inputt   PY3t   IOStreamc           B@ sG   e  Z d d   Z d   Z d   Z d   Z e d    Z d   Z	 RS(   c         @ s₯   t  | d  s  t  | d  rD | d  k	 r5 | } qD t d   n  |   _ | j   _   f d   } x6 t | t |   D] } t   | t	 | |   q~ Wd  S(   Nt   writet   flushs$   fallback required, but not specifiedc         @ s   t    |   o |  j d  S(   Nt   _(   t   hasattrt
   startswith(   t   meth(   t   self(    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/io.pyt   clone!   s    (
   R   t   Nonet
   ValueErrort   streamR	   t   _swritet   filtert   dirt   setattrt   getattr(   R   R   t   fallbackR   R   (    (   R   sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/io.pyt   __init__   s     		c         C@ s4   |  j  } d } | j d | j d | j d |  j  S(   Ns   {mod}.{cls}({args})t   modt   clst   args(   t	   __class__t   formatt
   __module__t   __name__R   (   R   R   t   tpl(    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/io.pyt   __repr__&   s    	c         C@ s_   y |  j  |  WnG y t | d d d |  j Wq[ t d |  j d t j q[ Xn Xd  S(   Nt   endt    t   files'   ERROR - failed to write data to stream:(   R   t   printR   t   syst   stderr(   R   t   data(    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/io.pyR	   +   s    c         C@ s=   t  | t  r | g } n  x | D] } |  j |  q" Wd  S(   N(   t
   isinstanceR   R	   (   R   t   linest   line(    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/io.pyt
   writelines9   s    c         C@ s
   |  j  j S(   N(   R   t   closed(   R   (    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/io.pyR/   C   s    c         C@ s   d  S(   N(    (   R   (    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/io.pyt   closeG   s    N(
   R!   R    R   R   R#   R	   R.   t   propertyR/   R0   (    (    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/io.pyR      s   			
t   wR   t   Teec           B@ sA   e  Z d  Z d d d  Z d   Z d   Z d   Z d   Z RS(   sε   A class to duplicate an output stream to stdout/err.

    This works in a manner very similar to the Unix 'tee' command.

    When the object is closed or deleted, it closes the original file given to
    it for duplication.
    R2   t   stdoutc         C@ s   | d k r t  d |   n  t | d  rI t | d  rI | |  _ n t | |  |  _ | |  _ t t |  |  _ t t | |   t	 |  _
 d S(   sL  Construct a new Tee object.

        Parameters
        ----------
        file_or_name : filename or open filehandle (writable)
          File that will be duplicated

        mode : optional, valid mode for open().
          If a filename was give, open with this mode.

        channel : str, one of ['stdout', 'stderr']
        R4   R)   s   Invalid channel spec %sR	   t   seekN(   s   stdouts   stderr(   R   R   R&   t   opent   channelR   R(   t   ostreamR   t   Falset   _closed(   R   t   file_or_namet   modeR7   (    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/io.pyR   [   s    	c         C@ s:   |  j    t t |  j |  j  |  j j   t |  _ d S(   s'   Close the file and restore the channel.N(	   R
   R   R(   R7   R8   R&   R0   t   TrueR:   (   R   (    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/io.pyR0   t   s    
c         C@ s1   |  j  j |  |  j j |  |  j j   d S(   s   Write data to both channels.N(   R&   R	   R8   R
   (   R   R*   (    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/io.pyR	   {   s    c         C@ s   |  j  j   |  j j   d S(   s   Flush both channels.N(   R&   R
   R8   (   R   (    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/io.pyR
      s    c         C@ s   |  j  s |  j   n  d  S(   N(   R:   R0   (   R   (    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/io.pyt   __del__   s    	(   R!   R    t   __doc__R   R0   R	   R
   R>   (    (    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/io.pyR3   P   s   			c         C@ sΚ   i t  d 6t d 6t  d 6t d 6} d } x | | j   k rΑ y) t |  d  j   } | se | } n  Wq+ t k
 r | rΎ | } qΎ q+ t k
 r½ | | j   k r· | } t   qΎ   q+ Xq+ W| | S(   sά  Asks a question and returns a boolean (y/n) answer.

    If default is given (one of 'y','n'), it is used if the user input is
    empty. If interrupt is given (one of 'y','n'), it is used if the user
    presses Ctrl-C. Otherwise the question is repeated until an answer is
    given.

    An EOF is treated as the default answer.  If there is no default, an
    exception is raised to prevent infinite loops.

    Valid answers are: y/yes/n/no (match is not case sensitive).t   yt   nt   yest   not    N(	   R=   R9   R   t   keysR   t   lowert   KeyboardInterruptt   EOFErrorR'   (   t   promptt   defaultt	   interruptt   answerst   ans(    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/io.pyt
   ask_yes_no   s     "
s   .pyc         C@ sC   t  j |  d } t | d  } | j |   | j   | | f S(   s£  Make a temporary python file, return filename and filehandle.

    Parameters
    ----------
    src : string or list of strings (no need for ending newlines if list)
      Source code to be written to the file.

    ext : optional, string
      Extension for the generated file.

    Returns
    -------
    (filename, open filehandle)
      It is the caller's responsibility to close the open file and unlink it.
    i   R2   (   t   tempfilet   mkstempR6   R	   R
   (   t   srct   extt   fnamet   f(    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/io.pyt   temp_pyfile¬   s
    
c          O@ s'   t  d  d d l m } | |  |   S(   s6   DEPRECATED: moved to notebook.services.contents.fileiosN   IPython.utils.io.atomic_writing has moved to notebook.services.contents.fileioi    (   t   atomic_writing(   R   t!   notebook.services.contents.fileioRV   (   R   t   kwargsRV   (    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/io.pyRV   Β   s    
c          O@ sH   t  d | j d d  d | j d d  d t j |   t j j   d S(   sF   Raw print to sys.__stdout__, otherwise identical interface to print().t   sepRD   R$   s   
R&   N(   R'   t   getR(   t
   __stdout__R
   (   R   t   kw(    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/io.pyt	   raw_printΘ   s    *c          O@ sH   t  d | j d d  d | j d d  d t j |   t j j   d S(   sF   Raw print to sys.__stderr__, otherwise identical interface to print().RY   RD   R$   s   
R&   N(   R'   RZ   R(   t
   __stderr__R
   (   R   R\   (    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/io.pyt   raw_print_errΠ   s    *R4   c         C@ s$   t  d  d d l m } | |   S(   s'   DEPRECATED, moved to nbconvert.utils.iosC   IPython.utils.io.unicode_std_stream has moved to nbconvert.utils.ioi    (   t   unicode_std_stream(   R   t   nbconvert.utils.ioR`   (   R   R`   (    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/io.pyR`   έ   s    
(    (!   R?   t
   __future__R    R   t   osR(   RO   t   warningsR   t   captureR   R   t	   py3compatR   R   R   R   R6   t   devnullt   stdinR4   R)   t   objectR3   R   RN   RU   RV   R]   R_   t   rprintt   rprinteR`   (    (    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/io.pyt   <module>   s,   6;!				