<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 11, 2015 at 10:52 AM, Alexander Walters <span dir="ltr"><<a href="mailto:tritium-list@sdamon.com" target="_blank">tritium-list@sdamon.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"><span class="">
On 8/11/2015 11:28, Wes Turner wrote:<br>
</span><blockquote type="cite"><span class="">
<p dir="ltr"><br>
On Aug 11, 2015 10:19 AM, "Wes Turner" <<a href="mailto:wes.turner@gmail.com" target="_blank">wes.turner@gmail.com</a>>
wrote:<br>
</p>
</span><span class=""><p dir="ltr">- [ ] review all string interpolation (for
"injection")<br>
* [ ] review every '%'<br>
* [ ] review every ".format()"<br>
* [ ] review every f-string (AND LOCALS AND GLOBALS)<br>
* every os.system, os.exec*, subprocess.Popen<br>
* every unclosed tag<br>
* every unescaped control character</p>
<p dir="ltr">This would create work we don't need.</p>
<p dir="ltr">Solution: __str_shell_ escapes, adds slashes, and
quotes. __str__SQL__ refs a global list of reserved words.</p>
</span></blockquote>
I don't understand why % and .format got interjected into this.<br>
<br>
If you are mentioning them as 'get the unprocessed version of any
string formatting', that is a bad idea, and not needed, since you
already have an unprocessed string object. Assuming the method were
named "hypothetical":<br>
<br>
>>> 'foo bar'.hypothetical() # returns 'foo bar'<br>
>>> '{0} bar'.format('foo').hypothetical() # returns
'foo bar'<br>
>>> ('%s bar' % ('foo',)).hypothetical() # returns 'foo
bar'<br>
>>> f'{foo} bar'.hypothetical() # returns '{foo} bar',
prime for translation.<br>
<br>
could gettext not be modified to create the same AST as f'{foo} bar'
when it is translated to '{foo} le bar.' and inject it back into the
runtime?<br></div></blockquote><div><br></div><div>well, we're talking about a functional [series of] transformations on __str__ (or __unicode__); with globals and locals,</div><div>and more-or-less a macro for eliding this (**frequently wrong** because when is a string not part of an output format with control characters that need to be escaped before they're interpolated in).</div><div><br></div><div>% and str.format, (and gettext), are the current ways to do this,</div><div>and they are also **frequently wrong** because HTML, SQL.</div><div><br></div><div>The risk with this additional syntax is that unescaped globals and locals are transcluded (and/or translated);</div><div>with an explicit (combination of) string prefixes to indicate forwards-compatible functional composition</div><div>(of usually mutable types).</div></div><br></div></div>