# HG changeset patch # User Tero Marttila # Date 1412369762 -10800 # Node ID e1e0c8099c8b355354d2a99aded8b158baa2bc52 # Parent 7c929ba47ba6f2e6837d4980f010cebc32bc115e pngtile.image: have BaseApplication.lookup_image() return type as well diff -r 7c929ba47ba6 -r e1e0c8099c8b pngtile/application.py --- a/pngtile/application.py Fri Oct 03 23:18:42 2014 +0300 +++ b/pngtile/application.py Fri Oct 03 23:56:02 2014 +0300 @@ -31,7 +31,7 @@ """ Lookup image by request path. - Returns name, path. + Returns name, path, type. For dirs, type will be None. """ if not os.path.isdir(self.image_root): @@ -49,23 +49,24 @@ if not os.path.exists(path): raise exceptions.NotFound(name) - - return name, path + + # determine time + if os.path.isdir(path): + return name, path, None + else: + basename, type = path.rsplit('.', 1) + + return name, path, type def get_image (self, url): """ Return Image object. """ - name, path = self.lookup_path(url) + name, path, type = self.lookup_path(url) - if os.path.isdir(path): - raise exceptions.BadRequest("Is a directory: {name}".format(name=name)) - - basename, file_type = path.rsplit('.', 1) - - if file_type not in self.IMAGE_TYPES: - raise exceptions.BadRequest("Not a supported image: {name}: {type}".format(name=name, type=file_type)) + if type not in self.IMAGE_TYPES: + raise exceptions.BadRequest("Not a supported image: {name}: {type}".format(name=name, type=type)) # get Image object image = self.image_cache.get(path) diff -r 7c929ba47ba6 -r e1e0c8099c8b pngtile/image.py --- a/pngtile/image.py Fri Oct 03 23:18:42 2014 +0300 +++ b/pngtile/image.py Fri Oct 03 23:56:02 2014 +0300 @@ -190,26 +190,12 @@ Handle request for an image """ - name, path = self.lookup_path(request.path) + name, path, type = self.lookup_path(request.path) - # determine type - if '/' in name: - _, name_base = name.rsplit('/', 1) - else: - name_base = name - - if '.' in name_base: - name_base, name_type = name_base.rsplit('.', 1) - else: - name_type = None - # determine handler - if os.path.isdir(path): + if not type: return self.handle_dir(request, name, path) - elif name_type and name_type in self.IMAGE_TYPES: + else: return self.handle_image(request, name, path) - else: - raise exceptions.NotFound(path) -