home *** CD-ROM | disk | FTP | other *** search
open in:
MacOS 8.1
|
Win98
|
DOS
view JSON data
|
view as text
This file was processed as: LaTeX Document
(document/latex).
You can browse this item here: tex
Confidence | Program | Detection | Match Type | Support
|
---|
100%
| dexvert
| LaTeX Document (document/latex)
| magic
| Supported |
1%
| dexvert
| Text File (text/txt)
| fallback
| Supported |
100%
| file
| JavaScript source
| default
| |
99%
| file
| LaTeX document text
| default
| |
98%
| file
| LaTeX document, ASCII text
| default
| |
100%
| checkBytes
| Printable ASCII
| default
| |
100%
| perlTextCheck
| Likely Text (Perl)
| default
| |
100%
| siegfried
| fmt/281 LaTeX (Subdocument)
| default
| |
100%
| detectItEasy
| Format: plain text[LF]
| default (weak)
|
|
hex view+--------+-------------------------+-------------------------+--------+--------+
|00000000| 5c 73 65 63 74 69 6f 6e | 7b 53 74 61 6e 64 61 72 |\section|{Standar|
|00000010| 64 20 4d 6f 64 75 6c 65 | 20 5c 73 65 63 74 63 6f |d Module| \sectco|
|00000020| 64 65 7b 72 65 78 65 63 | 7d 7d 0a 5c 73 74 6d 6f |de{rexec|}}.\stmo|
|00000030| 64 69 6e 64 65 78 7b 72 | 65 78 65 63 7d 0a 5c 72 |dindex{r|exec}.\r|
|00000040| 65 6e 65 77 63 6f 6d 6d | 61 6e 64 7b 5c 69 6e 64 |enewcomm|and{\ind|
|00000050| 65 78 73 75 62 69 74 65 | 6d 7d 7b 28 69 6e 20 6d |exsubite|m}{(in m|
|00000060| 6f 64 75 6c 65 20 72 65 | 78 65 63 29 7d 0a 0a 54 |odule re|xec)}..T|
|00000070| 68 69 73 20 6d 6f 64 75 | 6c 65 20 63 6f 6e 74 61 |his modu|le conta|
|00000080| 69 6e 73 20 74 68 65 20 | 5c 63 6f 64 65 7b 52 45 |ins the |\code{RE|
|00000090| 78 65 63 7d 20 63 6c 61 | 73 73 2c 20 77 68 69 63 |xec} cla|ss, whic|
|000000a0| 68 20 73 75 70 70 6f 72 | 74 73 0a 5c 63 6f 64 65 |h suppor|ts.\code|
|000000b0| 7b 72 5f 65 78 65 63 28 | 29 7d 2c 20 5c 63 6f 64 |{r_exec(|)}, \cod|
|000000c0| 65 7b 72 5f 65 76 61 6c | 28 29 7d 2c 20 5c 63 6f |e{r_eval|()}, \co|
|000000d0| 64 65 7b 72 5f 65 78 65 | 63 66 69 6c 65 28 29 7d |de{r_exe|cfile()}|
|000000e0| 2c 20 61 6e 64 0a 5c 63 | 6f 64 65 7b 72 5f 69 6d |, and.\c|ode{r_im|
|000000f0| 70 6f 72 74 28 29 7d 20 | 6d 65 74 68 6f 64 73 2c |port()} |methods,|
|00000100| 20 77 68 69 63 68 20 61 | 72 65 20 72 65 73 74 72 | which a|re restr|
|00000110| 69 63 74 65 64 20 76 65 | 72 73 69 6f 6e 73 20 6f |icted ve|rsions o|
|00000120| 66 20 74 68 65 20 73 74 | 61 6e 64 61 72 64 0a 50 |f the st|andard.P|
|00000130| 79 74 68 6f 6e 20 66 75 | 6e 63 74 69 6f 6e 73 20 |ython fu|nctions |
|00000140| 5c 63 6f 64 65 7b 65 78 | 65 63 28 29 7d 2c 20 5c |\code{ex|ec()}, \|
|00000150| 63 6f 64 65 7b 65 76 61 | 6c 28 29 7d 2c 20 5c 63 |code{eva|l()}, \c|
|00000160| 6f 64 65 7b 65 78 65 63 | 66 69 6c 65 28 29 7d 2c |ode{exec|file()},|
|00000170| 20 61 6e 64 0a 74 68 65 | 20 5c 63 6f 64 65 7b 69 | and.the| \code{i|
|00000180| 6d 70 6f 72 74 7d 20 73 | 74 61 74 65 6d 65 6e 74 |mport} s|tatement|
|00000190| 2e 0a 43 6f 64 65 20 65 | 78 65 63 75 74 65 64 20 |..Code e|xecuted |
|000001a0| 69 6e 20 74 68 69 73 20 | 72 65 73 74 72 69 63 74 |in this |restrict|
|000001b0| 65 64 20 65 6e 76 69 72 | 6f 6e 6d 65 6e 74 20 77 |ed envir|onment w|
|000001c0| 69 6c 6c 0a 6f 6e 6c 79 | 20 68 61 76 65 20 61 63 |ill.only| have ac|
|000001d0| 63 65 73 73 20 74 6f 20 | 6d 6f 64 75 6c 65 73 20 |cess to |modules |
|000001e0| 61 6e 64 20 66 75 6e 63 | 74 69 6f 6e 73 20 74 68 |and func|tions th|
|000001f0| 61 74 20 61 72 65 20 64 | 65 65 6d 65 64 20 73 61 |at are d|eemed sa|
|00000200| 66 65 3b 20 79 6f 75 0a | 63 61 6e 20 73 75 62 63 |fe; you.|can subc|
|00000210| 6c 61 73 73 20 5c 63 6f | 64 65 7b 52 45 78 65 63 |lass \co|de{RExec|
|00000220| 7d 20 74 6f 20 61 64 64 | 20 6f 72 20 72 65 6d 6f |} to add| or remo|
|00000230| 76 65 20 63 61 70 61 62 | 69 6c 69 74 69 65 73 20 |ve capab|ilities |
|00000240| 61 73 20 64 65 73 69 72 | 65 64 2e 0a 0a 5c 65 6d |as desir|ed...\em|
|00000250| 70 68 7b 4e 6f 74 65 3a | 7d 20 54 68 65 20 5c 63 |ph{Note:|} The \c|
|00000260| 6f 64 65 7b 52 45 78 65 | 63 7d 20 63 6c 61 73 73 |ode{RExe|c} class|
|00000270| 20 63 61 6e 20 70 72 65 | 76 65 6e 74 20 63 6f 64 | can pre|vent cod|
|00000280| 65 20 66 72 6f 6d 20 70 | 65 72 66 6f 72 6d 69 6e |e from p|erformin|
|00000290| 67 0a 75 6e 73 61 66 65 | 20 6f 70 65 72 61 74 69 |g.unsafe| operati|
|000002a0| 6f 6e 73 20 6c 69 6b 65 | 20 72 65 61 64 69 6e 67 |ons like| reading|
|000002b0| 20 6f 72 20 77 72 69 74 | 69 6e 67 20 64 69 73 6b | or writ|ing disk|
|000002c0| 20 66 69 6c 65 73 2c 20 | 6f 72 20 75 73 69 6e 67 | files, |or using|
|000002d0| 20 54 43 50 2f 49 50 0a | 73 6f 63 6b 65 74 73 2e | TCP/IP.|sockets.|
|000002e0| 20 20 48 6f 77 65 76 65 | 72 2c 20 69 74 20 64 6f | Howeve|r, it do|
|000002f0| 65 73 20 6e 6f 74 20 70 | 72 6f 74 65 63 74 20 61 |es not p|rotect a|
|00000300| 67 61 69 6e 73 74 20 63 | 6f 64 65 20 75 73 69 6e |gainst c|ode usin|
|00000310| 67 20 65 78 74 72 65 6d | 65 6c 79 0a 6c 61 72 67 |g extrem|ely.larg|
|00000320| 65 20 61 6d 6f 75 6e 74 | 73 20 6f 66 20 6d 65 6d |e amount|s of mem|
|00000330| 6f 72 79 20 6f 72 20 43 | 50 55 20 74 69 6d 65 2e |ory or C|PU time.|
|00000340| 20 20 0a 0a 5c 62 65 67 | 69 6e 7b 66 75 6e 63 64 | ..\beg|in{funcd|
|00000350| 65 73 63 7d 7b 52 45 78 | 65 63 7d 7b 5c 6f 70 74 |esc}{REx|ec}{\opt|
|00000360| 69 6f 6e 61 6c 7b 68 6f | 6f 6b 73 5c 6f 70 74 69 |ional{ho|oks\opti|
|00000370| 6f 6e 61 6c 7b 5c 2c 20 | 76 65 72 62 6f 73 65 7d |onal{\, |verbose}|
|00000380| 7d 7d 0a 52 65 74 75 72 | 6e 73 20 61 6e 20 69 6e |}}.Retur|ns an in|
|00000390| 73 74 61 6e 63 65 20 6f | 66 20 74 68 65 20 5c 63 |stance o|f the \c|
|000003a0| 6f 64 65 7b 52 45 78 65 | 63 7d 20 63 6c 61 73 73 |ode{RExe|c} class|
|000003b0| 2e 20 20 0a 0a 5c 76 61 | 72 7b 68 6f 6f 6b 73 7d |. ..\va|r{hooks}|
|000003c0| 20 69 73 20 61 6e 20 69 | 6e 73 74 61 6e 63 65 20 | is an i|nstance |
|000003d0| 6f 66 20 74 68 65 20 5c | 63 6f 64 65 7b 52 48 6f |of the \|code{RHo|
|000003e0| 6f 6b 73 7d 20 63 6c 61 | 73 73 20 6f 72 20 61 20 |oks} cla|ss or a |
|000003f0| 73 75 62 63 6c 61 73 73 | 20 6f 66 20 69 74 2e 0a |subclass| of it..|
|00000400| 49 66 20 69 74 20 69 73 | 20 6f 6d 69 74 74 65 64 |If it is| omitted|
|00000410| 20 6f 72 20 5c 63 6f 64 | 65 7b 4e 6f 6e 65 7d 2c | or \cod|e{None},|
|00000420| 20 74 68 65 20 64 65 66 | 61 75 6c 74 20 5c 63 6f | the def|ault \co|
|00000430| 64 65 7b 52 48 6f 6f 6b | 73 7d 20 63 6c 61 73 73 |de{RHook|s} class|
|00000440| 20 69 73 0a 69 6e 73 74 | 61 6e 74 69 61 74 65 64 | is.inst|antiated|
|00000450| 2e 0a 57 68 65 6e 65 76 | 65 72 20 74 68 65 20 52 |..Whenev|er the R|
|00000460| 45 78 65 63 20 6d 6f 64 | 75 6c 65 20 73 65 61 72 |Exec mod|ule sear|
|00000470| 63 68 65 73 20 66 6f 72 | 20 61 20 6d 6f 64 75 6c |ches for| a modul|
|00000480| 65 20 28 65 76 65 6e 20 | 61 20 62 75 69 6c 74 2d |e (even |a built-|
|00000490| 69 6e 20 6f 6e 65 29 0a | 6f 72 20 72 65 61 64 73 |in one).|or reads|
|000004a0| 20 61 20 6d 6f 64 75 6c | 65 27 73 20 63 6f 64 65 | a modul|e's code|
|000004b0| 2c 20 69 74 20 64 6f 65 | 73 6e 27 74 20 61 63 74 |, it doe|sn't act|
|000004c0| 75 61 6c 6c 79 20 67 6f | 20 6f 75 74 20 74 6f 20 |ually go| out to |
|000004d0| 74 68 65 20 66 69 6c 65 | 0a 73 79 73 74 65 6d 20 |the file|.system |
|000004e0| 69 74 73 65 6c 66 2e 20 | 20 52 61 74 68 65 72 2c |itself. | Rather,|
|000004f0| 20 69 74 20 63 61 6c 6c | 73 20 6d 65 74 68 6f 64 | it call|s method|
|00000500| 73 20 6f 66 20 61 6e 20 | 52 48 6f 6f 6b 73 20 69 |s of an |RHooks i|
|00000510| 6e 73 74 61 6e 63 65 20 | 74 68 61 74 0a 77 61 73 |nstance |that.was|
|00000520| 20 70 61 73 73 65 64 20 | 74 6f 20 6f 72 20 63 72 | passed |to or cr|
|00000530| 65 61 74 65 64 20 62 79 | 20 69 74 73 20 63 6f 6e |eated by| its con|
|00000540| 73 74 72 75 63 74 6f 72 | 2e 20 20 28 41 63 74 75 |structor|. (Actu|
|00000550| 61 6c 6c 79 2c 20 74 68 | 65 20 52 45 78 65 63 0a |ally, th|e RExec.|
|00000560| 6f 62 6a 65 63 74 20 64 | 6f 65 73 6e 27 74 20 6d |object d|oesn't m|
|00000570| 61 6b 65 20 74 68 65 73 | 65 20 63 61 6c 6c 73 2d |ake thes|e calls-|
|00000580| 2d 2d 74 68 65 79 20 61 | 72 65 20 6d 61 64 65 20 |--they a|re made |
|00000590| 62 79 20 61 20 6d 6f 64 | 75 6c 65 20 6c 6f 61 64 |by a mod|ule load|
|000005a0| 65 72 0a 6f 62 6a 65 63 | 74 20 74 68 61 74 27 73 |er.objec|t that's|
|000005b0| 20 70 61 72 74 20 6f 66 | 20 74 68 65 20 52 45 78 | part of| the REx|
|000005c0| 65 63 20 6f 62 6a 65 63 | 74 2e 20 20 54 68 69 73 |ec objec|t. This|
|000005d0| 20 61 6c 6c 6f 77 73 20 | 61 6e 6f 74 68 65 72 20 | allows |another |
|000005e0| 6c 65 76 65 6c 20 6f 66 | 0a 66 6c 65 78 69 62 69 |level of|.flexibi|
|000005f0| 6c 69 74 79 2c 20 65 2e | 67 2e 20 75 73 69 6e 67 |lity, e.|g. using|
|00000600| 20 70 61 63 6b 61 67 65 | 73 2e 29 0a 0a 42 79 20 | package|s.)..By |
|00000610| 70 72 6f 76 69 64 69 6e | 67 20 61 6e 20 61 6c 74 |providin|g an alt|
|00000620| 65 72 6e 61 74 65 20 52 | 48 6f 6f 6b 73 20 6f 62 |ernate R|Hooks ob|
|00000630| 6a 65 63 74 2c 20 77 65 | 20 63 61 6e 20 63 6f 6e |ject, we| can con|
|00000640| 74 72 6f 6c 20 74 68 65 | 0a 66 69 6c 65 20 73 79 |trol the|.file sy|
|00000650| 73 74 65 6d 20 61 63 63 | 65 73 73 65 73 20 6d 61 |stem acc|esses ma|
|00000660| 64 65 20 74 6f 20 69 6d | 70 6f 72 74 20 61 20 6d |de to im|port a m|
|00000670| 6f 64 75 6c 65 2c 20 77 | 69 74 68 6f 75 74 20 63 |odule, w|ithout c|
|00000680| 68 61 6e 67 69 6e 67 20 | 74 68 65 0a 61 63 74 75 |hanging |the.actu|
|00000690| 61 6c 20 61 6c 67 6f 72 | 69 74 68 6d 20 74 68 61 |al algor|ithm tha|
|000006a0| 74 20 63 6f 6e 74 72 6f | 6c 73 20 74 68 65 20 6f |t contro|ls the o|
|000006b0| 72 64 65 72 20 69 6e 20 | 77 68 69 63 68 20 74 68 |rder in |which th|
|000006c0| 6f 73 65 20 61 63 63 65 | 73 73 65 73 20 61 72 65 |ose acce|sses are|
|000006d0| 0a 6d 61 64 65 2e 20 20 | 46 6f 72 20 69 6e 73 74 |.made. |For inst|
|000006e0| 61 6e 63 65 2c 20 77 65 | 20 63 6f 75 6c 64 20 73 |ance, we| could s|
|000006f0| 75 62 73 74 69 74 75 74 | 65 20 61 6e 20 52 48 6f |ubstitut|e an RHo|
|00000700| 6f 6b 73 20 6f 62 6a 65 | 63 74 20 74 68 61 74 20 |oks obje|ct that |
|00000710| 70 61 73 73 65 73 0a 61 | 6c 6c 20 66 69 6c 65 73 |passes.a|ll files|
|00000720| 79 73 74 65 6d 20 72 65 | 71 75 65 73 74 73 20 74 |ystem re|quests t|
|00000730| 6f 20 61 20 66 69 6c 65 | 20 73 65 72 76 65 72 20 |o a file| server |
|00000740| 65 6c 73 65 77 68 65 72 | 65 2c 20 76 69 61 20 73 |elsewher|e, via s|
|00000750| 6f 6d 65 20 52 50 43 0a | 6d 65 63 68 61 6e 69 73 |ome RPC.|mechanis|
|00000760| 6d 20 73 75 63 68 20 61 | 73 20 49 4c 55 2e 20 20 |m such a|s ILU. |
|00000770| 47 72 61 69 6c 27 73 20 | 61 70 70 6c 65 74 20 6c |Grail's |applet l|
|00000780| 6f 61 64 65 72 20 75 73 | 65 73 20 74 68 69 73 20 |oader us|es this |
|00000790| 74 6f 20 73 75 70 70 6f | 72 74 0a 69 6d 70 6f 72 |to suppo|rt.impor|
|000007a0| 74 69 6e 67 20 61 70 70 | 6c 65 74 73 20 66 72 6f |ting app|lets fro|
|000007b0| 6d 20 61 20 55 52 4c 20 | 66 6f 72 20 61 20 64 69 |m a URL |for a di|
|000007c0| 72 65 63 74 6f 72 79 2e | 0a 0a 49 66 20 5c 76 61 |rectory.|..If \va|
|000007d0| 72 7b 76 65 72 62 6f 73 | 65 7d 20 69 73 20 74 72 |r{verbos|e} is tr|
|000007e0| 75 65 2c 20 61 64 64 69 | 74 69 6f 6e 61 6c 20 64 |ue, addi|tional d|
|000007f0| 65 62 75 67 67 69 6e 67 | 20 6f 75 74 70 75 74 20 |ebugging| output |
|00000800| 6d 61 79 20 62 65 20 73 | 65 6e 74 20 74 6f 0a 73 |may be s|ent to.s|
|00000810| 74 61 6e 64 61 72 64 20 | 6f 75 74 70 75 74 2e 0a |tandard |output..|
|00000820| 5c 65 6e 64 7b 66 75 6e | 63 64 65 73 63 7d 0a 0a |\end{fun|cdesc}..|
|00000830| 54 68 65 20 52 45 78 65 | 63 20 63 6c 61 73 73 20 |The RExe|c class |
|00000840| 68 61 73 20 74 68 65 20 | 66 6f 6c 6c 6f 77 69 6e |has the |followin|
|00000850| 67 20 63 6c 61 73 73 20 | 61 74 74 72 69 62 75 74 |g class |attribut|
|00000860| 65 73 2c 20 77 68 69 63 | 68 20 61 72 65 20 75 73 |es, whic|h are us|
|00000870| 65 64 20 62 79 20 74 68 | 65 0a 5c 63 6f 64 65 7b |ed by th|e.\code{|
|00000880| 5f 5f 69 6e 69 74 5f 5f | 7d 20 6d 65 74 68 6f 64 |__init__|} method|
|00000890| 2e 20 20 43 68 61 6e 67 | 69 6e 67 20 74 68 65 6d |. Chang|ing them|
|000008a0| 20 6f 6e 20 61 6e 20 65 | 78 69 73 74 69 6e 67 20 | on an e|xisting |
|000008b0| 69 6e 73 74 61 6e 63 65 | 20 77 6f 6e 27 74 0a 68 |instance| won't.h|
|000008c0| 61 76 65 20 61 6e 79 20 | 65 66 66 65 63 74 3b 20 |ave any |effect; |
|000008d0| 69 6e 73 74 65 61 64 2c | 20 63 72 65 61 74 65 20 |instead,| create |
|000008e0| 61 20 73 75 62 63 6c 61 | 73 73 20 6f 66 20 5c 63 |a subcla|ss of \c|
|000008f0| 6f 64 65 7b 52 45 78 65 | 63 7d 20 61 6e 64 20 61 |ode{RExe|c} and a|
|00000900| 73 73 69 67 6e 0a 74 68 | 65 6d 20 6e 65 77 20 76 |ssign.th|em new v|
|00000910| 61 6c 75 65 73 20 69 6e | 20 74 68 65 20 63 6c 61 |alues in| the cla|
|00000920| 73 73 20 64 65 66 69 6e | 69 74 69 6f 6e 2e 20 20 |ss defin|ition. |
|00000930| 49 6e 73 74 61 6e 63 65 | 73 20 6f 66 20 74 68 65 |Instance|s of the|
|00000940| 20 6e 65 77 20 63 6c 61 | 73 73 0a 77 69 6c 6c 20 | new cla|ss.will |
|00000950| 74 68 65 6e 20 75 73 65 | 20 74 68 6f 73 65 20 6e |then use| those n|
|00000960| 65 77 20 76 61 6c 75 65 | 73 2e 20 20 41 6c 6c 20 |ew value|s. All |
|00000970| 74 68 65 73 65 20 61 74 | 74 72 69 62 75 74 65 73 |these at|tributes|
|00000980| 20 61 72 65 20 74 75 70 | 6c 65 73 20 6f 66 0a 73 | are tup|les of.s|
|00000990| 74 72 69 6e 67 73 2e 0a | 0a 5c 72 65 6e 65 77 63 |trings..|.\renewc|
|000009a0| 6f 6d 6d 61 6e 64 7b 5c | 69 6e 64 65 78 73 75 62 |ommand{\|indexsub|
|000009b0| 69 74 65 6d 7d 7b 28 52 | 45 78 65 63 20 6f 62 6a |item}{(R|Exec obj|
|000009c0| 65 63 74 20 61 74 74 72 | 69 62 75 74 65 29 7d 0a |ect attr|ibute)}.|
|000009d0| 5c 62 65 67 69 6e 7b 64 | 61 74 61 64 65 73 63 7d |\begin{d|atadesc}|
|000009e0| 7b 6e 6f 6b 5f 62 75 69 | 6c 74 69 6e 5f 6e 61 6d |{nok_bui|ltin_nam|
|000009f0| 65 73 7d 0a 43 6f 6e 74 | 61 69 6e 73 20 74 68 65 |es}.Cont|ains the|
|00000a00| 20 6e 61 6d 65 73 20 6f | 66 20 62 75 69 6c 74 2d | names o|f built-|
|00000a10| 69 6e 20 66 75 6e 63 74 | 69 6f 6e 73 20 77 68 69 |in funct|ions whi|
|00000a20| 63 68 20 77 69 6c 6c 20 | 5c 65 6d 70 68 7b 6e 6f |ch will |\emph{no|
|00000a30| 74 7d 20 62 65 0a 61 76 | 61 69 6c 61 62 6c 65 20 |t} be.av|ailable |
|00000a40| 74 6f 20 70 72 6f 67 72 | 61 6d 73 20 72 75 6e 6e |to progr|ams runn|
|00000a50| 69 6e 67 20 69 6e 20 74 | 68 65 20 72 65 73 74 72 |ing in t|he restr|
|00000a60| 69 63 74 65 64 20 65 6e | 76 69 72 6f 6e 6d 65 6e |icted en|vironmen|
|00000a70| 74 2e 20 20 54 68 65 0a | 76 61 6c 75 65 20 66 6f |t. The.|value fo|
|00000a80| 72 20 5c 63 6f 64 65 7b | 52 45 78 65 63 7d 20 69 |r \code{|RExec} i|
|00000a90| 73 20 5c 63 6f 64 65 7b | 28 27 6f 70 65 6e 27 2c |s \code{|('open',|
|00000aa0| 7d 20 5c 63 6f 64 65 7b | 27 72 65 6c 6f 61 64 27 |} \code{|'reload'|
|00000ab0| 2c 7d 0a 5c 63 6f 64 65 | 7b 27 5f 5f 69 6d 70 6f |,}.\code|{'__impo|
|00000ac0| 72 74 5f 5f 27 29 7d 2e | 20 20 28 54 68 69 73 20 |rt__')}.| (This |
|00000ad0| 67 69 76 65 73 20 74 68 | 65 20 65 78 63 65 70 74 |gives th|e except|
|00000ae0| 69 6f 6e 73 2c 20 62 65 | 63 61 75 73 65 20 62 79 |ions, be|cause by|
|00000af0| 20 66 61 72 20 74 68 65 | 0a 6d 61 6a 6f 72 69 74 | far the|.majorit|
|00000b00| 79 20 6f 66 20 62 75 69 | 6c 74 2d 69 6e 20 66 75 |y of bui|lt-in fu|
|00000b10| 6e 63 74 69 6f 6e 73 20 | 61 72 65 20 68 61 72 6d |nctions |are harm|
|00000b20| 6c 65 73 73 2e 20 20 41 | 20 73 75 62 63 6c 61 73 |less. A| subclas|
|00000b30| 73 20 74 68 61 74 20 77 | 61 6e 74 73 20 74 6f 0a |s that w|ants to.|
|00000b40| 6f 76 65 72 72 69 64 65 | 20 74 68 69 73 20 76 61 |override| this va|
|00000b50| 72 69 61 62 6c 65 20 73 | 68 6f 75 6c 64 20 70 72 |riable s|hould pr|
|00000b60| 6f 62 61 62 6c 79 20 73 | 74 61 72 74 20 77 69 74 |obably s|tart wit|
|00000b70| 68 20 74 68 65 20 76 61 | 6c 75 65 20 66 72 6f 6d |h the va|lue from|
|00000b80| 20 74 68 65 0a 62 61 73 | 65 20 63 6c 61 73 73 20 | the.bas|e class |
|00000b90| 61 6e 64 20 63 6f 6e 63 | 61 74 65 6e 61 74 65 20 |and conc|atenate |
|00000ba0| 61 64 64 69 74 69 6f 6e | 61 6c 20 66 6f 72 62 69 |addition|al forbi|
|00000bb0| 64 64 65 6e 20 66 75 6e | 63 74 69 6f 6e 73 20 2d |dden fun|ctions -|
|00000bc0| 2d 2d 20 77 68 65 6e 20 | 6e 65 77 0a 64 61 6e 67 |-- when |new.dang|
|00000bd0| 65 72 6f 75 73 20 62 75 | 69 6c 74 2d 69 6e 20 66 |erous bu|ilt-in f|
|00000be0| 75 6e 63 74 69 6f 6e 73 | 20 61 72 65 20 61 64 64 |unctions| are add|
|00000bf0| 65 64 20 74 6f 20 50 79 | 74 68 6f 6e 2c 20 74 68 |ed to Py|thon, th|
|00000c00| 65 79 20 77 69 6c 6c 20 | 61 6c 73 6f 20 62 65 0a |ey will |also be.|
|00000c10| 61 64 64 65 64 20 74 6f | 20 74 68 69 73 20 6d 6f |added to| this mo|
|00000c20| 64 75 6c 65 2e 29 0a 5c | 65 6e 64 7b 64 61 74 61 |dule.).\|end{data|
|00000c30| 64 65 73 63 7d 0a 0a 5c | 62 65 67 69 6e 7b 64 61 |desc}..\|begin{da|
|00000c40| 74 61 64 65 73 63 7d 7b | 6f 6b 5f 62 75 69 6c 74 |tadesc}{|ok_built|
|00000c50| 69 6e 5f 6d 6f 64 75 6c | 65 73 7d 0a 43 6f 6e 74 |in_modul|es}.Cont|
|00000c60| 61 69 6e 73 20 74 68 65 | 20 6e 61 6d 65 73 20 6f |ains the| names o|
|00000c70| 66 20 62 75 69 6c 74 2d | 69 6e 20 6d 6f 64 75 6c |f built-|in modul|
|00000c80| 65 73 20 77 68 69 63 68 | 20 63 61 6e 20 62 65 20 |es which| can be |
|00000c90| 73 61 66 65 6c 79 20 69 | 6d 70 6f 72 74 65 64 2e |safely i|mported.|
|00000ca0| 0a 54 68 65 20 76 61 6c | 75 65 20 66 6f 72 20 5c |.The val|ue for \|
|00000cb0| 63 6f 64 65 7b 52 45 78 | 65 63 7d 20 69 73 20 5c |code{REx|ec} is \|
|00000cc0| 63 6f 64 65 7b 28 27 61 | 75 64 69 6f 6f 70 27 2c |code{('a|udioop',|
|00000cd0| 7d 20 5c 63 6f 64 65 7b | 27 61 72 72 61 79 27 2c |} \code{|'array',|
|00000ce0| 7d 0a 5c 63 6f 64 65 7b | 27 62 69 6e 61 73 63 69 |}.\code{|'binasci|
|00000cf0| 69 27 2c 7d 20 5c 63 6f | 64 65 7b 27 63 6d 61 74 |i',} \co|de{'cmat|
|00000d00| 68 27 2c 7d 20 5c 63 6f | 64 65 7b 27 65 72 72 6e |h',} \co|de{'errn|
|00000d10| 6f 27 2c 7d 20 5c 63 6f | 64 65 7b 27 69 6d 61 67 |o',} \co|de{'imag|
|00000d20| 65 6f 70 27 2c 7d 0a 5c | 63 6f 64 65 7b 27 6d 61 |eop',}.\|code{'ma|
|00000d30| 72 73 68 61 6c 27 2c 7d | 20 5c 63 6f 64 65 7b 27 |rshal',}| \code{'|
|00000d40| 6d 61 74 68 27 2c 7d 20 | 5c 63 6f 64 65 7b 27 6d |math',} |\code{'m|
|00000d50| 64 35 27 2c 7d 20 5c 63 | 6f 64 65 7b 27 6f 70 65 |d5',} \c|ode{'ope|
|00000d60| 72 61 74 6f 72 27 2c 7d | 0a 5c 63 6f 64 65 7b 27 |rator',}|.\code{'|
|00000d70| 70 61 72 73 65 72 27 2c | 7d 20 5c 63 6f 64 65 7b |parser',|} \code{|
|00000d80| 27 72 65 67 65 78 27 2c | 7d 20 5c 63 6f 64 65 7b |'regex',|} \code{|
|00000d90| 27 72 6f 74 6f 72 27 2c | 7d 20 5c 63 6f 64 65 7b |'rotor',|} \code{|
|00000da0| 27 73 65 6c 65 63 74 27 | 2c 7d 0a 5c 63 6f 64 65 |'select'|,}.\code|
|00000db0| 7b 27 73 74 72 6f 70 27 | 2c 7d 20 5c 63 6f 64 65 |{'strop'|,} \code|
|00000dc0| 7b 27 73 74 72 75 63 74 | 27 2c 7d 20 5c 63 6f 64 |{'struct|',} \cod|
|00000dd0| 65 7b 27 74 69 6d 65 27 | 29 7d 2e 20 20 41 20 73 |e{'time'|)}. A s|
|00000de0| 69 6d 69 6c 61 72 20 72 | 65 6d 61 72 6b 0a 61 62 |imilar r|emark.ab|
|00000df0| 6f 75 74 20 6f 76 65 72 | 72 69 64 69 6e 67 20 74 |out over|riding t|
|00000e00| 68 69 73 20 76 61 72 69 | 61 62 6c 65 20 61 70 70 |his vari|able app|
|00000e10| 6c 69 65 73 20 2d 2d 2d | 20 75 73 65 20 74 68 65 |lies ---| use the|
|00000e20| 20 76 61 6c 75 65 20 66 | 72 6f 6d 20 74 68 65 20 | value f|rom the |
|00000e30| 62 61 73 65 0a 63 6c 61 | 73 73 20 61 73 20 61 20 |base.cla|ss as a |
|00000e40| 73 74 61 72 74 69 6e 67 | 20 70 6f 69 6e 74 2e 0a |starting| point..|
|00000e50| 5c 65 6e 64 7b 64 61 74 | 61 64 65 73 63 7d 0a 0a |\end{dat|adesc}..|
|00000e60| 5c 62 65 67 69 6e 7b 64 | 61 74 61 64 65 73 63 7d |\begin{d|atadesc}|
|00000e70| 7b 6f 6b 5f 70 61 74 68 | 7d 0a 43 6f 6e 74 61 69 |{ok_path|}.Contai|
|00000e80| 6e 73 20 74 68 65 20 64 | 69 72 65 63 74 6f 72 69 |ns the d|irectori|
|00000e90| 65 73 20 77 68 69 63 68 | 20 77 69 6c 6c 20 62 65 |es which| will be|
|00000ea0| 20 73 65 61 72 63 68 65 | 64 20 77 68 65 6e 20 61 | searche|d when a|
|00000eb0| 6e 20 5c 63 6f 64 65 7b | 69 6d 70 6f 72 74 7d 0a |n \code{|import}.|
|00000ec0| 69 73 20 70 65 72 66 6f | 72 6d 65 64 20 69 6e 20 |is perfo|rmed in |
|00000ed0| 74 68 65 20 72 65 73 74 | 72 69 63 74 65 64 20 65 |the rest|ricted e|
|00000ee0| 6e 76 69 72 6f 6e 6d 65 | 6e 74 2e 20 20 0a 54 68 |nvironme|nt. .Th|
|00000ef0| 65 20 76 61 6c 75 65 20 | 66 6f 72 20 5c 63 6f 64 |e value |for \cod|
|00000f00| 65 7b 52 45 78 65 63 7d | 20 69 73 20 74 68 65 20 |e{RExec}| is the |
|00000f10| 73 61 6d 65 20 61 73 20 | 5c 63 6f 64 65 7b 73 79 |same as |\code{sy|
|00000f20| 73 2e 70 61 74 68 7d 20 | 28 61 74 20 74 68 65 20 |s.path} |(at the |
|00000f30| 74 69 6d 65 0a 74 68 65 | 20 6d 6f 64 75 6c 65 20 |time.the| module |
|00000f40| 69 73 20 6c 6f 61 64 65 | 64 29 20 66 6f 72 20 75 |is loade|d) for u|
|00000f50| 6e 72 65 73 74 72 69 63 | 74 65 64 20 63 6f 64 65 |nrestric|ted code|
|00000f60| 2e 0a 5c 65 6e 64 7b 64 | 61 74 61 64 65 73 63 7d |..\end{d|atadesc}|
|00000f70| 0a 0a 5c 62 65 67 69 6e | 7b 64 61 74 61 64 65 73 |..\begin|{datades|
|00000f80| 63 7d 7b 6f 6b 5f 70 6f | 73 69 78 5f 6e 61 6d 65 |c}{ok_po|six_name|
|00000f90| 73 7d 0a 25 20 53 68 6f | 75 6c 64 20 74 68 69 73 |s}.% Sho|uld this|
|00000fa0| 20 62 65 20 63 61 6c 6c | 65 64 20 6f 6b 5f 6f 73 | be call|ed ok_os|
|00000fb0| 5f 6e 61 6d 65 73 3f 0a | 43 6f 6e 74 61 69 6e 73 |_names?.|Contains|
|00000fc0| 20 74 68 65 20 6e 61 6d | 65 73 20 6f 66 20 74 68 | the nam|es of th|
|00000fd0| 65 20 66 75 6e 63 74 69 | 6f 6e 73 20 69 6e 20 74 |e functi|ons in t|
|00000fe0| 68 65 20 5c 63 6f 64 65 | 7b 6f 73 7d 20 6d 6f 64 |he \code|{os} mod|
|00000ff0| 75 6c 65 20 77 68 69 63 | 68 20 77 69 6c 6c 20 62 |ule whic|h will b|
|00001000| 65 0a 61 76 61 69 6c 61 | 62 6c 65 20 74 6f 20 70 |e.availa|ble to p|
|00001010| 72 6f 67 72 61 6d 73 20 | 72 75 6e 6e 69 6e 67 20 |rograms |running |
|00001020| 69 6e 20 74 68 65 20 72 | 65 73 74 72 69 63 74 65 |in the r|estricte|
|00001030| 64 20 65 6e 76 69 72 6f | 6e 6d 65 6e 74 2e 20 20 |d enviro|nment. |
|00001040| 54 68 65 0a 76 61 6c 75 | 65 20 66 6f 72 20 5c 63 |The.valu|e for \c|
|00001050| 6f 64 65 7b 52 45 78 65 | 63 7d 20 69 73 20 5c 63 |ode{RExe|c} is \c|
|00001060| 6f 64 65 7b 28 27 65 72 | 72 6f 72 27 2c 7d 20 5c |ode{('er|ror',} \|
|00001070| 63 6f 64 65 7b 27 66 73 | 74 61 74 27 2c 7d 0a 5c |code{'fs|tat',}.\|
|00001080| 63 6f 64 65 7b 27 6c 69 | 73 74 64 69 72 27 2c 7d |code{'li|stdir',}|
|00001090| 20 5c 63 6f 64 65 7b 27 | 6c 73 74 61 74 27 2c 7d | \code{'|lstat',}|
|000010a0| 20 5c 63 6f 64 65 7b 27 | 72 65 61 64 6c 69 6e 6b | \code{'|readlink|
|000010b0| 27 2c 7d 20 5c 63 6f 64 | 65 7b 27 73 74 61 74 27 |',} \cod|e{'stat'|
|000010c0| 2c 7d 0a 5c 63 6f 64 65 | 7b 27 74 69 6d 65 73 27 |,}.\code|{'times'|
|000010d0| 2c 7d 20 5c 63 6f 64 65 | 7b 27 75 6e 61 6d 65 27 |,} \code|{'uname'|
|000010e0| 2c 7d 20 5c 63 6f 64 65 | 7b 27 67 65 74 70 69 64 |,} \code|{'getpid|
|000010f0| 27 2c 7d 20 5c 63 6f 64 | 65 7b 27 67 65 74 70 70 |',} \cod|e{'getpp|
|00001100| 69 64 27 2c 7d 0a 5c 63 | 6f 64 65 7b 27 67 65 74 |id',}.\c|ode{'get|
|00001110| 63 77 64 27 2c 7d 20 5c | 63 6f 64 65 7b 27 67 65 |cwd',} \|code{'ge|
|00001120| 74 75 69 64 27 2c 7d 20 | 5c 63 6f 64 65 7b 27 67 |tuid',} |\code{'g|
|00001130| 65 74 67 69 64 27 2c 7d | 20 5c 63 6f 64 65 7b 27 |etgid',}| \code{'|
|00001140| 67 65 74 65 75 69 64 27 | 2c 7d 0a 5c 63 6f 64 65 |geteuid'|,}.\code|
|00001150| 7b 27 67 65 74 65 67 69 | 64 27 29 7d 2e 0a 5c 65 |{'getegi|d')}..\e|
|00001160| 6e 64 7b 64 61 74 61 64 | 65 73 63 7d 0a 0a 5c 62 |nd{datad|esc}..\b|
|00001170| 65 67 69 6e 7b 64 61 74 | 61 64 65 73 63 7d 7b 6f |egin{dat|adesc}{o|
|00001180| 6b 5f 73 79 73 5f 6e 61 | 6d 65 73 7d 0a 43 6f 6e |k_sys_na|mes}.Con|
|00001190| 74 61 69 6e 73 20 74 68 | 65 20 6e 61 6d 65 73 20 |tains th|e names |
|000011a0| 6f 66 20 74 68 65 20 66 | 75 6e 63 74 69 6f 6e 73 |of the f|unctions|
|000011b0| 20 61 6e 64 20 76 61 72 | 69 61 62 6c 65 73 20 69 | and var|iables i|
|000011c0| 6e 20 74 68 65 20 5c 63 | 6f 64 65 7b 73 79 73 7d |n the \c|ode{sys}|
|000011d0| 0a 6d 6f 64 75 6c 65 20 | 77 68 69 63 68 20 77 69 |.module |which wi|
|000011e0| 6c 6c 20 62 65 20 61 76 | 61 69 6c 61 62 6c 65 20 |ll be av|ailable |
|000011f0| 74 6f 20 70 72 6f 67 72 | 61 6d 73 20 72 75 6e 6e |to progr|ams runn|
|00001200| 69 6e 67 20 69 6e 20 74 | 68 65 20 72 65 73 74 72 |ing in t|he restr|
|00001210| 69 63 74 65 64 0a 65 6e | 76 69 72 6f 6e 6d 65 6e |icted.en|vironmen|
|00001220| 74 2e 20 20 54 68 65 20 | 76 61 6c 75 65 20 66 6f |t. The |value fo|
|00001230| 72 20 5c 63 6f 64 65 7b | 52 45 78 65 63 7d 20 69 |r \code{|RExec} i|
|00001240| 73 20 5c 63 6f 64 65 7b | 28 27 70 73 31 27 2c 7d |s \code{|('ps1',}|
|00001250| 0a 5c 63 6f 64 65 7b 27 | 70 73 32 27 2c 7d 20 5c |.\code{'|ps2',} \|
|00001260| 63 6f 64 65 7b 27 63 6f | 70 79 72 69 67 68 74 27 |code{'co|pyright'|
|00001270| 2c 7d 20 5c 63 6f 64 65 | 7b 27 76 65 72 73 69 6f |,} \code|{'versio|
|00001280| 6e 27 2c 7d 20 5c 63 6f | 64 65 7b 27 70 6c 61 74 |n',} \co|de{'plat|
|00001290| 66 6f 72 6d 27 2c 7d 0a | 5c 63 6f 64 65 7b 27 65 |form',}.|\code{'e|
|000012a0| 78 69 74 27 2c 7d 20 5c | 63 6f 64 65 7b 27 6d 61 |xit',} \|code{'ma|
|000012b0| 78 69 6e 74 27 29 7d 2e | 0a 5c 65 6e 64 7b 64 61 |xint')}.|.\end{da|
|000012c0| 74 61 64 65 73 63 7d 0a | 0a 52 45 78 65 63 20 69 |tadesc}.|.RExec i|
|000012d0| 6e 73 74 61 6e 63 65 73 | 20 73 75 70 70 6f 72 74 |nstances| support|
|000012e0| 20 74 68 65 20 66 6f 6c | 6c 6f 77 69 6e 67 20 6d | the fol|lowing m|
|000012f0| 65 74 68 6f 64 73 3a 0a | 5c 72 65 6e 65 77 63 6f |ethods:.|\renewco|
|00001300| 6d 6d 61 6e 64 7b 5c 69 | 6e 64 65 78 73 75 62 69 |mmand{\i|ndexsubi|
|00001310| 74 65 6d 7d 7b 28 52 45 | 78 65 63 20 6f 62 6a 65 |tem}{(RE|xec obje|
|00001320| 63 74 20 6d 65 74 68 6f | 64 29 7d 0a 0a 5c 62 65 |ct metho|d)}..\be|
|00001330| 67 69 6e 7b 66 75 6e 63 | 64 65 73 63 7d 7b 72 5f |gin{func|desc}{r_|
|00001340| 65 76 61 6c 7d 7b 63 6f | 64 65 7d 0a 5c 76 61 72 |eval}{co|de}.\var|
|00001350| 7b 63 6f 64 65 7d 20 6d | 75 73 74 20 65 69 74 68 |{code} m|ust eith|
|00001360| 65 72 20 62 65 20 61 20 | 73 74 72 69 6e 67 20 63 |er be a |string c|
|00001370| 6f 6e 74 61 69 6e 69 6e | 67 20 61 20 50 79 74 68 |ontainin|g a Pyth|
|00001380| 6f 6e 20 65 78 70 72 65 | 73 73 69 6f 6e 2c 20 6f |on expre|ssion, o|
|00001390| 72 0a 61 20 63 6f 6d 70 | 69 6c 65 64 20 63 6f 64 |r.a comp|iled cod|
|000013a0| 65 20 6f 62 6a 65 63 74 | 2c 20 77 68 69 63 68 20 |e object|, which |
|000013b0| 77 69 6c 6c 20 62 65 20 | 65 76 61 6c 75 61 74 65 |will be |evaluate|
|000013c0| 64 20 69 6e 20 74 68 65 | 20 72 65 73 74 72 69 63 |d in the| restric|
|000013d0| 74 65 64 0a 65 6e 76 69 | 72 6f 6e 6d 65 6e 74 27 |ted.envi|ronment'|
|000013e0| 73 20 5c 63 6f 64 65 7b | 5f 5f 6d 61 69 6e 5f 5f |s \code{|__main__|
|000013f0| 7d 20 6d 6f 64 75 6c 65 | 2e 20 20 54 68 65 20 76 |} module|. The v|
|00001400| 61 6c 75 65 20 6f 66 20 | 74 68 65 20 65 78 70 72 |alue of |the expr|
|00001410| 65 73 73 69 6f 6e 20 6f | 72 0a 63 6f 64 65 20 6f |ession o|r.code o|
|00001420| 62 6a 65 63 74 20 77 69 | 6c 6c 20 62 65 20 72 65 |bject wi|ll be re|
|00001430| 74 75 72 6e 65 64 2e 0a | 5c 65 6e 64 7b 66 75 6e |turned..|\end{fun|
|00001440| 63 64 65 73 63 7d 0a 0a | 5c 62 65 67 69 6e 7b 66 |cdesc}..|\begin{f|
|00001450| 75 6e 63 64 65 73 63 7d | 7b 72 5f 65 78 65 63 7d |uncdesc}|{r_exec}|
|00001460| 7b 63 6f 64 65 7d 0a 5c | 76 61 72 7b 63 6f 64 65 |{code}.\|var{code|
|00001470| 7d 20 6d 75 73 74 20 65 | 69 74 68 65 72 20 62 65 |} must e|ither be|
|00001480| 20 61 20 73 74 72 69 6e | 67 20 63 6f 6e 74 61 69 | a strin|g contai|
|00001490| 6e 69 6e 67 20 6f 6e 65 | 20 6f 72 20 6d 6f 72 65 |ning one| or more|
|000014a0| 20 6c 69 6e 65 73 20 6f | 66 0a 50 79 74 68 6f 6e | lines o|f.Python|
|000014b0| 20 63 6f 64 65 2c 20 6f | 72 20 61 20 63 6f 6d 70 | code, o|r a comp|
|000014c0| 69 6c 65 64 20 63 6f 64 | 65 20 6f 62 6a 65 63 74 |iled cod|e object|
|000014d0| 2c 20 77 68 69 63 68 20 | 77 69 6c 6c 20 62 65 20 |, which |will be |
|000014e0| 65 78 65 63 75 74 65 64 | 20 69 6e 20 74 68 65 0a |executed| in the.|
|000014f0| 72 65 73 74 72 69 63 74 | 65 64 20 65 6e 76 69 72 |restrict|ed envir|
|00001500| 6f 6e 6d 65 6e 74 27 73 | 20 5c 63 6f 64 65 7b 5f |onment's| \code{_|
|00001510| 5f 6d 61 69 6e 5f 5f 7d | 20 6d 6f 64 75 6c 65 2e |_main__}| module.|
|00001520| 0a 5c 65 6e 64 7b 66 75 | 6e 63 64 65 73 63 7d 0a |.\end{fu|ncdesc}.|
|00001530| 0a 5c 62 65 67 69 6e 7b | 66 75 6e 63 64 65 73 63 |.\begin{|funcdesc|
|00001540| 7d 7b 72 5f 65 78 65 63 | 66 69 6c 65 7d 7b 66 69 |}{r_exec|file}{fi|
|00001550| 6c 65 6e 61 6d 65 7d 0a | 45 78 65 63 75 74 65 20 |lename}.|Execute |
|00001560| 74 68 65 20 50 79 74 68 | 6f 6e 20 63 6f 64 65 20 |the Pyth|on code |
|00001570| 63 6f 6e 74 61 69 6e 65 | 64 20 69 6e 20 74 68 65 |containe|d in the|
|00001580| 20 66 69 6c 65 20 5c 76 | 61 72 7b 66 69 6c 65 6e | file \v|ar{filen|
|00001590| 61 6d 65 7d 20 69 6e 20 | 74 68 65 0a 72 65 73 74 |ame} in |the.rest|
|000015a0| 72 69 63 74 65 64 20 65 | 6e 76 69 72 6f 6e 6d 65 |ricted e|nvironme|
|000015b0| 6e 74 27 73 20 5c 63 6f | 64 65 7b 5f 5f 6d 61 69 |nt's \co|de{__mai|
|000015c0| 6e 5f 5f 7d 20 6d 6f 64 | 75 6c 65 2e 0a 5c 65 6e |n__} mod|ule..\en|
|000015d0| 64 7b 66 75 6e 63 64 65 | 73 63 7d 0a 0a 4d 65 74 |d{funcde|sc}..Met|
|000015e0| 68 6f 64 73 20 77 68 6f | 73 65 20 6e 61 6d 65 73 |hods who|se names|
|000015f0| 20 62 65 67 69 6e 20 77 | 69 74 68 20 5c 63 6f 64 | begin w|ith \cod|
|00001600| 65 7b 73 5f 7d 20 61 72 | 65 20 73 69 6d 69 6c 61 |e{s_} ar|e simila|
|00001610| 72 20 74 6f 20 74 68 65 | 20 66 75 6e 63 74 69 6f |r to the| functio|
|00001620| 6e 73 0a 62 65 67 69 6e | 6e 69 6e 67 20 77 69 74 |ns.begin|ning wit|
|00001630| 68 20 5c 63 6f 64 65 7b | 72 5f 7d 2c 20 62 75 74 |h \code{|r_}, but|
|00001640| 20 74 68 65 20 63 6f 64 | 65 20 77 69 6c 6c 20 62 | the cod|e will b|
|00001650| 65 20 67 72 61 6e 74 65 | 64 20 61 63 63 65 73 73 |e grante|d access|
|00001660| 20 74 6f 0a 72 65 73 74 | 72 69 63 74 65 64 20 76 | to.rest|ricted v|
|00001670| 65 72 73 69 6f 6e 73 20 | 6f 66 20 74 68 65 20 73 |ersions |of the s|
|00001680| 74 61 6e 64 61 72 64 20 | 49 2f 4f 20 73 74 72 65 |tandard |I/O stre|
|00001690| 61 6e 73 20 5c 63 6f 64 | 65 7b 73 79 73 2e 73 74 |ans \cod|e{sys.st|
|000016a0| 64 69 6e 7d 2c 0a 5c 63 | 6f 64 65 7b 73 79 73 2e |din},.\c|ode{sys.|
|000016b0| 73 74 64 65 72 72 7d 2c | 20 61 6e 64 20 5c 63 6f |stderr},| and \co|
|000016c0| 64 65 7b 73 79 73 2e 73 | 74 64 6f 75 74 7d 2e 20 |de{sys.s|tdout}. |
|000016d0| 20 0a 0a 5c 62 65 67 69 | 6e 7b 66 75 6e 63 64 65 | ..\begi|n{funcde|
|000016e0| 73 63 7d 7b 73 5f 65 76 | 61 6c 7d 7b 63 6f 64 65 |sc}{s_ev|al}{code|
|000016f0| 7d 0a 5c 76 61 72 7b 63 | 6f 64 65 7d 20 6d 75 73 |}.\var{c|ode} mus|
|00001700| 74 20 62 65 20 61 20 73 | 74 72 69 6e 67 20 63 6f |t be a s|tring co|
|00001710| 6e 74 61 69 6e 69 6e 67 | 20 61 20 50 79 74 68 6f |ntaining| a Pytho|
|00001720| 6e 20 65 78 70 72 65 73 | 73 69 6f 6e 2c 20 77 68 |n expres|sion, wh|
|00001730| 69 63 68 20 77 69 6c 6c | 0a 62 65 20 65 76 61 6c |ich will|.be eval|
|00001740| 75 61 74 65 64 20 69 6e | 20 74 68 65 20 72 65 73 |uated in| the res|
|00001750| 74 72 69 63 74 65 64 20 | 65 6e 76 69 72 6f 6e 6d |tricted |environm|
|00001760| 65 6e 74 2e 20 20 0a 5c | 65 6e 64 7b 66 75 6e 63 |ent. .\|end{func|
|00001770| 64 65 73 63 7d 0a 0a 5c | 62 65 67 69 6e 7b 66 75 |desc}..\|begin{fu|
|00001780| 6e 63 64 65 73 63 7d 7b | 73 5f 65 78 65 63 7d 7b |ncdesc}{|s_exec}{|
|00001790| 63 6f 64 65 7d 0a 5c 76 | 61 72 7b 63 6f 64 65 7d |code}.\v|ar{code}|
|000017a0| 20 6d 75 73 74 20 62 65 | 20 61 20 73 74 72 69 6e | must be| a strin|
|000017b0| 67 20 63 6f 6e 74 61 69 | 6e 69 6e 67 20 6f 6e 65 |g contai|ning one|
|000017c0| 20 6f 72 20 6d 6f 72 65 | 20 6c 69 6e 65 73 20 6f | or more| lines o|
|000017d0| 66 20 50 79 74 68 6f 6e | 20 63 6f 64 65 2c 0a 77 |f Python| code,.w|
|000017e0| 68 69 63 68 20 77 69 6c | 6c 20 62 65 20 65 78 65 |hich wil|l be exe|
|000017f0| 63 75 74 65 64 20 69 6e | 20 74 68 65 20 72 65 73 |cuted in| the res|
|00001800| 74 72 69 63 74 65 64 20 | 65 6e 76 69 72 6f 6e 6d |tricted |environm|
|00001810| 65 6e 74 2e 20 20 0a 5c | 65 6e 64 7b 66 75 6e 63 |ent. .\|end{func|
|00001820| 64 65 73 63 7d 0a 0a 5c | 62 65 67 69 6e 7b 66 75 |desc}..\|begin{fu|
|00001830| 6e 63 64 65 73 63 7d 7b | 73 5f 65 78 65 63 66 69 |ncdesc}{|s_execfi|
|00001840| 6c 65 7d 7b 63 6f 64 65 | 7d 0a 45 78 65 63 75 74 |le}{code|}.Execut|
|00001850| 65 20 74 68 65 20 50 79 | 74 68 6f 6e 20 63 6f 64 |e the Py|thon cod|
|00001860| 65 20 63 6f 6e 74 61 69 | 6e 65 64 20 69 6e 20 74 |e contai|ned in t|
|00001870| 68 65 20 66 69 6c 65 20 | 5c 76 61 72 7b 66 69 6c |he file |\var{fil|
|00001880| 65 6e 61 6d 65 7d 20 69 | 6e 20 74 68 65 0a 72 65 |ename} i|n the.re|
|00001890| 73 74 72 69 63 74 65 64 | 20 65 6e 76 69 72 6f 6e |stricted| environ|
|000018a0| 6d 65 6e 74 2e 0a 5c 65 | 6e 64 7b 66 75 6e 63 64 |ment..\e|nd{funcd|
|000018b0| 65 73 63 7d 0a 0a 5c 63 | 6f 64 65 7b 52 45 78 65 |esc}..\c|ode{RExe|
|000018c0| 63 7d 20 6f 62 6a 65 63 | 74 73 20 6d 75 73 74 20 |c} objec|ts must |
|000018d0| 61 6c 73 6f 20 73 75 70 | 70 6f 72 74 20 76 61 72 |also sup|port var|
|000018e0| 69 6f 75 73 20 6d 65 74 | 68 6f 64 73 20 77 68 69 |ious met|hods whi|
|000018f0| 63 68 20 77 69 6c 6c 20 | 62 65 0a 69 6d 70 6c 69 |ch will |be.impli|
|00001900| 63 69 74 6c 79 20 63 61 | 6c 6c 65 64 20 62 79 20 |citly ca|lled by |
|00001910| 63 6f 64 65 20 65 78 65 | 63 75 74 69 6e 67 20 69 |code exe|cuting i|
|00001920| 6e 20 74 68 65 20 72 65 | 73 74 72 69 63 74 65 64 |n the re|stricted|
|00001930| 20 65 6e 76 69 72 6f 6e | 6d 65 6e 74 2e 0a 4f 76 | environ|ment..Ov|
|00001940| 65 72 72 69 64 69 6e 67 | 20 74 68 65 73 65 20 6d |erriding| these m|
|00001950| 65 74 68 6f 64 73 20 69 | 6e 20 61 20 73 75 62 63 |ethods i|n a subc|
|00001960| 6c 61 73 73 20 69 73 20 | 75 73 65 64 20 74 6f 20 |lass is |used to |
|00001970| 63 68 61 6e 67 65 20 74 | 68 65 20 70 6f 6c 69 63 |change t|he polic|
|00001980| 69 65 73 0a 65 6e 66 6f | 72 63 65 64 20 62 79 20 |ies.enfo|rced by |
|00001990| 61 20 72 65 73 74 72 69 | 63 74 65 64 20 65 6e 76 |a restri|cted env|
|000019a0| 69 72 6f 6e 6d 65 6e 74 | 2e 0a 0a 5c 62 65 67 69 |ironment|...\begi|
|000019b0| 6e 7b 66 75 6e 63 64 65 | 73 63 7d 7b 72 5f 69 6d |n{funcde|sc}{r_im|
|000019c0| 70 6f 72 74 7d 7b 6d 6f | 64 75 6c 65 6e 61 6d 65 |port}{mo|dulename|
|000019d0| 5c 6f 70 74 69 6f 6e 61 | 6c 7b 5c 2c 20 67 6c 6f |\optiona|l{\, glo|
|000019e0| 62 61 6c 73 5c 2c 20 6c | 6f 63 61 6c 73 5c 2c 20 |bals\, l|ocals\, |
|000019f0| 66 72 6f 6d 6c 69 73 74 | 7d 7d 0a 49 6d 70 6f 72 |fromlist|}}.Impor|
|00001a00| 74 20 74 68 65 20 6d 6f | 64 75 6c 65 20 5c 76 61 |t the mo|dule \va|
|00001a10| 72 7b 6d 6f 64 75 6c 65 | 6e 61 6d 65 7d 2c 20 72 |r{module|name}, r|
|00001a20| 61 69 73 69 6e 67 20 61 | 6e 20 5c 63 6f 64 65 7b |aising a|n \code{|
|00001a30| 49 6d 70 6f 72 74 45 72 | 72 6f 72 7d 0a 65 78 63 |ImportEr|ror}.exc|
|00001a40| 65 70 74 69 6f 6e 20 69 | 66 20 74 68 65 20 6d 6f |eption i|f the mo|
|00001a50| 64 75 6c 65 20 69 73 20 | 63 6f 6e 73 69 64 65 72 |dule is |consider|
|00001a60| 65 64 20 75 6e 73 61 66 | 65 2e 0a 5c 65 6e 64 7b |ed unsaf|e..\end{|
|00001a70| 66 75 6e 63 64 65 73 63 | 7d 0a 0a 5c 62 65 67 69 |funcdesc|}..\begi|
|00001a80| 6e 7b 66 75 6e 63 64 65 | 73 63 7d 7b 72 5f 6f 70 |n{funcde|sc}{r_op|
|00001a90| 65 6e 7d 7b 66 69 6c 65 | 6e 61 6d 65 5c 6f 70 74 |en}{file|name\opt|
|00001aa0| 69 6f 6e 61 6c 7b 5c 2c | 20 6d 6f 64 65 5c 6f 70 |ional{\,| mode\op|
|00001ab0| 74 69 6f 6e 61 6c 7b 5c | 2c 20 62 75 66 73 69 7a |tional{\|, bufsiz|
|00001ac0| 65 7d 7d 7d 0a 4d 65 74 | 68 6f 64 20 63 61 6c 6c |e}}}.Met|hod call|
|00001ad0| 65 64 20 77 68 65 6e 20 | 5c 63 6f 64 65 7b 6f 70 |ed when |\code{op|
|00001ae0| 65 6e 28 29 7d 20 69 73 | 20 63 61 6c 6c 65 64 20 |en()} is| called |
|00001af0| 69 6e 20 74 68 65 20 72 | 65 73 74 72 69 63 74 65 |in the r|estricte|
|00001b00| 64 0a 65 6e 76 69 72 6f | 6e 6d 65 6e 74 2e 20 20 |d.enviro|nment. |
|00001b10| 54 68 65 20 61 72 67 75 | 6d 65 6e 74 73 20 61 72 |The argu|ments ar|
|00001b20| 65 20 69 64 65 6e 74 69 | 63 61 6c 20 74 6f 20 74 |e identi|cal to t|
|00001b30| 68 6f 73 65 20 6f 66 20 | 5c 63 6f 64 65 7b 6f 70 |hose of |\code{op|
|00001b40| 65 6e 28 29 7d 2c 0a 61 | 6e 64 20 61 20 66 69 6c |en()},.a|nd a fil|
|00001b50| 65 20 6f 62 6a 65 63 74 | 20 28 6f 72 20 61 20 63 |e object| (or a c|
|00001b60| 6c 61 73 73 20 69 6e 73 | 74 61 6e 63 65 20 63 6f |lass ins|tance co|
|00001b70| 6d 70 61 74 69 62 6c 65 | 20 77 69 74 68 20 66 69 |mpatible| with fi|
|00001b80| 6c 65 20 6f 62 6a 65 63 | 74 73 29 0a 73 68 6f 75 |le objec|ts).shou|
|00001b90| 6c 64 20 62 65 20 72 65 | 74 75 72 6e 65 64 2e 20 |ld be re|turned. |
|00001ba0| 20 5c 63 6f 64 65 7b 52 | 45 78 65 63 7d 27 73 20 | \code{R|Exec}'s |
|00001bb0| 64 65 66 61 75 6c 74 20 | 62 65 68 61 76 69 6f 75 |default |behaviou|
|00001bc0| 72 20 69 73 20 61 6c 6c | 6f 77 20 6f 70 65 6e 69 |r is all|ow openi|
|00001bd0| 6e 67 0a 61 6e 79 20 66 | 69 6c 65 20 66 6f 72 20 |ng.any f|ile for |
|00001be0| 72 65 61 64 69 6e 67 2c | 20 62 75 74 20 66 6f 72 |reading,| but for|
|00001bf0| 62 69 64 64 69 6e 67 20 | 61 6e 79 20 61 74 74 65 |bidding |any atte|
|00001c00| 6d 70 74 20 74 6f 20 77 | 72 69 74 65 20 61 20 66 |mpt to w|rite a f|
|00001c10| 69 6c 65 2e 20 20 53 65 | 65 0a 74 68 65 20 65 78 |ile. Se|e.the ex|
|00001c20| 61 6d 70 6c 65 20 62 65 | 6c 6f 77 20 66 6f 72 20 |ample be|low for |
|00001c30| 61 6e 20 69 6d 70 6c 65 | 6d 65 6e 74 61 74 69 6f |an imple|mentatio|
|00001c40| 6e 20 6f 66 20 61 20 6c | 65 73 73 20 72 65 73 74 |n of a l|ess rest|
|00001c50| 72 69 63 74 69 76 65 0a | 5c 63 6f 64 65 7b 72 5f |rictive.|\code{r_|
|00001c60| 6f 70 65 6e 28 29 7d 2e | 0a 5c 65 6e 64 7b 66 75 |open()}.|.\end{fu|
|00001c70| 6e 63 64 65 73 63 7d 0a | 0a 5c 62 65 67 69 6e 7b |ncdesc}.|.\begin{|
|00001c80| 66 75 6e 63 64 65 73 63 | 7d 7b 72 5f 72 65 6c 6f |funcdesc|}{r_relo|
|00001c90| 61 64 7d 7b 6d 6f 64 75 | 6c 65 7d 0a 52 65 6c 6f |ad}{modu|le}.Relo|
|00001ca0| 61 64 20 74 68 65 20 6d | 6f 64 75 6c 65 20 6f 62 |ad the m|odule ob|
|00001cb0| 6a 65 63 74 20 5c 76 61 | 72 7b 6d 6f 64 75 6c 65 |ject \va|r{module|
|00001cc0| 7d 2c 20 72 65 2d 70 61 | 72 73 69 6e 67 20 61 6e |}, re-pa|rsing an|
|00001cd0| 64 20 72 65 2d 69 6e 69 | 74 69 61 6c 69 7a 69 6e |d re-ini|tializin|
|00001ce0| 67 20 69 74 2e 20 20 0a | 5c 65 6e 64 7b 66 75 6e |g it. .|\end{fun|
|00001cf0| 63 64 65 73 63 7d 0a 0a | 5c 62 65 67 69 6e 7b 66 |cdesc}..|\begin{f|
|00001d00| 75 6e 63 64 65 73 63 7d | 7b 72 5f 75 6e 6c 6f 61 |uncdesc}|{r_unloa|
|00001d10| 64 7d 7b 6d 6f 64 75 6c | 65 7d 0a 55 6e 6c 6f 61 |d}{modul|e}.Unloa|
|00001d20| 64 20 74 68 65 20 6d 6f | 64 75 6c 65 20 6f 62 6a |d the mo|dule obj|
|00001d30| 65 63 74 20 5c 76 61 72 | 7b 6d 6f 64 75 6c 65 7d |ect \var|{module}|
|00001d40| 20 28 69 2e 65 2e 2c 20 | 72 65 6d 6f 76 65 20 69 | (i.e., |remove i|
|00001d50| 74 20 66 72 6f 6d 20 74 | 68 65 0a 72 65 73 74 72 |t from t|he.restr|
|00001d60| 69 63 74 65 64 20 65 6e | 76 69 72 6f 6e 6d 65 6e |icted en|vironmen|
|00001d70| 74 27 73 20 5c 63 6f 64 | 65 7b 73 79 73 2e 6d 6f |t's \cod|e{sys.mo|
|00001d80| 64 75 6c 65 73 7d 20 64 | 69 63 74 69 6f 6e 61 72 |dules} d|ictionar|
|00001d90| 79 29 2e 0a 5c 65 6e 64 | 7b 66 75 6e 63 64 65 73 |y)..\end|{funcdes|
|00001da0| 63 7d 0a 0a 41 6e 64 20 | 74 68 65 69 72 20 65 71 |c}..And |their eq|
|00001db0| 75 69 76 61 6c 65 6e 74 | 73 20 77 69 74 68 20 61 |uivalent|s with a|
|00001dc0| 63 63 65 73 73 20 74 6f | 20 72 65 73 74 72 69 63 |ccess to| restric|
|00001dd0| 74 65 64 20 73 74 61 6e | 64 61 72 64 20 49 2f 4f |ted stan|dard I/O|
|00001de0| 20 73 74 72 65 61 6d 73 | 3a 0a 0a 5c 62 65 67 69 | streams|:..\begi|
|00001df0| 6e 7b 66 75 6e 63 64 65 | 73 63 7d 7b 73 5f 69 6d |n{funcde|sc}{s_im|
|00001e00| 70 6f 72 74 7d 7b 6d 6f | 64 75 6c 65 6e 61 6d 65 |port}{mo|dulename|
|00001e10| 5c 6f 70 74 69 6f 6e 61 | 6c 7b 5c 2c 20 67 6c 6f |\optiona|l{\, glo|
|00001e20| 62 61 6c 73 2c 20 6c 6f | 63 61 6c 73 2c 20 66 72 |bals, lo|cals, fr|
|00001e30| 6f 6d 6c 69 73 74 7d 7d | 0a 49 6d 70 6f 72 74 20 |omlist}}|.Import |
|00001e40| 74 68 65 20 6d 6f 64 75 | 6c 65 20 5c 76 61 72 7b |the modu|le \var{|
|00001e50| 6d 6f 64 75 6c 65 6e 61 | 6d 65 7d 2c 20 72 61 69 |modulena|me}, rai|
|00001e60| 73 69 6e 67 20 61 6e 20 | 5c 63 6f 64 65 7b 49 6d |sing an |\code{Im|
|00001e70| 70 6f 72 74 45 72 72 6f | 72 7d 0a 65 78 63 65 70 |portErro|r}.excep|
|00001e80| 74 69 6f 6e 20 69 66 20 | 74 68 65 20 6d 6f 64 75 |tion if |the modu|
|00001e90| 6c 65 20 69 73 20 63 6f | 6e 73 69 64 65 72 65 64 |le is co|nsidered|
|00001ea0| 20 75 6e 73 61 66 65 2e | 0a 5c 65 6e 64 7b 66 75 | unsafe.|.\end{fu|
|00001eb0| 6e 63 64 65 73 63 7d 0a | 0a 5c 62 65 67 69 6e 7b |ncdesc}.|.\begin{|
|00001ec0| 66 75 6e 63 64 65 73 63 | 7d 7b 73 5f 72 65 6c 6f |funcdesc|}{s_relo|
|00001ed0| 61 64 7d 7b 6d 6f 64 75 | 6c 65 7d 0a 52 65 6c 6f |ad}{modu|le}.Relo|
|00001ee0| 61 64 20 74 68 65 20 6d | 6f 64 75 6c 65 20 6f 62 |ad the m|odule ob|
|00001ef0| 6a 65 63 74 20 5c 76 61 | 72 7b 6d 6f 64 75 6c 65 |ject \va|r{module|
|00001f00| 7d 2c 20 72 65 2d 70 61 | 72 73 69 6e 67 20 61 6e |}, re-pa|rsing an|
|00001f10| 64 20 72 65 2d 69 6e 69 | 74 69 61 6c 69 7a 69 6e |d re-ini|tializin|
|00001f20| 67 20 69 74 2e 20 20 0a | 5c 65 6e 64 7b 66 75 6e |g it. .|\end{fun|
|00001f30| 63 64 65 73 63 7d 0a 0a | 5c 62 65 67 69 6e 7b 66 |cdesc}..|\begin{f|
|00001f40| 75 6e 63 64 65 73 63 7d | 7b 73 5f 75 6e 6c 6f 61 |uncdesc}|{s_unloa|
|00001f50| 64 7d 7b 6d 6f 64 75 6c | 65 7d 0a 55 6e 6c 6f 61 |d}{modul|e}.Unloa|
|00001f60| 64 20 74 68 65 20 6d 6f | 64 75 6c 65 20 6f 62 6a |d the mo|dule obj|
|00001f70| 65 63 74 20 5c 76 61 72 | 7b 6d 6f 64 75 6c 65 7d |ect \var|{module}|
|00001f80| 2e 20 20 20 0a 25 20 58 | 58 58 20 77 68 61 74 20 |. .% X|XX what |
|00001f90| 61 72 65 20 74 68 65 20 | 73 65 6d 61 6e 74 69 63 |are the |semantic|
|00001fa0| 73 20 6f 66 20 74 68 69 | 73 3f 20 20 0a 5c 65 6e |s of thi|s? .\en|
|00001fb0| 64 7b 66 75 6e 63 64 65 | 73 63 7d 0a 0a 5c 73 75 |d{funcde|sc}..\su|
|00001fc0| 62 73 65 63 74 69 6f 6e | 7b 41 6e 20 65 78 61 6d |bsection|{An exam|
|00001fd0| 70 6c 65 7d 0a 0a 4c 65 | 74 20 75 73 20 73 61 79 |ple}..Le|t us say|
|00001fe0| 20 74 68 61 74 20 77 65 | 20 77 61 6e 74 20 61 20 | that we| want a |
|00001ff0| 73 6c 69 67 68 74 6c 79 | 20 6d 6f 72 65 20 72 65 |slightly| more re|
|00002000| 6c 61 78 65 64 20 70 6f | 6c 69 63 79 20 74 68 61 |laxed po|licy tha|
|00002010| 6e 20 74 68 65 0a 73 74 | 61 6e 64 61 72 64 20 52 |n the.st|andard R|
|00002020| 45 78 65 63 20 63 6c 61 | 73 73 2e 20 20 46 6f 72 |Exec cla|ss. For|
|00002030| 20 65 78 61 6d 70 6c 65 | 2c 20 69 66 20 77 65 27 | example|, if we'|
|00002040| 72 65 20 77 69 6c 6c 69 | 6e 67 20 74 6f 20 61 6c |re willi|ng to al|
|00002050| 6c 6f 77 20 66 69 6c 65 | 73 20 69 6e 0a 5c 66 69 |low file|s in.\fi|
|00002060| 6c 65 7b 2f 74 6d 70 7d | 20 74 6f 20 62 65 20 77 |le{/tmp}| to be w|
|00002070| 72 69 74 74 65 6e 2c 20 | 77 65 20 63 61 6e 20 73 |ritten, |we can s|
|00002080| 75 62 63 6c 61 73 73 20 | 74 68 65 20 5c 63 6f 64 |ubclass |the \cod|
|00002090| 65 7b 52 45 78 65 63 7d | 20 63 6c 61 73 73 3a 0a |e{RExec}| class:.|
|000020a0| 0a 5c 62 63 6f 64 65 5c | 62 65 67 69 6e 7b 76 65 |.\bcode\|begin{ve|
|000020b0| 72 62 61 74 69 6d 7d 0a | 63 6c 61 73 73 20 54 6d |rbatim}.|class Tm|
|000020c0| 70 57 72 69 74 65 72 52 | 45 78 65 63 28 72 65 78 |pWriterR|Exec(rex|
|000020d0| 65 63 2e 52 45 78 65 63 | 29 3a 0a 20 20 20 20 64 |ec.RExec|):. d|
|000020e0| 65 66 20 72 5f 6f 70 65 | 6e 28 73 65 6c 66 2c 20 |ef r_ope|n(self, |
|000020f0| 66 69 6c 65 2c 20 6d 6f | 64 65 3d 27 72 27 2c 20 |file, mo|de='r', |
|00002100| 62 75 66 3d 2d 31 29 3a | 0a 20 20 20 20 20 20 20 |buf=-1):|. |
|00002110| 20 69 66 20 6d 6f 64 65 | 20 69 6e 20 28 27 72 27 | if mode| in ('r'|
|00002120| 2c 20 27 72 62 27 29 3a | 0a 20 20 20 20 20 20 20 |, 'rb'):|. |
|00002130| 20 20 20 20 20 70 61 73 | 73 0a 20 20 20 20 20 20 | pas|s. |
|00002140| 20 20 65 6c 69 66 20 6d | 6f 64 65 20 69 6e 20 28 | elif m|ode in (|
|00002150| 27 77 27 2c 20 27 77 62 | 27 2c 20 27 61 27 2c 20 |'w', 'wb|', 'a', |
|00002160| 27 61 62 27 29 3a 0a 20 | 20 20 20 20 20 20 20 20 |'ab'):. | |
|00002170| 20 20 20 23 20 63 68 65 | 63 6b 20 66 69 6c 65 6e | # che|ck filen|
|00002180| 61 6d 65 20 3a 20 6d 75 | 73 74 20 62 65 67 69 6e |ame : mu|st begin|
|00002190| 20 77 69 74 68 20 2f 74 | 6d 70 2f 0a 20 20 20 20 | with /t|mp/. |
|000021a0| 20 20 20 20 20 20 20 20 | 69 66 20 66 69 6c 65 5b | |if file[|
|000021b0| 3a 35 5d 21 3d 27 2f 74 | 6d 70 2f 27 3a 20 0a 20 |:5]!='/t|mp/': . |
|000021c0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 72 | | r|
|000021d0| 61 69 73 65 20 49 4f 45 | 72 72 6f 72 2c 20 22 63 |aise IOE|rror, "c|
|000021e0| 61 6e 27 74 20 77 72 69 | 74 65 20 6f 75 74 73 69 |an't wri|te outsi|
|000021f0| 64 65 20 2f 74 6d 70 22 | 0a 20 20 20 20 20 20 20 |de /tmp"|. |
|00002200| 20 20 20 20 20 65 6c 69 | 66 20 28 73 74 72 69 6e | eli|f (strin|
|00002210| 67 2e 66 69 6e 64 28 66 | 69 6c 65 2c 20 27 2f 2e |g.find(f|ile, '/.|
|00002220| 2e 2f 27 29 20 3e 3d 20 | 30 20 6f 72 0a 20 20 20 |./') >= |0 or. |
|00002230| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 66 69 | | fi|
|00002240| 6c 65 5b 3a 33 5d 20 3d | 3d 20 27 2e 2e 2f 27 20 |le[:3] =|= '../' |
|00002250| 6f 72 20 66 69 6c 65 5b | 2d 33 3a 5d 20 3d 3d 20 |or file[|-3:] == |
|00002260| 27 2f 2e 2e 27 29 3a 0a | 20 20 20 20 20 20 20 20 |'/..'):.| |
|00002270| 20 20 20 20 20 20 20 20 | 72 61 69 73 65 20 49 4f | |raise IO|
|00002280| 45 72 72 6f 72 2c 20 22 | 27 2e 2e 27 20 69 6e 20 |Error, "|'..' in |
|00002290| 66 69 6c 65 6e 61 6d 65 | 20 66 6f 72 62 69 64 64 |filename| forbidd|
|000022a0| 65 6e 22 0a 20 20 20 20 | 20 20 20 20 65 6c 73 65 |en". | else|
|000022b0| 3a 20 72 61 69 73 65 20 | 49 4f 45 72 72 6f 72 2c |: raise |IOError,|
|000022c0| 20 22 49 6c 6c 65 67 61 | 6c 20 6f 70 65 6e 28 29 | "Illega|l open()|
|000022d0| 20 6d 6f 64 65 22 0a 20 | 20 20 20 20 20 20 20 72 | mode". | r|
|000022e0| 65 74 75 72 6e 20 6f 70 | 65 6e 28 66 69 6c 65 2c |eturn op|en(file,|
|000022f0| 20 6d 6f 64 65 2c 20 62 | 75 66 29 0a 5c 65 6e 64 | mode, b|uf).\end|
|00002300| 7b 76 65 72 62 61 74 69 | 6d 7d 5c 65 63 6f 64 65 |{verbati|m}\ecode|
|00002310| 0a 0a 4e 6f 74 69 63 65 | 20 74 68 61 74 20 74 68 |..Notice| that th|
|00002320| 65 20 61 62 6f 76 65 20 | 63 6f 64 65 20 77 69 6c |e above |code wil|
|00002330| 6c 20 6f 63 63 61 73 69 | 6f 6e 61 6c 6c 79 20 66 |l occasi|onally f|
|00002340| 6f 72 62 69 64 20 61 20 | 70 65 72 66 65 63 74 6c |orbid a |perfectl|
|00002350| 79 20 76 61 6c 69 64 0a | 66 69 6c 65 6e 61 6d 65 |y valid.|filename|
|00002360| 3b 20 66 6f 72 20 65 78 | 61 6d 70 6c 65 2c 20 63 |; for ex|ample, c|
|00002370| 6f 64 65 20 69 6e 20 74 | 68 65 20 72 65 73 74 72 |ode in t|he restr|
|00002380| 69 63 74 65 64 20 65 6e | 76 69 72 6f 6e 6d 65 6e |icted en|vironmen|
|00002390| 74 20 77 6f 6e 27 74 20 | 62 65 0a 61 62 6c 65 20 |t won't |be.able |
|000023a0| 74 6f 20 6f 70 65 6e 20 | 61 20 66 69 6c 65 20 63 |to open |a file c|
|000023b0| 61 6c 6c 65 64 20 5c 66 | 69 6c 65 7b 2f 74 6d 70 |alled \f|ile{/tmp|
|000023c0| 2f 66 6f 6f 2f 2e 2e 2f | 62 61 72 7d 2e 20 20 54 |/foo/../|bar}. T|
|000023d0| 6f 20 66 69 78 20 74 68 | 69 73 2c 20 74 68 65 0a |o fix th|is, the.|
|000023e0| 5c 63 6f 64 65 7b 72 5f | 6f 70 65 6e 7d 20 6d 65 |\code{r_|open} me|
|000023f0| 74 68 6f 64 20 77 6f 75 | 6c 64 20 68 61 76 65 20 |thod wou|ld have |
|00002400| 74 6f 20 73 69 6d 70 6c | 69 66 79 20 74 68 65 20 |to simpl|ify the |
|00002410| 66 69 6c 65 6e 61 6d 65 | 20 74 6f 0a 5c 66 69 6c |filename| to.\fil|
|00002420| 65 7b 2f 74 6d 70 2f 62 | 61 72 7d 2c 20 77 68 69 |e{/tmp/b|ar}, whi|
|00002430| 63 68 20 77 6f 75 6c 64 | 20 72 65 71 75 69 72 65 |ch would| require|
|00002440| 20 73 70 6c 69 74 74 69 | 6e 67 20 61 70 61 72 74 | splitti|ng apart|
|00002450| 20 74 68 65 20 66 69 6c | 65 6e 61 6d 65 20 61 6e | the fil|ename an|
|00002460| 64 0a 70 65 72 66 6f 72 | 6d 69 6e 67 20 76 61 72 |d.perfor|ming var|
|00002470| 69 6f 75 73 20 6f 70 65 | 72 61 74 69 6f 6e 73 20 |ious ope|rations |
|00002480| 6f 6e 20 69 74 2e 20 20 | 49 6e 20 63 61 73 65 73 |on it. |In cases|
|00002490| 20 77 68 65 72 65 20 73 | 65 63 75 72 69 74 79 20 | where s|ecurity |
|000024a0| 69 73 20 61 74 0a 73 74 | 61 6b 65 2c 20 69 74 20 |is at.st|ake, it |
|000024b0| 6d 61 79 20 62 65 20 70 | 72 65 66 65 72 61 62 6c |may be p|referabl|
|000024c0| 65 20 74 6f 20 77 72 69 | 74 65 20 73 69 6d 70 6c |e to wri|te simpl|
|000024d0| 65 20 63 6f 64 65 20 77 | 68 69 63 68 20 69 73 20 |e code w|hich is |
|000024e0| 73 6f 6d 65 74 69 6d 65 | 73 0a 6f 76 65 72 6c 79 |sometime|s.overly|
|000024f0| 20 72 65 73 74 72 69 63 | 74 69 76 65 2c 20 69 6e | restric|tive, in|
|00002500| 73 74 65 61 64 20 6f 66 | 20 6d 6f 72 65 20 67 65 |stead of| more ge|
|00002510| 6e 65 72 61 6c 20 63 6f | 64 65 20 74 68 61 74 20 |neral co|de that |
|00002520| 69 73 20 61 6c 73 6f 20 | 6d 6f 72 65 0a 63 6f 6d |is also |more.com|
|00002530| 70 6c 65 78 20 61 6e 64 | 20 6d 61 79 20 68 61 72 |plex and| may har|
|00002540| 62 6f 72 20 61 20 73 75 | 62 74 6c 65 20 73 65 63 |bor a su|btle sec|
|00002550| 75 72 69 74 79 20 68 6f | 6c 65 2e 0a |urity ho|le.. |
+--------+-------------------------+-------------------------+--------+--------+