[Zope-dev] Accept-Charset hearders causing 500 internal server error.[correct but not lenient]

Romain Slootmaekers romain@zzict.com
Mon, 10 Feb 2003 21:58:18 +0100


Leonardo Rochael Almeida wrote:
> On Mon, 2003-02-10 at 10:27, Romain Slootmaekers wrote:
> 
>>Romain Slootmaekers wrote:
>>Hi,
>>below the original post:
>>
>>it is a bug in Products/Localizer/Accept.py
>>
>>here's the code to fix it:
>>
>>#--- code fix starting from line 102 ---
>>
>>
>># Get the quality
>>             try:
>>                 if len(x) == 2:
>>                     quality = x[1]            # Get the quality
>>                     quality =quality.strip()
>>                     quality = quality[2:]     # Get the number (remove 
>>"q=")
>>                     quality = float(quality)  # Change it to float
>>                 else:
>>                     quality = 1.0
>>             except:
>>                 quality=1.0
>>#--- end of code fix ---
>>
>>I added a strip() and a try/except for other things that can go wrong.
> 
> 
> 
> Please, please, please, don't use generic "except:". They can cause ZODB
> corruption if they catch ConflictErrors. In the case of the code above,
> test for specific errors that "float(quality)" or "x[1]" can raise and
> catch those instead.
> 

In general, a generic except is evil.
Here, I seriously don't see how the code inside the try/except can cause 
a conflict error or other serious damage.

In general, general remarks are evil ;)

Sloot.