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

Leonardo Rochael Almeida leo@hiper.com.br
10 Feb 2003 18:11:15 -0200


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.

-- 
Ideas don't stay in some minds very long because they don't like
solitary confinement.