Skip to content

Commit

Permalink
Fixed two python2/3 bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
defnull committed Feb 17, 2013
1 parent 9328efc commit 166251b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def _e(): return sys.exc_info()[1]
json_loads = lambda s: json_lds(touni(s))
callable = lambda x: hasattr(x, '__call__')
imap = map
def _raise(*a): raise a[0](a[1]).with_traceback(a[2])
else: # 2.x
import httplib
import thread
Expand All @@ -107,6 +108,7 @@ def next(it): return it.next()
else: # 2.6, 2.7
from collections import MutableMapping as DictMixin
json_loads = json_lds
eval(compile('def _raise(*a): raise a[0], a[1], a[2]', '<py3fix>', 'exec'))

# Some helpers for string/byte handling
def tob(s, enc='utf8'):
Expand Down Expand Up @@ -561,7 +563,7 @@ def mountpoint_wrapper():
def start_response(status, headerlist, exc_info=None):
if exc_info:
try:
raise exc_info[0], exc_info[1], exc_info[2]
_raise(*exc_info)
finally:
exc_info = None
rs.status = status
Expand Down Expand Up @@ -1610,8 +1612,8 @@ def apply(self, callback, route):
def wrapper(*a, **ka):
try:
rv = callback(*a, **ka)
except HTTPError, e:
rv = e
except HTTPError:
rv = _e()

if isinstance(rv, dict):
#Attempt to serialize, raises exception on failure
Expand Down

0 comments on commit 166251b

Please sign in to comment.