Modify ↓
#13202 closed defect (fixed)
AttributeError: 'FileContentStream' object has no attribute 'seek'
Reported by: | Ryan J Ollos | Owned by: | Jun Omae |
---|---|---|---|
Priority: | normal | Component: | ArchiveViewerPlugin |
Severity: | normal | Keywords: | |
Cc: | Trac Release: | 1.0 |
Description
I get the following on Trac 1.0-stable and 1.2-stable:
12:14:49 Trac[api] WARNING: HTML preview using ZipRenderer with <RenderingContext <Resource u'repository:proj1, source:ArchiveViewer-0.1-py2.7.egg@132'>> failed: Traceback (most recent call last): File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/mimeview/api.py", line 814, in render rendered_content, filename, url) File "/Users/rjollos/Documents/Workspace/trac-dev/trac-hacks/archiveviewerplugin/1.0/archiveviewer/zip.py", line 125, in render zipfile = ZipFile(content.input) File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/zipfile.py", line 770, in __init__ self._RealGetContents() File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/zipfile.py", line 809, in _RealGetContents endrec = _EndRecData(fp) File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/zipfile.py", line 208, in _EndRecData fpin.seek(0, 2) AttributeError: 'FileContentStream' object has no attribute 'seek'
$ svn --version svn, version 1.9.5 (r1770682) compiled May 12 2017, 06:52:50 on x86_64-apple-darwin16.5.0 $ python --version Python 2.7.13
Issue appears to be associated with addition of FileContentStream
class in r11797.
Attachments (0)
Change History (8)
comment:1 Changed 8 years ago by
comment:2 follow-up: 6 Changed 8 years ago by
I consider it would be simple to use hasattr(content.input, 'seek')
(untested).
-
archiveviewerplugin/1.0/archiveviewer/zip.py
diff --git a/archiveviewerplugin/1.0/archiveviewer/zip.py b/archiveviewerplugin/1.0/archiveviewer/zip.py index 9b606f50d..0ad460ce8 100644
a b from datetime import datetime 12 12 from genshi.builder import tag 13 13 from genshi.core import QName 14 14 from genshi.filters.transform import Transformer, ENTER 15 try: 16 Stream = False 17 from svn.core import Stream 18 except ImportError: 19 pass 15 20 16 from trac.attachment import Attachment, AttachmentModule 21 17 from trac.core import Component, implements, TracError 22 18 from trac.mimeview.api import IHTMLPreviewRenderer, Mimeview … … from trac.web.chrome import web_context, add_stylesheet, add_link 33 29 from trac.web.href import Href 34 30 from trac.web.wsgi import _FileWrapper 35 31 from trac.wiki.api import IWikiSyntaxProvider 36 from zipfile import ZipFile , ZipExtFile32 from zipfile import ZipFile 37 33 import os 38 34 import re 39 35 … … class ZipRenderer(Component): 117 113 118 114 def render(self, context, mimetype, content, filename=None, url=None): 119 115 if content and content.input: 120 max_size = self.env.config.getint('attachment', 'max_zip_size', default=2097152)121 if (Stream and isinstance(content.input, Stream)) \122 or ZipExtFile and isinstance(content.input, ZipExtFile):123 zipfile = ZipFile(StringIO(content.input.read(max_size)))124 else:125 zipfile = ZipFile(content.input)116 f = content.input 117 if not hasattr(f, 'seek'): 118 max_size = self.config.getint('attachment', 'max_zip_size', 119 2097152) 120 f = StringIO(f.read(max_size)) 121 zipfile = ZipFile(f) 126 122 listitems = [] 127 123 for info in zipfile.infolist(): 128 124 resource = context.resource.child('zip', info.filename)
Also, [attachment] max_zip_size
can be -1 to disable download as zip. I think we should check it.
comment:3 Changed 8 years ago by
Owner: | changed from matobaa to Ryan J Ollos |
---|---|
Status: | new → accepted |
Thanks, that looks good. I will test and commit.
comment:6 Changed 8 years ago by
comment:7 Changed 8 years ago by
Resolution: | → fixed |
---|---|
Status: | accepted → closed |
comment:8 Changed 8 years ago by
Owner: | changed from Ryan J Ollos to Jun Omae |
---|
Note: See
TracTickets for help on using
tickets.
Proposed fix, tested with Trac 1.0, 1.0-stable and 1.2-stable:
archiveviewer/zip.py