Commits

spirit committed 37f2fe3

Make it work with Python 2.5.

  • Participants
  • Parent commits 7280140

Comments (0)

Files changed (1)

File guess_language/__init__.py

 import unicodedata
 import warnings
 
-from collections import defaultdict, namedtuple
-from importlib import import_module
+from collections import defaultdict
 
 from .data import BLOCKS, BLOCK_RSHIFT
 
 MIN_LENGTH = 20
 MAX_GRAMS = 300
 WORD_RE = re.compile(r"(?:[^\W\d_]|['’])+", re.U)
-MODEL_ROOT = __package__ + ".data.models."
+MODEL_ROOT = __name__ + ".data.models."
 
 BASIC_LATIN = {
     "en", "ceb", "ha", "so", "tlh", "id", "haw", "la", "sw", "eu",
 
 models = {}
 
-LanguageInfo = namedtuple("LanguageInfo", ["tag", "id", "name"])
+try:
+    from importlib import import_module
+except ImportError:
+    import sys
+
+    def import_module(name):
+        """Import a module.
+        """
+        __import__(name)
+        return sys.modules[name]
+
+try:
+    from collections import namedtuple
+
+    LanguageInfo = namedtuple("LanguageInfo", ["tag", "id", "name"])
+except ImportError:
+    class LanguageInfo:
+        def __new__(cls, tag, id, name):
+            return tuple((tag, id, name))
 
 
 class UNKNOWN(str):
     @functools.wraps(func)
     def new_func(*args, **kwargs):
         warnings.warn(
-            "call to deprecated function {}()".format(func.__name__),
+            "call to deprecated function %s()" % func.__name__,
             category=DeprecationWarning,
             stacklevel=2
         )
     """
     if not isinstance(text, str):
         warnings.warn("passing an encoded string is deprecated",
-                      DeprecationWarning, 3)
+                      DeprecationWarning, 4)
         text = text.decode(encoding)
     return text