diff options
author | Alex Gr?nholm <alex.gronholm@nextday.fi> | 2011-05-22 05:03:21 +0300 |
---|---|---|
committer | Alex Gr?nholm <alex.gronholm@nextday.fi> | 2011-05-22 05:03:21 +0300 |
commit | 1df1c78299e06fecde664d4ddb5ec549097daf88 (patch) | |
tree | 39202cc5b606804ae6c5d012cb7b97acfa55eb0c /paste/deploy/compat.py | |
parent | af0125821babc057b451f659b816216569ce8f26 (diff) | |
download | pastedeploy-1df1c78299e06fecde664d4ddb5ec549097daf88.tar.gz |
Refactored the code to be compatible with Python 3.1 and above
Diffstat (limited to 'paste/deploy/compat.py')
-rw-r--r-- | paste/deploy/compat.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/paste/deploy/compat.py b/paste/deploy/compat.py new file mode 100644 index 0000000..f7b93f5 --- /dev/null +++ b/paste/deploy/compat.py @@ -0,0 +1,30 @@ +# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org) +# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php +"""Python 2<->3 compatibility module""" +import sys + + +def print_(template, *args, **kwargs): + template = str(template) + if args: + template = template % args + elif kwargs: + template = template % kwargs + sys.stdout.writelines(template) + +if sys.version_info < (3, 0): + basestring = basestring + from ConfigParser import ConfigParser + from urllib import unquote + iteritems = lambda d: d.iteritems() + + def reraise(t, e, tb): + exec('raise t, e, tb', dict(t=t, e=e, tb=tb)) +else: + basestring = str + from configparser import ConfigParser + from urllib.parse import unquote + iteritems = lambda d: d.items() + + def reraise(t, e, tb): + exec('raise e from tb', dict(e=e, tb=tb)) |