Changeset - 69725698aeae
[Not reviewed]
0 2 0
Ben Sturmfels (bsturmfels) - 2 years ago 2021-11-26 01:41:27
ben@sturm.com.au
Fix a encoding issues for future Python 3 support.
2 files changed with 2 insertions and 7 deletions:
0 comments (0 inline, 0 general)
www/conservancy/__init__.py
Show inline comments
...
 
@@ -10,13 +10,13 @@ from django.shortcuts import render as render_template_with_context
 
class ParameterValidator(object):
 
    def __init__(self, given_hash_or_params, params_hash_key=None):
 
        if params_hash_key is None:
 
            self.given_hash = given_hash_or_params
 
        else:
 
            self.given_hash = given_hash_or_params.get(params_hash_key)
 
        seed = getattr(settings, 'CONSERVANCY_SECRET_KEY', '')
 
        seed = getattr(settings, 'CONSERVANCY_SECRET_KEY', '').encode('utf-8')
 
        self.hasher = hashlib.sha256(seed)
 
        if isinstance(self.given_hash, basestring):
 
            self.hash_type = type(self.given_hash)
 
        else:
 
            self.hash_type = type(self.hasher.hexdigest())
 
        self.valid = None
www/conservancy/static/views.py
Show inline comments
...
 
@@ -29,18 +29,13 @@ def handler500(request):
 
    return handler(request, 500)
 

	
 
def index(request, *args, **kwargs):
 
    path = request.path.lstrip(u'/')
 
    if path.endswith(u'/'):
 
        path += u'index.html'
 
    try:
 
        path_bytes = path.encode(FILESYSTEM_ENCODING)
 
    except UnicodeEncodeError:
 
        # If the path can't be expressed on the filesystem, it must not exist.
 
        return handler404(request)
 
    fullpath = os.path.join(STATIC_ROOT, path_bytes)
 
    fullpath = os.path.join(STATIC_ROOT, path)
 
    if not os.path.exists(fullpath):
 
        return handler404(request)
 
    content_type, _ = mimetypes.guess_type(path)
 
    if content_type != 'text/html':
 
        return HttpResponse(open(fullpath, 'rb'), content_type)
 
    else:
0 comments (0 inline, 0 general)