From: W. Trevor King Date: Sun, 12 Aug 2012 22:53:00 +0000 (-0400) Subject: Pass stream into ._error() calls in gallery.py. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=6506f908b65778cb17ef200560c2873babeb48b6;p=mw2txt.git Pass stream into ._error() calls in gallery.py. Avoids 502 errors when ._response() tries to .write() when stream is None. --- diff --git a/posts/gallery/gallery.py b/posts/gallery/gallery.py index a5354fc..7746061 100755 --- a/posts/gallery/gallery.py +++ b/posts/gallery/gallery.py @@ -216,7 +216,7 @@ class CGIGalleryServer (object): if not url.startswith(self._base_url): LOG.error('cannot convert {} to a relative URL of {}'.format( url, self._base_url)) - return self._error(404) + return self._error(404, stream=stream) if url == self._base_url: return None return url[len(self._base_url):] @@ -270,7 +270,7 @@ class CGIGalleryServer (object): LOG.debug('index page') return self._directory(self._base_path, stream=stream) - def _thumb(self, image, max_width=None, max_height=None): + def _thumb(self, image, max_width=None, max_height=None, stream=None): if not _os_path.exists(self._cache_path): _os.makedirs(self._cache_path) dirname,filename = _os_path.split(image) @@ -285,7 +285,7 @@ class CGIGalleryServer (object): image_path = _os_path.join(self._base_path, image) if not _os_path.isfile(image_path): LOG.error('image path for thumbnail does not exist') - return self._error(404) + return self._error(404, stream=stream) if (not _os_path.isfile(thumb_path) or _os_path.getmtime(image_path) > _os_path.getmtime(thumb_path)): invoke(['convert', '-format', 'png', '-strip', '-quality', '95', @@ -294,7 +294,7 @@ class CGIGalleryServer (object): thumb_path]) return thumb_url - def _mp4(self, video, *args): + def _mp4(self, video, stream=None): if not video.endswith('.mov'): LOG.error("can't translate {} to MPEGv4".format(video)) dirname,filename = _os_path.split(video) @@ -307,7 +307,7 @@ class CGIGalleryServer (object): mp4_path = _os_path.join(cache_dir, mp4_filename) if not _os_path.isfile(video): LOG.error('source video path does not exist') - return self._error(404) + return self._error(404, stream=stream) if (not _os_path.isfile(mp4_path) or _os_path.getmtime(video) > _os_path.getmtime(mp4_path)): arg = ['ffmpeg', '-i', video, '-acodec', 'libfaac', '-aq', '200', @@ -319,7 +319,7 @@ class CGIGalleryServer (object): invoke(arg) return self._url(mp4_url) - def _ogv(self, video, *args): + def _ogv(self, video, stream=None): if not video.endswith('.mov'): LOG.error("can't translate {} to Ogg Video".format(video)) dirname,filename = _os_path.split(video) @@ -332,7 +332,7 @@ class CGIGalleryServer (object): ogv_path = _os_path.join(cache_dir, ogv_filename) if not _os_path.isfile(video): LOG.error('source video path does not exist') - return self._error(404) + return self._error(404, stream=stream) if (not _os_path.isfile(ogv_path) or _os_path.getmtime(video) > _os_path.getmtime(ogv_path)): arg = ['ffmpeg2theora', '--optimize'] @@ -348,18 +348,19 @@ class CGIGalleryServer (object): except IOError: return None - def _get_image_video(self, path, fallback=None): + def _get_image_video(self, path, fallback=None, stream=None): base_path = image_base(path) for extension in VIDEO_EXTENSIONS: video_path = base_path + extension if _os_path.isfile(video_path): - return self._video(video_path, fallback=fallback) + return self._video( + video_path, fallback=fallback, stream=stream) return None - def _captioned_video(self, path, href=None): - img = self._image(path, max_width=640, max_height=480) + def _captioned_video(self, path, href=None, stream=None): + img = self._image(path, max_width=640, max_height=480, stream=stream) caption = self._get_image_caption(path) - video = self._get_image_video(path, fallback=[img]) + video = self._get_image_video(path, fallback=[img], stream=stream) content = [] if video: content.extend(video) @@ -374,7 +375,7 @@ class CGIGalleryServer (object): content.append('

{}

'.format(caption)) return content - def _video(self, video, fallback=None, **kwargs): + def _video(self, video, fallback=None, stream=None, **kwargs): if fallback is None: fallback = [ '

Your browser does not support the <video> tag, try', @@ -382,8 +383,8 @@ class CGIGalleryServer (object): '

', ] fallback = [' '+line for line in fallback] - ogv = self._ogv(video) - mp4 = self._mp4(video) + ogv = self._ogv(video, stream=stream) + mp4 = self._mp4(video, stream=stream) return [ '

', ('