Example #1
0
 def _tileFromHash(cls, item, x, y, z, mayRedirect=False, **kwargs):
     tileCache, tileCacheLock = getTileCache()
     if tileCache is None:
         return None
     if 'largeImage' not in item:
         return None
     if item['largeImage'].get('expected'):
         return None
     sourceName = item['largeImage']['sourceName']
     try:
         sourceClass = girder_tilesource.AvailableGirderTileSources[
             sourceName]
     except TileSourceException:
         return None
     classHash = sourceClass.getLRUHash(item, **kwargs)
     tileHash = sourceClass.__name__ + ' ' + classHash + ' ' + strhash(
         classHash) + strhash(*(x, y, z), mayRedirect=mayRedirect, **kwargs)
     try:
         if tileCacheLock is None:
             tileData = tileCache[tileHash]
         else:
             with tileCacheLock:
                 tileData = tileCache[tileHash]
         tileMime = TileOutputMimeTypes.get(kwargs.get('encoding'),
                                            'image/jpeg')
         return tileData, tileMime
     except (KeyError, ValueError):
         return None
Example #2
0
 def getLRUHash(*args, **kwargs):
     return strhash(
         super(TestTileSource, TestTileSource).getLRUHash(
             *args, **kwargs),
         kwargs.get('minLevel'), kwargs.get('maxLevel'),
         kwargs.get('tileWidth'), kwargs.get('tileHeight'),
         kwargs.get('fractal'))
Example #3
0
def _handleETag(key, item, *args, **kwargs):
    """
    Add or check an ETag header.

    :param key: key for making a distinc etag.
    :param item: item used for the item _id and updated timestamp.
    :param *args, **kwargs: additional arguments for generating an etag.
    """
    etag = hashlib.md5(strhash(key, str(item['_id']), *args, **kwargs).encode()).hexdigest()
    setResponseHeader('ETag', etag)
    conditions = [str(x) for x in cherrypy.request.headers.elements('If-Match') or []]
    if conditions and not (conditions == ['*'] or etag in conditions):
        raise cherrypy.HTTPError(
            412, 'If-Match failed: ETag %r did not match %r' % (etag, conditions))
    conditions = [str(x) for x in cherrypy.request.headers.elements('If-None-Match') or []]
    if conditions == ['*'] or etag in conditions:
        raise cherrypy.HTTPRedirect([], 304)
    # Explicitly set a max-ago to recheck the cahe after a while
    setResponseHeader('Cache-control', 'max-age=600')
Example #4
0
 def getLRUHash(*args, **kwargs):
     return strhash(
         super(PILFileTileSource,
               PILFileTileSource).getLRUHash(*args, **kwargs),
         kwargs.get('maxSize'))