Commits

Anonymous committed 5540a92

let user with version < 1.1 use django_authopenid

  • Participants
  • Parent commits 12780c1

Comments (0)

Files changed (3)

 
-- version 1.0a
+## version 1.0a
 
-- need django latest trunk
+### BREAKING CHANGE: 
+- need django latest trunk or 1.1 when released
+- no more legacy user creation and account managementt. Developpers could use django-registration or anything else
+
+### OTHERS:
+
 - `django_authopenid.util` is now deprecated and renamed to `django.utils`
 - default django openid store is now in `django_authopenid.openid_store`
 - you could now set a custom openid store by settings settings.OPENID_STORE

File django_authopenid/__init__.py

 
 from django.conf import settings
 from django.core.exceptions import ImproperlyConfigured
-from django.utils.importlib import import_module
+
+try:
+    from django.utils.importlib import import_module
+except ImportError:
+    # version < 1.1
+    from django_authopenid.utils.importlib import import_module
 
 try:
     __version__ = __import__('pkg_resources').get_distribution('django_authopenid').version

File django_authopenid/utils/importlib.py

+
+# From django project
+# Taken from Python 2.7 with permission from/by the original author.
+
+import sys
+
+def _resolve_name(name, package, level):
+    """Return the absolute name of the module to be imported."""
+    if not hasattr(package, 'rindex'):
+        raise ValueError("'package' not set to a string")
+    dot = len(package)
+    for x in xrange(level, 1, -1):
+        try:
+            dot = package.rindex('.', 0, dot)
+        except ValueError:
+            raise ValueError("attempted relative import beyond top-level "
+                              "package")
+    return "%s.%s" % (package[:dot], name)
+
+
+def import_module(name, package=None):
+    """Import a module.
+
+    The 'package' argument is required when performing a relative import. It
+    specifies the package to use as the anchor point from which to resolve the
+    relative import to an absolute import.
+
+    """
+    if name.startswith('.'):
+        if not package:
+            raise TypeError("relative imports require the 'package' argument")
+        level = 0
+        for character in name:
+            if character != '.':
+                break
+            level += 1
+        name = _resolve_name(name[level:], package, level)
+    __import__(name)
+    return sys.modules[name]