AlkantarClanX12

Your IP : 18.221.102.0


Current Path : /proc/thread-self/root/opt/alt/python33/lib64/python3.3/__pycache__/
Upload File :
Current File : //proc/thread-self/root/opt/alt/python33/lib64/python3.3/__pycache__/pipes.cpython-33.pyc

�
��f�"c@s�dZddlZddlZddlZddlmZdgZdZdZdZ	dZ
d	Zd
Zeee	e
eegZ
Gdd�d�Zdd
�ZdS(u�Conversion pipeline templates.

The problem:
------------

Suppose you have some data that you want to convert to another format,
such as from GIF image format to PPM image format.  Maybe the
conversion involves several steps (e.g. piping it through compress or
uuencode).  Some of the conversion steps may require that their input
is a disk file, others may be able to read standard input; similar for
their output.  The input to the entire conversion may also be read
from a disk file or from an open file, and similar for its output.

The module lets you construct a pipeline template by sticking one or
more conversion steps together.  It will take care of creating and
removing temporary files if they are necessary to hold intermediate
data.  You can then use the template to do conversions from many
different sources to many different destinations.  The temporary
file names used are different each time the template is used.

The templates are objects so you can create templates for many
different conversion steps and store them in a dictionary, for
instance.


Directions:
-----------

To create a template:
    t = Template()

To add a conversion step to a template:
   t.append(command, kind)
where kind is a string of two characters: the first is '-' if the
command reads its standard input or 'f' if it requires a file; the
second likewise for the output. The command must be valid /bin/sh
syntax.  If input or output files are required, they are passed as
$IN and $OUT; otherwise, it must be  possible to use the command in
a pipeline.

To add a conversion step at the beginning:
   t.prepend(command, kind)

To convert a file to another file using a template:
  sts = t.copy(infile, outfile)
If infile or outfile are the empty string, standard input is read or
standard output is written, respectively.  The return value is the
exit status of the conversion pipeline.

To open a file for reading or writing through a conversion pipeline:
   fp = t.open(file, mode)
where mode is 'r' to read the file, or 'w' to write it -- just like
for the built-in function open() or for os.popen().

To create a new template object initialized to a given one:
   t2 = t.clone()
iN(uquoteuTemplateuffu-fuf-u--u.-u-.cBs�|EeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS(uTemplateu'Class representing a pipeline template.cCsd|_|j�dS(u-Template() returns a fresh pipeline template.iN(u	debuggingureset(uself((u*/opt/alt/python33/lib64/python3.3/pipes.pyu__init__Us	uTemplate.__init__cCsd|jfS(u t.__repr__() implements repr(t).u<Template instance, steps=%r>(usteps(uself((u*/opt/alt/python33/lib64/python3.3/pipes.pyu__repr__ZsuTemplate.__repr__cCs
g|_dS(u<t.reset() restores a pipeline template to its initial state.N(usteps(uself((u*/opt/alt/python33/lib64/python3.3/pipes.pyureset^suTemplate.resetcCs/t�}|jdd�|_|j|_|S(ubt.clone() returns a new pipeline template with identical
        initial state as the current one.N(uTemplateustepsu	debugging(uselfut((u*/opt/alt/python33/lib64/python3.3/pipes.pyuclonebs	uTemplate.clonecCs
||_dS(u(t.debug(flag) turns debugging on or off.N(u	debugging(uselfuflag((u*/opt/alt/python33/lib64/python3.3/pipes.pyudebugjsuTemplate.debugcCst|�td�k	r'td��n|tkrItd|f��n|tkrdtd��n|jr�|jddtkr�td��n|ddkr�tjd	|�r�td
��n|ddkr�tjd|�r�td��n|jj	||f�d
S(u/t.append(cmd, kind) adds a new step at the end.uu%Template.append: cmd must be a stringuTemplate.append: bad kind %ru-Template.append: SOURCE can only be prependediu'Template.append: already ends with SINKiufu\$IN\bu#Template.append: missing $IN in cmdu\$OUT\bu$Template.append: missing $OUT in cmdNi����(
utypeu	TypeErroru	stepkindsu
ValueErroruSOURCEustepsuSINKureusearchuappend(uselfucmdukind((u*/opt/alt/python33/lib64/python3.3/pipes.pyuappendns ##uTemplate.appendcCst|�td�k	r'td��n|tkrItd|f��n|tkrdtd��n|jr�|jddtkr�td��n|ddkr�tjd	|�r�td
��n|ddkr�tjd|�r�td��n|jj	d||f�d
S(u2t.prepend(cmd, kind) adds a new step at the front.uu&Template.prepend: cmd must be a stringuTemplate.prepend: bad kind %ru+Template.prepend: SINK can only be appendediiu,Template.prepend: already begins with SOURCEufu\$IN\bu$Template.prepend: missing $IN in cmdu\$OUT\bu%Template.prepend: missing $OUT in cmdN(
utypeu	TypeErroru	stepkindsu
ValueErroruSINKustepsuSOURCEureusearchuinsert(uselfucmdukind((u*/opt/alt/python33/lib64/python3.3/pipes.pyuprepend~s ##uTemplate.prependcCsI|dkr|j|�S|dkr2|j|�Std|f��dS(u~t.open(file, rw) returns a pipe or file object open for
        reading or writing; the file is the other end of the pipeline.uruwu,Template.open: rw must be 'r' or 'w', not %rN(uopen_ruopen_wu
ValueError(uselfufileurw((u*/opt/alt/python33/lib64/python3.3/pipes.pyuopen�s

u
Template.opencCs^|jst|d�S|jddtkr<td��n|j|d�}tj|d�S(uit.open_r(file) and t.open_w(file) implement
        t.open(file, 'r') and t.open(file, 'w') respectively.uriu)Template.open_r: pipeline ends width SINKui����(ustepsuopenuSINKu
ValueErrorumakepipelineuosupopen(uselfufileucmd((u*/opt/alt/python33/lib64/python3.3/pipes.pyuopen_r�s	
uTemplate.open_rcCs^|jst|d�S|jddtkr<td��n|jd|�}tj|d�S(Nuwiiu,Template.open_w: pipeline begins with SOURCEu(ustepsuopenuSOURCEu
ValueErrorumakepipelineuosupopen(uselfufileucmd((u*/opt/alt/python33/lib64/python3.3/pipes.pyuopen_w�s	
uTemplate.open_wcCstj|j||��S(N(uosusystemumakepipeline(uselfuinfileuoutfile((u*/opt/alt/python33/lib64/python3.3/pipes.pyucopy�su
Template.copycCs9t||j|�}|jr5t|�d|}n|S(Nuset -x; (umakepipelineustepsu	debugginguprint(uselfuinfileuoutfileucmd((u*/opt/alt/python33/lib64/python3.3/pipes.pyumakepipeline�s
	

uTemplate.makepipelineN(u__name__u
__module__u__qualname__u__doc__u__init__u__repr__uresetucloneudebuguappenduprependuopenuopen_ruopen_wucopyumakepipeline(u
__locals__((u*/opt/alt/python33/lib64/python3.3/pipes.pyuTemplateRs

c	Cs�g}x-|D]%\}}|jd||dg�q
W|sX|jddddg�n|ddd�\}}|ddkr�|r�|jdddddg�n||dd<|ddd�\}}|ddkr|r|jddddg�n||dd<g}x�tdt|��D]�}||dd}||d}	|ddkss|	ddkr-tj�\}
}tj|
�|j|�|||dd<||d<q-q-Wx�|D]�}|\}
}}}|ddkrd	t|�d
|}n|ddkr9dt|
�d
|}n|ddkrf|
rf|d
t|
�}n|ddkr�|r�|dt|�}n||d<q�W|dd}xz|dd�D]h}|dd�\}}|ddkrd|kr	d|d}n|d|}q�|d|}q�W|r�d}x"|D]}|dt|�}q?Wdt|d�d}|d|d|}n|S(Nuucatu--iiiufiuOUT=u; uIN=u-u <u >u{ u; }u |
u
urm -fu utrap u; exitu 1 2 3 13 14 15i����i����i����i����(	uappenduinserturangeulenutempfileumkstempuosucloseuquote(uinfileustepsuoutfileulistucmdukindugarbageuiulkindurkindufdutempuitemuinfuoutfucmdlisturmcmdufileutrapcmd((u*/opt/alt/python33/lib64/python3.3/pipes.pyumakepipeline�s` 

%

umakepipeline(u__doc__ureuosutempfileushlexuquoteu__all__uFILEIN_FILEOUTu
STDIN_FILEOUTu
FILEIN_STDOUTuSTDIN_STDOUTuSOURCEuSINKu	stepkindsuTemplateumakepipeline(((u*/opt/alt/python33/lib64/python3.3/pipes.pyu<module>9s	c