python (3.11.7)

(root)/
lib/
python3.11/
__pycache__/
pipes.cpython-311.opt-1.pyc

e#dZddlZddlZddlZddlZddlmZejeddgZ	dZ
dZd	Zd
Z
dZdZe
eee
eegZGd
dZdZdS)aConversion 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()
N)quote)
)removeTemplateffz-fzf---z.-z-.cZeZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdS)rz'Class representing a pipeline template.c<d|_|dS)z-Template() returns a fresh pipeline template.rN)	debuggingresetselfs 9/BuggyBox/python/3.11.7/bootstrap/lib/python3.11/pipes.py__init__zTemplate.__init__Xs

cd|jdS)z t.__repr__() implements repr(t).z<Template instance, steps=>stepsrs r__repr__zTemplate.__repr__]s26***>>rcg|_dS)z<t.reset() restores a pipeline template to its initial state.Nrrs rr
zTemplate.resetas



rcbt}|jdd|_|j|_|S)zbt.clone() returns a new pipeline template with identical
        initial state as the current one.N)rrr)rts  rclonezTemplate.clonees,
JJ*QQQ-nrc||_dS)z(t.debug(flag) turns debugging on or off.N)r)rflags  rdebugzTemplate.debugms
rct|tstd|tvrt	d||t
krt	d|jr+|jddtkrt	d|ddkr$tj	d	|st	d
|ddkr$tj	d|st	d|j
||fd
S)z/t.append(cmd, kind) adds a new step at the end.z%Template.append: cmd must be a stringzTemplate.append: bad kind z-Template.append: SOURCE can only be prependedz'Template.append: already ends with SINKrf\$IN\bz#Template.append: missing $IN in cmd\$OUT\bz$Template.append: missing $OUT in cmdN)
isinstancestr	TypeError	stepkinds
ValueErrorSOURCErSINKresearchappendrcmdkinds   rr.zTemplate.appendqs#s##	ECDDDy  *ttEFFF6>>LMMM:	H$*R.+t33FGGG7c>>")Is";";>BCCC7c>>")J"<"<>CDDD
3+&&&&&rct|tstd|tvrt	d||t
krt	d|jr+|jddtkrt	d|ddkr$tj	d|st	d	|ddkr$tj	d
|st	d|j
d||fdS)
z2t.prepend(cmd, kind) adds a new step at the front.z&Template.prepend: cmd must be a stringzTemplate.prepend: bad kind z+Template.prepend: SINK can only be appendedrr!z,Template.prepend: already begins with SOURCEr"r#z$Template.prepend: missing $IN in cmdr$z%Template.prepend: missing $OUT in cmdN)r%r&r'r(r)r+rr*r,r-insertr/s   rprependzTemplate.prepends#s##	FDEEEy  *FGGG4<<JKKK:	M$*Q-*f44KLLL7c>>")Is";";>CDDD7c>>")J"<"<>DEEE
!c4[)))))rc|dkr||S|dkr||Std|)z~t.open(file, rw) returns a pipe or file object open for
        reading or writing; the file is the other end of the pipeline.rwz*Template.open: rw must be 'r' or 'w', not )open_ropen_wr))rfilerws   ropenz
Template.opensX99;;t$$$
99;;t$$$jB!""	"rc|jst|dS|jddtkrtd||d}tj|dS)zit.open_r(file) and t.open_w(file) implement
        t.open(file, 'r') and t.open(file, 'w') respectively.r6r r!z)Template.open_r: pipeline ends width SINK)rr<r+r)makepipelineospopenrr:r0s   rr8zTemplate.open_rshz	#c??":b>!$$HIIIb))xS!!!rc|jst|dS|jddtkrtd|d|}tj|dS)Nr7rr!z,Template.open_w: pipeline begins with SOURCEr>)rr<r*r)r?r@rArBs   rr9zTemplate.open_wsfz	#c??":a=v%%KLLLD))xS!!!rcRtj|||S)N)r@systemr?)rinfileoutfiles   rcopyz
Template.copys"y**67;;<<<rcht||j|}|jrt|d|z}|S)Nzset -x; )r?rrprint)rrFrGr0s    rr?zTemplate.makepipelines964:w77>	##JJJs"C
rN)__name__
__module____qualname____doc__rrr
rrr.r4r<r8r9rHr?rrrrUs11
???''' *** """""""""===rcVg}|D]\}}|d||dg|s|gd|ddd\}}|ddkr|s|dgd||dd<|ddd\}}|ddkr|s|gd||dd<g}tdt|D]}||dz
d}||d}	|ddks|	ddkrXt	j\}
}t
j|
|||x||dz
d<||d<|D]}|\}
}}}|ddkrd	t|zd
z|z}|ddkrdt|
zd
z|z}|ddkr|
r|d
zt|
z}|ddkr|r|dzt|z}||d<|dd}|ddD]8}|dd\}}|ddkrd|vrd|zdz}|dz|z}0|dz|z}9|rBd}|D]}|dzt|z}dt|dzzdz}|dz|zdz|z}|S)Nr>)r>catr	r>rr!rr"r zOUT=z; zIN=-z <z >z{ z; }z |

zrm -f ztrap z; exitz 1 2 3 13 14 15)	r.r3rangelentempfilemkstempr@closer)rFrrGlistr0r1garbageilkindrkindfdtempiteminfoutfcmdlistrmcmdr:trapcmds                   rr?r?sLD))	TRdB'((((+)))***q'!A#,KS$Aw#~~f~A,,,---DGAJr(1Q3-KS$Aw#~~g~)))***DHRLG
1c$ii
 
 ..QqS	!Q
8s??eAh#oo!)++JRHRLLLNN4   )--D1IbMDGAJ

!%c47c>>5;;&-3C7c>>%**$t+c1C7c>>c>*uSzz)C7c>>d>*uT{{*CQ1gajGQRR++1Q3id7b==d{{Sj5(&,GGns*GG:	.	.DCK%++-EEE%("23336GGD.7*T1E9Nr)rNr,r@rXwarningsshlexr_deprecatedrK__all__FILEIN_FILEOUT
STDIN_FILEOUT
FILEIN_STDOUTSTDIN_STDOUTr*r+r(rr?rOrr<module>rps88v
							Xg....,


]M<
T
	````````FBBBBBr