PK†¦8“×2EGG-INFO/dependency_links.txt PK†¦8Aé"Ô::EGG-INFO/entry_points.txt[trac.plugins] includemacro.macros = includemacro.macros PK†¦8nÂtg}}EGG-INFO/PKG-INFOMetadata-Version: 1.0 Name: TracIncludeMacro Version: 1.1 Summary: Include the contents of external URLs and other Trac objects in a wiki page. Home-page: http://trac-hacks.org/wiki/IncludeMacro Author: Noah Kantrowitz Author-email: noah@coderanger.net License: BSD Description: UNKNOWN Keywords: trac 0.10 plugin wiki include macro Platform: UNKNOWN Classifier: Framework :: Trac PK†¦8‹Ó OEGG-INFO/SOURCES.txtsetup.py TracIncludeMacro.egg-info/PKG-INFO TracIncludeMacro.egg-info/SOURCES.txt TracIncludeMacro.egg-info/dependency_links.txt TracIncludeMacro.egg-info/entry_points.txt TracIncludeMacro.egg-info/top_level.txt includemacro/__init__.py includemacro/macros.py PK†¦8 Né EGG-INFO/top_level.txtincludemacro PK†¦8“×2EGG-INFO/zip-safe PKJ¦8includemacro/__init__.pyPK†¦8X̘+‹‹includemacro/__init__.pyc;ò = Hc@sdS(N((((s;build/bdist.darwin-8.11.1-i386/egg/includemacro/__init__.pys?sPK©¦8ùe;—mmincludemacro/macros.py# TracIncludeMacro macros import urllib2 from HTMLParser import HTMLParseError from trac.core import * from trac.wiki.macros import WikiMacroBase from trac.wiki.formatter import system_message from trac.wiki.model import WikiPage from trac.mimeview.api import Mimeview, get_mimetype from trac.perm import IPermissionRequestor from trac.util.html import Markup __all__ = ['IncludeMacro'] class IncludeMacro(WikiMacroBase): """A macro to include other resources in wiki pages. More documentation to follow. """ implements(IPermissionRequestor) # Default output formats for sources that need them default_formats = { 'wiki': 'text/x-trac-wiki', } # IWikiMacroProvider methods def render_macro(self, req, name, content): args = [x.strip() for x in content.split(',')] if len(args) == 1: args.append(None) elif len(args) != 2: return system_message('Invalid arguments "%s"'%content) # Pull out the arguments source, dest_format = args try: source_format, source_obj = source.split(':', 1) except ValueError: # If no : is present, assume its a wiki page source_format, source_obj = 'wiki', source # Apply a default format if needed if dest_format is None: try: dest_format = self.default_formats[source_format] except KeyError: pass if source_format in ('http', 'https', 'ftp'): # Since I can't really do recursion checking, and because this # could be a source of abuse allow selectively blocking it. # RFE: Allow blacklist/whitelist patterns for URLS. # RFE: Track page edits and prevent unauthorized users from ever entering a URL include. if not req.perm.has_permission('INCLUDE_URL'): self.log.info('IncludeMacro: Blocking attempt by %s to include URL %s on page %s', req.authname, source, req.path_info) return '' try: urlf = urllib2.urlopen(source) out = urlf.read() except urllib2.URLError, e: return system_message('Error while retrieving file', str(e)) except TracError, e: return system_message('Error while previewing', str(e)) elif source_format == 'wiki': # XXX: Check for recursion in page includes. if not req.perm.has_permission('WIKI_VIEW'): return '' page = WikiPage(self.env, source_obj) if not page.exists: return system_message('Wiki page %s does not exist'%source_obj) out = page.text elif source_format == 'source': if not req.perm.has_permission('FILE_VIEW'): return '' repo = self.env.get_repository(req.authname) node = repo.get_node(source_obj) out = node.get_content().read() if dest_format is None: dest_format = node.content_type or get_mimetype(source_obj, out) # RFE: Add ticket: and comment: sources. # RFE: Add attachment: source. else: return system_message('Unsupported include source %s'%source) # If we have a preview format, use it if dest_format: out = Mimeview(self.env).render(req, dest_format, out) # Escape if needed if not self.config.getbool('wiki', 'render_unsafe_content', False): try: out = Markup(out).sanitize() except HTMLParseError: out = Markup(out).escape() return out # IPermissionRequestor methods def get_permission_actions(self): yield 'INCLUDE_URL' PK†¦8“  ¶aaincludemacro/macros.pyc;ò î Hc@s”dkZdklZdkTdklZdklZdkl Z dk l Z l Z dk lZdklZd gZd efd „ƒYZdS( N(sHTMLParseError(s*(s WikiMacroBase(ssystem_message(sWikiPage(sMimeviews get_mimetype(sIPermissionRequestor(sMarkups IncludeMacrocBs9tZdZeeƒhdd