Skip to content

Commit

Permalink
Should fix #123, base_uri was set to fp when info was first extracted…
Browse files Browse the repository at this point in the history
… as a side effect of an img request
  • Loading branch information
Jon Stroop committed Sep 9, 2014
1 parent ad6f2ce commit a5821d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions loris/img_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ def scale_dim(dim_len, scale):
return int(ceil(dim_len * 1.0/scale))

def to_dict(self):
logger.debug('self.ident in to_dict: %s' % (self.ident,))
d = {}
d['@context'] = CONTEXT
d['@id'] = self.ident
Expand Down Expand Up @@ -378,6 +379,7 @@ def __getitem__(self, ident):

def __setitem__(self, ident, info):
# to fs
logger.debug('ident passed to __setitem__: %s' % (ident,))
info_fp = self._get_info_fp(ident)
dp = os.path.dirname(info_fp)
if not os.path.exists(dp):
Expand Down
17 changes: 13 additions & 4 deletions loris/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def route(self, request):
size = slices.pop()
region = slices.pop()

return self.get_img(request, ident, region, size, rotation, quality, fmt)
return self.get_img(request, ident, region, size, rotation, quality, fmt, base_uri)
except ValueError:
return BadRequestResponse('could not parse image request')
# info
Expand Down Expand Up @@ -457,12 +457,20 @@ def _get_info(self,ident,request,base_uri,src_fp=None,src_format=None):
logger.debug('Format: %s' % (src_format,))
logger.debug('File Path: %s' % (src_fp,))
logger.debug('Identifier: %s' % (ident,))
logger.debug('Base URI: %s' % (base_uri,))

# get the info
info = ImageInfo.from_image_file(base_uri, src_fp, src_format, formats)

# store
if self.enable_caching:
# Elusive bug. For some reason, every once in a while, ident
# is the path on the file system rather than the URI.
# One thing that's confusing about it is that here 'ident' is
# used to mean the identifier slice of the request, and in the
# info cache it's used this way, but ImageInfo.ident is URI
# that goes in @id.
logger.debug('ident used to store %s: %s' % (ident,ident))
self.info_cache[ident] = info
# pick up the timestamp... :()
info,last_mod = self.info_cache[ident]
Expand All @@ -471,7 +479,7 @@ def _get_info(self,ident,request,base_uri,src_fp=None,src_format=None):

return (info,last_mod)

def get_img(self, request, ident, region, size, rotation, quality, target_fmt):
def get_img(self, request, ident, region, size, rotation, quality, target_fmt, base_uri):
'''Get an Image.
Args:
request (Request):
Expand Down Expand Up @@ -518,7 +526,7 @@ def get_img(self, request, ident, region, size, rotation, quality, target_fmt):
# resolve the identifier
src_fp, src_format = self.resolver.resolve(ident)
# hand the Image object its info
info = self._get_info(ident, request, src_fp, src_format)[0]
info = self._get_info(ident, request, base_uri, src_fp, src_format)[0]
image_request.info = info
# we need to do the above to set the canonical link header

Expand All @@ -532,7 +540,8 @@ def get_img(self, request, ident, region, size, rotation, quality, target_fmt):
src_fp, src_format = self.resolver.resolve(ident)

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

# 3. Check that we can make the quality requested
Expand Down

0 comments on commit a5821d6

Please sign in to comment.