From: Matías Aguirre Date: Thu, 5 Jul 2012 03:50:02 +0000 (-0300) Subject: Add 1.2.5 compatibility code. Refs #386 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=7ede350549523d54d34aa74b96ab4fe6cd70595d;p=django-social-auth.git Add 1.2.5 compatibility code. Refs #386 --- diff --git a/social_auth/backends/__init__.py b/social_auth/backends/__init__.py index a56ca5d..aa8e215 100644 --- a/social_auth/backends/__init__.py +++ b/social_auth/backends/__init__.py @@ -23,11 +23,10 @@ from django.contrib.auth import authenticate from django.contrib.auth.backends import ModelBackend from django.utils import simplejson from django.utils.importlib import import_module -from django.utils.crypto import constant_time_compare from social_auth.utils import setting, log, model_to_ctype, ctype_to_model, \ clean_partial_pipeline, url_add_parameters, \ - get_random_string + get_random_string, constant_time_compare from social_auth.store import DjangoOpenIDStore from social_auth.backends.exceptions import StopPipeline, AuthException, \ AuthFailed, AuthCanceled, \ diff --git a/social_auth/utils.py b/social_auth/utils.py index afc8177..7c9a1f6 100644 --- a/social_auth/utils.py +++ b/social_auth/utils.py @@ -35,9 +35,6 @@ except ImportError: # django < 1.4 return ''.join([random.choice(allowed_chars) for i in range(length)]) -get_random_string = random_string - - try: from django.utils.timezone import utc as django_utc except ImportError: # django < 1.4 @@ -55,9 +52,23 @@ except ImportError: # django < 1.4 def dst(self, dt): return timedelta(0) - django_utc = None + django_utc = UTC() + +try: + from django.utils.crypto import constant_time_compare as ct_compare +except ImportError: # django < 1.4 + def ct_compare(val1, val2): + if len(val1) != len(val2): + return False + result = 0 + for x, y in zip(val1, val2): + result |= ord(x) ^ ord(y) + return result == 0 + +get_random_string = random_string +constant_time_compare = ct_compare utc = django_utc