Skip to content

Commit

Permalink
Django 1.7 and Python 3 compatability tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoyles87 committed Dec 10, 2014
1 parent 19d79ec commit af6ada9
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 5 deletions.
4 changes: 4 additions & 0 deletions django_clickbank/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals

__version__ = '0.2.8'
__url__ = 'https://github.com/sureiya/django-clickbank'
default_app_config = "django_clickbank.apps.DjangoClickbankConfig"
4 changes: 4 additions & 0 deletions django_clickbank/migrations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals

"""
Django migrations for django_clickbank app
Expand Down
3 changes: 3 additions & 0 deletions django_clickbank/south_migrations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
4 changes: 4 additions & 0 deletions django_clickbank/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals

from .test_helpers import *
from .test_views import *
5 changes: 5 additions & 0 deletions django_clickbank/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#see http://django.readthedocs.org/en/latest/releases/1.7.html#standalone-scripts
import django
django.setup()


from django.core.urlresolvers import reverse
from django.test import TestCase, Client
from django.test.utils import override_settings
Expand Down
3 changes: 3 additions & 0 deletions django_clickbank/util/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
8 changes: 4 additions & 4 deletions django_clickbank/util/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def verify_secret(post, secret_key=settings.CLICKBANK_SECRET_KEY):
data.append(post[field])
data.append(secret_key)
hash_string = '|'.join(data)
hex_digest = unicode(hashlib.sha1(hash_string).hexdigest()[:8].upper(), encoding='ascii')
hex_digest = hashlib.sha1(hash_string.encode('utf-8')).hexdigest()[:8].upper()
verification = post_hash == hex_digest
#zimport ipdb; ipdb.set_trace()
logger.debug('Verification: cverify = {0}'.format(repr(post_hash)))
Expand All @@ -41,7 +41,7 @@ def verify_secret(post, secret_key=settings.CLICKBANK_SECRET_KEY):
logger.debug('Verification: {0}'.format(verification))

return verification
except Exception, e:
except Exception as e:
raise
logger.debug('Notification Verification Failed {0}'.format(e))
return False
Expand All @@ -66,7 +66,7 @@ def make_secret(post, secret_key=settings.CLICKBANK_SECRET_KEY):
data.append(post[field])
data.append(secret_key)
hash_string = '|'.join(data)
return hashlib.sha1(hash_string).hexdigest()[:8].upper()
return hashlib.sha1(hash_string.encode('utf-8')).hexdigest()[:8].upper()


class conditional_decorator(object):
Expand Down Expand Up @@ -139,7 +139,7 @@ def remap_post(data):
u'ccustshippingstate': u'shipping_province'
}

for key, value in data.iteritems():
for key, value in data.items():
if key in MAPPING:
remapped_data[MAPPING[key]] = value

Expand Down
2 changes: 1 addition & 1 deletion django_clickbank/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def ipn(request, get=False):
# We want to be able to do more with it before the post_create and post_save signals
# are called.
notification = form.save(commit=False)
except Exception, e:
except Exception as e:
raise NotificationFailedValidation(e)
else:
if '__all__' in form.errors:
Expand Down
10 changes: 10 additions & 0 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,19 @@
'django_nose',
],
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner',
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
)


#see http://django.readthedocs.org/en/latest/releases/1.7.html#standalone-scripts
import django
django.setup()


def runtests(*test_args):
parent = dirname(abspath(__file__))
sys.path.insert(0, parent)
Expand Down

0 comments on commit af6ada9

Please sign in to comment.