]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Started work on cleanups for Python 3
authorArmin Ronacher <armin.ronacher@active-4.com>
Sat, 6 Jul 2013 13:49:50 +0000 (15:49 +0200)
committerArmin Ronacher <armin.ronacher@active-4.com>
Sat, 6 Jul 2013 13:49:50 +0000 (15:49 +0200)
babel/__init__.py
babel/_compat.py [new file with mode: 0644]
babel/compat.py [deleted file]
babel/core.py
babel/localedata.py
scripts/import_cldr.py

index 2e34f7c7f549b10e2762d1eb2a9b07d39aa61f36..ae7d6ca98d664a2c629fd1d6a78e30d21b015455 100644 (file)
@@ -26,7 +26,8 @@ This package is basically composed of two major parts:
 :see: http://www.unicode.org/cldr/
 """
 
-from babel.core import *
+from babel.core import UnknownLocaleError, Locale, default_locale, \
+     negotiate_locale, parse_locale
 
 
 try:
diff --git a/babel/_compat.py b/babel/_compat.py
new file mode 100644 (file)
index 0000000..f710492
--- /dev/null
@@ -0,0 +1,58 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2007-2011 Edgewall Software
+# All rights reserved.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at http://babel.edgewall.org/wiki/License.
+#
+# This software consists of voluntary contributions made by many
+# individuals. For the exact contribution history, see the revision
+# history and logs, available at http://babel.edgewall.org/log/.
+
+
+import sys
+
+PY2 = sys.version_info[0] == 2
+
+_identity = lambda x: x
+
+
+if not PY2:
+    text_type = str
+    string_types = (str,)
+    integer_types = (int, )
+
+    iterkeys = lambda d: iter(d.keys())
+    itervalues = lambda d: iter(d.values())
+    iteritems = lambda d: iter(d.items())
+
+    from io import StringIO
+    import cPickle as pickle
+
+    def reraise(tp, value, tb=None):
+        if value.__traceback__ is not tb:
+            raise value.with_traceback(tb)
+        raise value
+
+    implements_to_string = _identity
+
+else:
+    text_type = unicode
+    string_types = (str, unicode)
+    integer_types = (int, long)
+
+    iterkeys = lambda d: d.iterkeys()
+    itervalues = lambda d: d.itervalues()
+    iteritems = lambda d: d.iteritems()
+
+    from cStringIO import StringIO
+    import pickle
+
+    exec('def reraise(tp, value, tb=None):\n raise tp, value, tb')
+
+    def implements_to_string(cls):
+        cls.__unicode__ = cls.__str__
+        cls.__str__ = lambda x: x.__unicode__().encode('utf-8')
+        return cls
diff --git a/babel/compat.py b/babel/compat.py
deleted file mode 100644 (file)
index c9d407a..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# Copyright (C) 2007-2011 Edgewall Software
-# All rights reserved.
-#
-# This software is licensed as described in the file COPYING, which
-# you should have received as part of this distribution. The terms
-# are also available at http://babel.edgewall.org/wiki/License.
-#
-# This software consists of voluntary contributions made by many
-# individuals. For the exact contribution history, see the revision
-# history and logs, available at http://babel.edgewall.org/log/.
-
-try:
-    import threading
-except ImportError:
-    import dummy_threading as threading
-
index dc36a06cf85e06e855dfe5ddf66da87bac603856..4c531259ba1775b0ad9a73325343f86ea9db7193 100644 (file)
@@ -14,9 +14,9 @@
 """Core locale representation and locale data access."""
 
 import os
-import cPickle as pickle
 
 from babel import localedata
+from babel._compat import pickle
 
 __all__ = ['UnknownLocaleError', 'Locale', 'default_locale', 'negotiate_locale',
            'parse_locale']
index ee63a07a355a753210768691bddcb4af829deb6d..7257f6fd3144c4249f28974c80448306c6fc7061 100644 (file)
 """
 
 import os
-import cPickle as pickle
+import threading
 from UserDict import DictMixin
 
-from babel.compat import threading
+from babel._compat import pickle
 
 __all__ = ['exists', 'locale_identifiers', 'load']
 
index 1ebb06bebd49104ab74a0082bfdbf233099f421b..6586a0447c3f8ce0439162b7fbb6a3d5ddb18e77 100755 (executable)
@@ -12,7 +12,6 @@
 # individuals. For the exact contribution history, see the revision
 # history and logs, available at http://babel.edgewall.org/log/.
 
-import cPickle as pickle
 from optparse import OptionParser
 import os
 import re
@@ -25,6 +24,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(sys.argv[0]), '..'))
 from babel import dates, numbers
 from babel.plural import PluralRule
 from babel.localedata import Alias
+from babel._compat import pickle
 
 parse = ElementTree.parse
 weekdays = {'mon': 0, 'tue': 1, 'wed': 2, 'thu': 3, 'fri': 4, 'sat': 5,
@@ -421,7 +421,7 @@ def main():
                         try:
                             date_formats[elem.attrib.get('type')] = \
                                 dates.parse_pattern(unicode(elem.findtext('dateFormat/pattern')))
-                        except ValueError, e:
+                        except ValueError as e:
                             error(e)
                     elif elem.tag == 'alias':
                         date_formats = Alias(_translate_alias(
@@ -438,7 +438,7 @@ def main():
                         try:
                             time_formats[elem.attrib.get('type')] = \
                                 dates.parse_pattern(unicode(elem.findtext('timeFormat/pattern')))
-                        except ValueError, e:
+                        except ValueError as e:
                             error(e)
                     elif elem.tag == 'alias':
                         time_formats = Alias(_translate_alias(
@@ -455,7 +455,7 @@ def main():
                         try:
                             datetime_formats[elem.attrib.get('type')] = \
                                 unicode(elem.findtext('dateTimeFormat/pattern'))
-                        except ValueError, e:
+                        except ValueError as e:
                             error(e)
                     elif elem.tag == 'alias':
                         datetime_formats = Alias(_translate_alias(