A critique of cgi.escape

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Tue Sep 26 03:15:22 EDT 2006


In message <1159253834.519665.109770 at m7g2000cwm.googlegroups.com>, Dan
Bishop wrote:

> Lawrence D'Oliveiro wrote:
>> In message <mailman.570.1159194107.10491.python-list at python.org>, Fredrik
>> Lundh wrote:
>>
>> > Max M wrote:
>> >
>> >> It also makes the  escaped html harder to read for standard cases.
>> >
>> > and slows things down a bit.
>> >
>> > (cgi.escape(s, True) is slower than cgi.escape(s), for reasons that are
>> > obvious for anyone who's looked at the code).
>>
>> What you're doing is adding to the reasons why the existing cgi.escape
>> function is stupidly designed and implemented. The True case is by far
>> the most common, so to make that the slow case, as well as being the
>> non-default case, is doubly brain-dead.
> 
> How exactly would you make s = s.replace('"',""") faster than
> *not* doing the replacement?

Wrong answer. Correctness comes first, then we worry about efficiency.



More information about the Python-list mailing list