Skip to content

Commit

Permalink
Improve unicode stability
Browse files Browse the repository at this point in the history
Deprecate Django<1.7
  • Loading branch information
Thomas Vavrys committed Jul 18, 2016
1 parent e4c9afc commit 40c57ef
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 80 deletions.
14 changes: 0 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,6 @@ language: python

matrix:
include:
- env: TOXENV=django14-py26
python: 2.6
- env: TOXENV=django14-py27
python: 2.7
- env: TOXENV=django15-py26
python: 2.6
- env: TOXENV=django15-py27
python: 2.7
- env: TOXENV=django16-py26
python: 2.6
- env: TOXENV=django16-py27
python: 2.7
- env: TOXENV=django16-py33
python: 3.3
- env: TOXENV=django17-py27
python: 2.7
- env: TOXENV=django17-py33
Expand Down
7 changes: 6 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Changelog
---------

Version 2.0.0
`````````````

- Deprecates Django<1.7
- Improves unicode stability

Version 1.3.0
`````````````
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ Documentation is available at http://pythonhosted.org/django-memoize/.
Requirements
------------

Django >= 1.4 is required.
Django >= 1.7 is required.
37 changes: 7 additions & 30 deletions memoize/__init__.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,20 @@
# -*- coding: utf-8 -*-
__version__ = '1.3.1'
__version__ = '2.0.0'
__versionfull__ = __version__

import base64
import functools
import hashlib
import inspect
import logging
import string
import uuid

from django.conf import settings
from django.core.cache import cache as default_cache

try:
from django.core.cache.backends.base import DEFAULT_TIMEOUT
except ImportError: # Django < 1.6 compatibility
DEFAULT_TIMEOUT = 300

from ._compat import PY2
from django.core.cache.backends.base import DEFAULT_TIMEOUT
from django.utils.encoding import force_bytes

logger = logging.getLogger(__name__)

# Used to remove control characters and whitespace from cache keys.
valid_chars = set(string.ascii_letters + string.digits + '_.')
delchars = ''.join(c for c in map(chr, range(256)) if c not in valid_chars)
if PY2:
null_control = (None, delchars)
else:
null_control = (dict((k, None) for k in delchars),)


def function_namespace(f, args=None):
"""
Expand Down Expand Up @@ -71,11 +56,9 @@ def function_namespace(f, args=None):
name = f.__name__

ns = '.'.join((module, name))
ns = ns.translate(*null_control)

if instance_token:
ins = '.'.join((module, name, instance_token))
ins = ins.translate(*null_control)
else:
ins = None

Expand Down Expand Up @@ -134,7 +117,7 @@ def _memvname(self, funcname):
return funcname + '_memver'

def _memoize_make_version_hash(self):
return base64.b64encode(uuid.uuid4().bytes)[:6].decode('utf-8')
return uuid.uuid4().hex

def _memoize_version(self, f, args=None,
reset=False, delete=False, timeout=DEFAULT_TIMEOUT):
Expand Down Expand Up @@ -203,15 +186,9 @@ def make_cache_key(f, *args, **kwargs):
else:
keyargs, keykwargs = args, kwargs

try:
updated = "{0}{1}{2}".format(altfname, keyargs, keykwargs)
except AttributeError:
updated = "%s%s%s" % (altfname, keyargs, keykwargs)

cache_key = hashlib.md5()
cache_key.update(updated.encode('utf-8'))
cache_key = base64.b64encode(cache_key.digest())[:16]
cache_key = cache_key.decode('utf-8')
cache_key = hashlib.md5(
force_bytes((altfname, keyargs, keykwargs))
).hexdigest()
cache_key += version_data

if self.cache_prefix:
Expand Down
22 changes: 0 additions & 22 deletions memoize/_compat.py

This file was deleted.

Empty file removed memoize/models.py
Empty file.
7 changes: 2 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

setup(
name='django-memoize',
version='1.3.1',
version='2.0.0',
packages=['memoize'],
include_package_data=True,
license='BSD License',
Expand All @@ -23,7 +23,7 @@
author_email='tvavrys@sleio.com',
long_description=__doc__,
install_requires=[
'django >= 1.4'
'django >= 1.7'
],
classifiers=[
'Development Status :: 5 - Production/Stable',
Expand All @@ -39,9 +39,6 @@
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Framework :: Django',
'Framework :: Django :: 1.4',
'Framework :: Django :: 1.5',
'Framework :: Django :: 1.6',
'Framework :: Django :: 1.7',
'Framework :: Django :: 1.8',
'Framework :: Django :: 1.9',
Expand Down
Empty file removed tests/models.py
Empty file.
7 changes: 0 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
[tox]
envlist =
django14-py{26,27}
django15-py{26,27}
django16-py{26,27,33}
django17-py{27,33,34}
django18-py{27,33,34,35}
django19-py{27,34,35}

[testenv]
basepython =
py26: python2.6
py27: python2.7
py33: python3.3
py34: python3.4
py35: python3.5

deps =
django14: Django>=1.4,<1.5
django15: Django>=1.5,<1.6
django16: Django>=1.6,<1.7
django17: Django>=1.7,<1.8
django18: Django>=1.8,<1.9
django19: Django<1.10
Expand Down

0 comments on commit 40c57ef

Please sign in to comment.