Ticket #9058: configure-preview-limit-by-mimetype.diff
File configure-preview-limit-by-mimetype.diff, 2.1 KB (added by , 12 years ago) |
---|
-
trac/mimeview/api.py
633 633 and a Python regexp used for matching filenames, separated by a colon 634 634 (":"). (''since 1.0'')""") 635 635 636 preview_limit_map = ListOption('mimeviewer', 'preview_limit_map', 637 'text/x-diff:262144,text/x-rst:262144', 638 doc="""List of specific preview limits per MIME type. (''local extension'')""") 639 636 640 treat_as_binary = ListOption('mimeviewer', 'treat_as_binary', 637 641 'application/octet-stream, application/pdf, application/postscript, ' 638 642 'application/msword,application/rtf,', … … 642 646 def __init__(self): 643 647 self._mime_map = None 644 648 self._mime_map_patterns = None 649 self._preview_limit_map = None 645 650 646 651 # Public API 647 652 … … 909 914 self._mime_map[keyword] = assocations[0] 910 915 return self._mime_map 911 916 917 @property 918 def preview_limit_map(self): 919 # fill preview limit map from configuration 920 if not self._preview_limit_map: 921 self._preview_limit_map = {} 922 for mapping in self.config['mimeviewer'].getlist('preview_limit_map'): 923 if ':' in mapping: 924 values = mapping.split(':') 925 self._preview_limit_map[values[0]] = int(values[1]) 926 return self._preview_limit_map 927 912 928 def get_mimetype(self, filename, content=None): 913 929 """Infer the MIME type from the `filename` or the `content`. 914 930 … … 998 1014 'max_file_size_reached': False, 999 1015 'rendered': None, 1000 1016 } 1001 if length >= self.max_preview_size: 1017 preview_limit = self.preview_limit_map.get(ct_mimetype(mimetype), 1018 self.max_preview_size) 1019 if length >= preview_limit: 1020 data['max_file_size'] = preview_limit 1002 1021 data['max_file_size_reached'] = True 1003 1022 else: 1004 1023 result = self.render(context, mimetype, content, filename, url,