Skip to content

Commit

Permalink
unquote identifiers before calculating cache path. Closes #122
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Stroop committed Sep 9, 2014
1 parent a5821d6 commit b679ee3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
12 changes: 6 additions & 6 deletions loris/img.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from loris_exception import ImageException
from urllib import unquote, quote_plus
from werkzeug.http import generate_etag
from urllib import unquote

logger = getLogger(__name__)

Expand Down Expand Up @@ -223,7 +224,7 @@ def __setitem__(self, image_request, fp):
# Does this make sense? It's a little strange because we already know
# the cache root in the webapp. We'll use the Image object (the key)
# to make any additional smlinks.
canonical_fp = path.join(self._links_root, image_request.c14n_cache_path)
canonical_fp = path.join(self._links_root, unquote(image_request.c14n_cache_path))
ImageCache._link(fp, canonical_fp)
if not image_request.is_canonical:
alt_fp = path.join(self._links_root, image_request.cache_path)
Expand All @@ -246,8 +247,7 @@ def get(self, image_request):
return None

def _get_cache_path(self, image_request):
return path.realpath(path.join(self._links_root, image_request.cache_path))




return path.realpath(path.join(self._links_root, unquote(image_request.cache_path)))
# Every request would need the info in order to determine the canonical path:
# return path.realpath(path.join(self._links_root, unquote(image_request.c14n_cache_path)))
# is it worth it?
5 changes: 3 additions & 2 deletions loris/img_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import json
import os
import struct
from urllib import unquote

try:
from collections import OrderedDict
Expand Down Expand Up @@ -320,10 +321,10 @@ def __init__(self, root, size=500):
self._lock = Lock()

def _get_info_fp(self,ident):
return os.path.join(self.root,ident,'info.json')
return os.path.join(self.root, unquote(ident), 'info.json')

def _get_color_profile_fp(self,ident):
return os.path.join(self.root,ident,'profile.icc')
return os.path.join(self.root, unquote(ident), 'profile.icc')

def get(self, ident):
'''
Expand Down
4 changes: 2 additions & 2 deletions loris/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def get_img(self, request, ident, region, size, rotation, quality, target_fmt, b
# accessed, which mean we don't have to catch any exceptions here.
image_request = img.ImageRequest(ident, region, size, rotation, quality, target_fmt)

logger.debug(image_request.request_path)
logger.debug('Image Request Path: %s' % (image_request.request_path,))

if self.enable_caching:
in_cache = image_request in self.img_cache
Expand Down Expand Up @@ -539,8 +539,8 @@ def get_img(self, request, ident, region, size, rotation, quality, target_fmt, b
# 1. Resolve the identifier
src_fp, src_format = self.resolver.resolve(ident)


# 2. Hand the Image object its info
# IT'S HERE
info = self._get_info(ident, request, base_uri, src_fp, src_format)[0]
image_request.info = info

Expand Down

0 comments on commit b679ee3

Please sign in to comment.