durusmail: quixote-users: Patch to protect against future changes to integer division semantics
Patch to protect against future changes to integer division semantics
2004-04-18
Patch to protect against future changes to integer division semantics
2004-04-18
2004-04-18
Patch to protect against future changes to integer division semantics
2004-04-18
Patch to protect against future changes to integer division semantics
Jim Dukarm
2004-04-18
> I noticed that http_response.py uses integer division in the set_status
> method to get the base status (e.g., 400) of an unknown status code
> (e.g., 493):

>     reason = status_reasons[(status / 100) * 100]

> Once integer division semantics change in Python 3.0, this is going to
> start failing. Here's patch to guard against this change while still
> remaining compatible with versions of Python all the way back to 2.0.

> +try:
> +    from __future__ import division
> +except SyntaxError:
> +    _new_division = 0
> +else:
> +    _new_division = 1
> [etc]

It would be a lot simpler just to forget the division and use this:

   reason = status_reasons[status - status%100]

Jim Dukarm
DELTA-X RESEARCH
Victoria BC Canada



reply