def process_request(self, req): ''' serve the request but check wether the file realy is in cache ( absolute second part, f.e. an attemp to access restricted areas ) for those request, trying access files anywhere, serve an Exception, otherwise let let it handle send_file, which checks for existence and serves either the file or an error ''' path = PPHTDPathSelOption.absbasepath() if req.path_info.startswith('/'): slashes = 2 else: slashes = 1 name = req.path_info[(slashes + len(PPConstant.change_ticket_suffix)):] self.conf = PPConfiguration(self.env) self.req = req done = self.update_connections() if done: name = 'crystal_project/16x16/state/ok.png' accessname = os.path.join(path, name) else: #name = 'images/crystal_project/16x16/messagebox/critical.png' raise TracError( 'Ticket Save Fail: %s --> %s ' % (self.get_args('ppdep_from'), self.get_args('ppdep_to'))) return req.send_file(accessname, get_mimetype(accessname))
def render_macro(self, req, name, content): # Pull out the arguments source_obj = str(content) dest_format = "text/x-trac-wiki" 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) ctxt = Context.from_request(req, 'source', source_obj) # RFE: Add ticket: and comment: sources. <NPK> # RFE: Add attachment: source. <NPK> # If we have a preview format, use it # Escape if needed # if not self.config.getbool('wiki', 'render_unsafe_content', False): # try: # out = HTMLParser(StringIO(out)).parse() | HTMLSanitizer() # except ParseError: # out = escape(out) # reader = str(out).split("||") need_header = 1 foo = (str( WikiTextRenderer(self.env).render(ctxt, "text/x-trac-wiki", str(out)))) return foo
def process_request( self, req ): ''' serve the request but check wether the file realy is in cache ( absolute second part, f.e. an attemp to access restricted areas ) for those request, trying access files anywhere, serve an Exception, otherwise let let it handle send_file, which checks for existence and serves either the file or an error ''' path = PPHTDPathSelOption.absbasepath() if req.path_info.startswith('/'): slashes = 2 else: slashes = 1 name = req.path_info[(slashes+len(PPConstant.change_ticket_suffix)):] self.conf = PPConfiguration( self.env ) self.req = req done = self.update_connections() if done: name = 'crystal_project/16x16/state/ok.png' accessname = os.path.join( path, name ) else: #name = 'images/crystal_project/16x16/messagebox/critical.png' raise TracError( 'Ticket Save Fail: %s --> %s ' % (self.get_args('ppdep_from'), self.get_args('ppdep_to') ) ) return req.send_file( accessname, get_mimetype( accessname ) )
def post_process_request(self, req, template, data, content_type): """Post process request filter. Removes all trac provided css if required""" if template is None and data is None and \ sys.exc_info() == (None, None, None): return template, data, content_type def is_active_theme(): is_active = False active_theme = ThemeEngineSystem(self.env).theme if active_theme is not None: this_theme_name = self.get_theme_names().next() is_active = active_theme['name'] == this_theme_name return is_active req.chrome['labels'] = self._get_whitelabelling() if data is not None: data['product_list'] = \ ProductModule.get_product_list(self.env, req) links = req.chrome.get('links', {}) # replace favicon if appropriate if self.env.project_icon == 'common/trac.ico': bh_icon = 'theme/img/bh.ico' new_icon = { 'href': req.href.chrome(bh_icon), 'type': get_mimetype(bh_icon) } if links.get('icon'): links.get('icon')[0].update(new_icon) if links.get('shortcut icon'): links.get('shortcut icon')[0].update(new_icon) is_active_theme = is_active_theme() if self.disable_all_trac_css and is_active_theme: if self.disable_all_trac_css: stylesheets = links.get('stylesheet', []) if stylesheets: path = '/chrome/common/css/' _iter = ([ss, ss.get('href', '')] for ss in stylesheets) links['stylesheet'] = \ [ss for ss, href in _iter if not path in href or href.rsplit('/', 1)[-1] in self.BLOODHOUND_KEEP_CSS] template, modifier = \ self.BLOODHOUND_TEMPLATE_MAP.get(template, (template, None)) if modifier is not None: modifier = getattr(self, modifier) modifier(req, template, data, content_type, is_active_theme) if is_active_theme and data is not None: data['responsive_layout'] = \ self.env.config.getbool('bloodhound', 'responsive_layout', 'true') data['bhrelations'] = \ self.env.config.getbool('components', 'bhrelations.*', 'false') return template, data, content_type
def post_process_request(self, req, template, data, content_type): """Post process request filter. Removes all trac provided css if required""" if template is None and data is None and \ sys.exc_info() == (None, None, None): return template, data, content_type def is_active_theme(): is_active = False active_theme = ThemeEngineSystem(self.env).theme if active_theme is not None: this_theme_name = self.get_theme_names().next() is_active = active_theme['name'] == this_theme_name return is_active req.chrome['labels'] = self._get_whitelabelling() if data is not None: data['product_list'] = \ ProductModule.get_product_list(self.env, req) links = req.chrome.get('links', {}) # replace favicon if appropriate if self.env.project_icon == 'common/trac.ico': bh_icon = 'theme/img/bh.ico' new_icon = {'href': req.href.chrome(bh_icon), 'type': get_mimetype(bh_icon)} if links.get('icon'): links.get('icon')[0].update(new_icon) if links.get('shortcut icon'): links.get('shortcut icon')[0].update(new_icon) is_active_theme = is_active_theme() if self.disable_all_trac_css and is_active_theme: if self.disable_all_trac_css: stylesheets = links.get('stylesheet', []) if stylesheets: path = '/chrome/common/css/' _iter = ([ss, ss.get('href', '')] for ss in stylesheets) links['stylesheet'] = \ [ss for ss, href in _iter if not path in href or href.rsplit('/', 1)[-1] in self.BLOODHOUND_KEEP_CSS] template, modifier = \ self.BLOODHOUND_TEMPLATE_MAP.get(template, (template, None)) if modifier is not None: modifier = getattr(self, modifier) modifier(req, template, data, content_type, is_active_theme) if is_active_theme and data is not None: data['responsive_layout'] = \ self.env.config.getbool('bloodhound', 'responsive_layout', 'true') data['bhrelations'] = \ self.env.config.getbool('components', 'bhrelations.*', 'false') return template, data, content_type
def test_from_content_using_CONTENT_RE(self): self.assertEqual('text/x-python', get_mimetype('xxx', """ #!/usr/bin/python # This is a python script """)) self.assertEqual('text/x-ksh', get_mimetype('xxx', """ #!/bin/ksh # This is a shell script """)) self.assertEqual('text/x-python', get_mimetype('xxx', """ # -*- Python -*- # This is a python script """)) self.assertEqual('text/x-ruby', get_mimetype('xxx', """ # -*- mode: ruby -*- # This is a ruby script """))
def get_icon_data(self, req): icon = {} icon_src = icon_abs_src = self.env.project_icon if icon_src: if not icon_src.startswith('/') and icon_src.find('://') == -1: if '/' in icon_src: icon_abs_src = req.abs_href.chrome(icon_src) icon_src = req.href.chrome(icon_src) else: icon_abs_src = req.abs_href.chrome('common', icon_src) icon_src = req.href.chrome('common', icon_src) mimetype = get_mimetype(icon_src) icon = { 'src': icon_src, 'abs_src': icon_abs_src, 'mimetype': mimetype } return icon
def post_process_request(self, req, template, data, content_type): """Post process request filter. Removes all trac provided css if required""" def is_active_theme(): is_active = False active_theme = ThemeEngineSystem(self.env).theme if active_theme is not None: this_theme_name = self.get_theme_names().next() is_active = active_theme['name'] == this_theme_name return is_active links = req.chrome.get('links', {}) # replace favicon if appropriate if self.env.project_icon == 'common/trac.ico': bh_icon = 'theme/img/bh.ico' new_icon = { 'href': req.href.chrome(bh_icon), 'type': get_mimetype(bh_icon) } if links.get('icon'): links.get('icon')[0].update(new_icon) if links.get('shortcut icon'): links.get('shortcut icon')[0].update(new_icon) is_active_theme = is_active_theme() if self.disable_all_trac_css and is_active_theme: if self.disable_all_trac_css: stylesheets = links.get('stylesheet', []) if stylesheets: path = req.base_path + '/chrome/common/css/' _iter = ([ss, ss.get('href', '')] for ss in stylesheets) links['stylesheet'] = [ ss for ss, href in _iter if not href.startswith(path) or href.rsplit('/', 1)[-1] in self.BLOODHOUND_KEEP_CSS ] template, modifier = self.BLOODHOUND_TEMPLATE_MAP.get( template, (template, None)) if modifier is not None: modifier = getattr(self, modifier) modifier(req, template, data, content_type, is_active_theme) return template, data, content_type
def process_request(self, req): prefix = req.args['prefix'] filename = req.args['filename'] dirs = [] for provider in self.template_providers: for dir in [ os.path.normpath(dir[1]) for dir in provider.get_htdocs_dirs() or [] if dir[0] == prefix and dir[1] ]: dirs.append(dir) path = os.path.normpath(os.path.join(dir, filename)) if os.path.commonprefix([dir, path]) != dir: raise TracError( _("Invalid chrome path %(path)s.", path=filename)) elif os.path.isfile(path): req.send_file(path, get_mimetype(path)) self.log.warning('File %s not found in any of %s', filename, dirs) raise HTTPNotFound('File %s not found', filename)
def process_request(self, req): ''' serve the request but check wether the file realy is in cache ( absolute second part, f.e. an attemp to access restricted areas ) for those request, trying access files anywhere, serve an Exception, otherwise let it handle send_file, which checks for existence and serves either the file or an error ''' if req.path_info.startswith('/'): slashes = 2 else: slashes = 1 name = req.path_info[(slashes + len(PPConstant.cache_content_suffix)):] # dont use the cache, just verify the file existence and conf = PPConfiguration(self.env) cpath = os.path.normpath(conf.get('cachepath')) fname = os.path.normpath(name) if os.path.isabs(fname): self.env.log.warn('Attempted bypass ( access for %s ) ' % fname) raise TracError('Access Denied for "%s"' % fname) accessname = os.path.join(cpath, name) # no isfile and exitence check, both are done on send_file with error handling return req.send_file(accessname, get_mimetype(accessname))
def process_request( self, req ): ''' serve the request but check wether the file realy is in cache ( absolute second part, f.e. an attemp to access restricted areas ) for those request, trying access files anywhere, serve an Exception, otherwise let it handle send_file, which checks for existence and serves either the file or an error ''' if req.path_info.startswith('/'): slashes = 2 else: slashes = 1 name = req.path_info[(slashes+len(PPConstant.cache_content_suffix)):] # dont use the cache, just verify the file existence and conf = PPConfiguration( self.env ) cpath = os.path.normpath( conf.get( 'cachepath' ) ) fname = os.path.normpath( name ) if os.path.isabs( fname ): self.env.log.warn( 'Attempted bypass ( access for %s ) ' %fname ) raise TracError( 'Access Denied for "%s"' % fname ) accessname = os.path.join( cpath, name ) # no isfile and exitence check, both are done on send_file with error handling return req.send_file( accessname, get_mimetype( accessname ) )
def test_from_suffix_using_mimetypes(self): accepted = ('image/png', 'image/x-png') self.assertTrue(get_mimetype('doc/trac_logo.png', None) in accepted)
repos_name, repos, source_obj = \ repos_mgr.get_repository_by_path(source_obj) except AttributeError: # 0.11 repos = repos_mgr.get_repository(formatter.req.authname) path, rev = _split_path(source_obj) try: node = repos.get_node(path, rev) except (NoSuchChangeset, NoSuchNode), e: return system_message(e), None, None content = node.get_content() out = '' ctxt = dest_format = None if content: out = content.read() if dest_format is None: dest_format = node.content_type or get_mimetype(path, out) ctxt = Context.from_request(formatter.req, 'source', path) return out, ctxt, dest_format def _extract_section(self, text, section): m1 = re.search("(^\s*(?P<heading>={1,6})\s(.*?)(\#%s)\s*$)" % section, text, re.MULTILINE) if m1: stext = text[m1.end(0):] m2 = re.search( "(^\s*%s\s(.*?)(\#%s)?\s*$)" % (m1.group('heading'), WikiParser.XML_NAME), stext, re.MULTILINE) if m2: return stext[:m2.start(0)]
def test_from_suffix_using_MIME_MAP(self): self.assertEqual('text/plain', get_mimetype('README', None)) self.assertEqual('text/plain', get_mimetype('README.txt', None))
# XXX: Check for recursion in page includes. <NPK> 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 ctxt = Context.from_request(req, 'wiki', source_obj) elif source_format == 'source': if not req.perm.has_permission('FILE_VIEW'): return '' repo = self.env.get_repository(authname=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) ctxt = Context.from_request(req, 'source', source_obj) # RFE: Add ticket: and comment: sources. <NPK> # RFE: Add attachment: source. <NPK> else: return system_message('Unsupported include source %s'%source) # If there was a fragment name given then find the fragment. fragment = [] current_fragment_name = None if fragment_name: for line in out.splitlines(): res = re.search(r'FRAGMENT\(([^)]*)\)', line) if res: current_fragment_name = res.groups()[0] else:
def render_macro(self, req, name, content): args = [x.strip() for x in content.split(',')] # return args if len(args) == 1: args.append(None) elif len(args) != 2: return system_message('Invalid arguments "%s"' % content) # Pull out the arguments source, theader = args try: source_format, source_obj = source.split(':', 1) except ValueError: # If no : is present, assume its a wiki page source_format, source_obj = 'source', source # Apply a default format if needed try: if theader is not None: isTheader, theader_content = theader.split("=", 1) except AttributeError: pass try: dest_format = self.default_formats[source_format] except KeyError: pass if 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) ctxt = Context.from_request(req, 'source', source_obj) # RFE: Add ticket: and comment: sources. <NPK> # RFE: Add attachment: source. <NPK> else: return system_message('Unsupported include source %s' % source) # If we have a preview format, use it # Escape if needed # if not self.config.getbool('wiki', 'render_unsafe_content', False): # try: # out = HTMLParser(StringIO(out)).parse() | HTMLSanitizer() # except ParseError: # out = escape(out) # reader = str(out).split("||") need_header = 1 foo = '' foo += '<table class="sortable" style="border:1px solid #000;">' try: if theader is not None: if isTheader == "header": custom_theader = theader_content.split(";") foo += '<tr>' for theader_cell in custom_theader: foo += '<th style="border:1px solid #000;">' + str( theader_cell) + '</th>' foo += "</tr>\n" except AttributeError: pass for row in str(out).splitlines(): foo += "<tr>\n" for cell in row.split("||"): if cell.startswith("|"): foo += '<td align="right" style="border:1px solid #000;">' if dest_format: foo += (str( Mimeview(self.env).render( None, "text/x-trac-wiki", str(cell.lstrip("|"))))[16:])[:-19] foo += "</td>" else: foo += '<td align="right" style="border:1px solid #000;">' if dest_format: foo += (str( Mimeview(self.env).render( None, "text/x-trac-wiki", str(cell))).lstrip("<p>")[16:])[:-19] foo += "</td>" # foo +=str(row) # for cell in row: # foo += cell # foo += "-" foo += "</tr></table>" return foo
return out # IPermissionRequestor methods def get_permission_actions(self): yield "INCLUDE_URL" # Private methods def _get_source(self, formatter, source_obj, dest_format): repos_mgr = RepositoryManager(self.env) try: # 0.12+ repos_name, repos, source_obj = repos_mgr.get_repository_by_path(source_obj) except AttributeError, e: # 0.11 repos = repos_mgr.get_repository(formatter.req.authname) path, rev = _split_path(source_obj) node = repos.get_node(path, rev) out = node.get_content().read() if dest_format is None: dest_format = node.content_type or get_mimetype(path, out) ctxt = Context.from_request(formatter.req, "source", path) return out, ctxt, dest_format def _split_path(source_obj): if "@" in source_obj: path, rev = source_obj.split("@", 1) else: path, rev = source_obj, None return path, rev
def test_from_suffix_using_mimetypes(self): self.assertEqual('image/png', get_mimetype('doc/trac_logo.png', None))
def test_from_suffix_using_mimetypes(self): accepted = ('image/png', 'image/x-png') self.assertIn(get_mimetype('doc/trac_logo.png', None), accepted)
def post_process_request(self, req, template, data, content_type): """Post process request filter. Removes all trac provided css if required""" #if "TRAC_ADMIN" in req.perm: # add_ctxtnav(req, "Admin", "#", "Admin") add_meta(req, "width=device-width", http_equiv=None, name="viewport", scheme=None, lang=None) if self.is_active_theme: add_stylesheet(req, 'theme/css/foundation.css') add_stylesheet(req, 'theme/css/foundation-icons.css') add_stylesheet(req, 'theme/css/zurb_browser.css') add_stylesheet(req, 'theme/css/zurb_milestone.css') add_stylesheet(req, 'theme/css/zurb_tickets.css') add_stylesheet(req, 'theme/css/zurb_admin_um.css') add_script(req, 'theme/js/custom.modernizr.js') add_script(req, 'theme/js/foundation.min.js') #add_script(req, 'theme/js/jquery.js') #add_script(req, 'theme/js/zepto.js') #add_script(req, 'theme/js/jquery.js') # if data no has the key page means that am not on a wiki page, initialize value o page in "" if not data.has_key('page'): data['page'] = "" #if template is using user manager plugin... if template == "admin_um.html": if data['user_manager'].has_key('panel'): if data['user_manager']['panel'] == "account": data['user_manager'][ 'template'] = "zurb_admin_um_account.html" elif data['user_manager']['panel'] == "permissions": data['user_manager'][ 'template'] = "zurb_admin_um_permissions.html" elif data['user_manager']['panel'] == "profile": data['user_manager'][ 'template'] = "zurb_admin_um_profile.html" if template is None and data is None and sys.exc_info() == (None, None, None): return template, data, content_type links = req.chrome.get('links', {}) #replace favicon if appropriate if self.env.project_icon == 'common/trac.ico': bh_icon = 'theme/img/bh.ico' new_icon = { 'href': req.href.chrome(bh_icon), 'type': get_mimetype(bh_icon) } if links.get('icon'): links.get('icon')[0].update(new_icon) if links.get('shortcut icon'): links.get('shortcut icon')[0].update(new_icon) if self.disable_all_trac_css and self.is_active_theme: if self.disable_all_trac_css: stylesheets = links.get('stylesheet', []) if stylesheets: path = req.base_path + '/chrome/common/css/' _iter = ([ss, ss.get('href', '')] for ss in stylesheets) links['stylesheet'] = [ ss for ss, href in _iter if not href.startswith(path) or href.rsplit('/', 1)[-1] in self.ZURB_KEEP_CSS ] template, modifier = self.ZURB_TEMPLATE_MAP.get( template, (template, None)) if modifier is not None: modifier = getattr(self, modifier) modifier(req, template, data, content_type, self.is_active_theme) # if is_active_theme and data is not None: # data['responsive_layout'] = self.env.config.getbool( # 'bloodhound', 'responsive_layout', 'true') return template, data, content_type
def test_from_suffix_using_mimetypes(self): self.assertEqual('application/x-python-code', get_mimetype('test.pyc', None))
def get_content_type(self): return get_mimetype(self.path)
def test_from_content_using_is_binary(self): self.assertEqual('application/octet-stream', get_mimetype('xxx', "abc\0xyz"))
def post_process_request(self, req, template, data, content_type): """Post process request filter. Removes all trac provided css if required""" #if "TRAC_ADMIN" in req.perm: # add_ctxtnav(req, "Admin", "#", "Admin") add_meta(req, "width=device-width", http_equiv=None, name="viewport", scheme=None, lang=None) if self.is_active_theme: add_stylesheet(req, 'theme/css/foundation.css') add_stylesheet(req, 'theme/css/foundation-icons.css') add_stylesheet(req, 'theme/css/zurb_browser.css') add_stylesheet(req, 'theme/css/zurb_milestone.css') add_stylesheet(req, 'theme/css/zurb_tickets.css') add_stylesheet(req, 'theme/css/zurb_admin_um.css') add_script(req, 'theme/js/custom.modernizr.js') add_script(req, 'theme/js/foundation.min.js') #add_script(req, 'theme/js/jquery.js') #add_script(req, 'theme/js/zepto.js') #add_script(req, 'theme/js/jquery.js') # if data no has the key page means that am not on a wiki page, initialize value o page in "" if not data.has_key('page'): data['page'] = ""; #if template is using user manager plugin... if template=="admin_um.html": if data['user_manager'].has_key('panel'): if data['user_manager']['panel'] == "account": data['user_manager']['template'] = "zurb_admin_um_account.html" elif data['user_manager']['panel'] == "permissions": data['user_manager']['template'] = "zurb_admin_um_permissions.html" elif data['user_manager']['panel'] == "profile": data['user_manager']['template'] = "zurb_admin_um_profile.html" if template is None and data is None and sys.exc_info() == (None, None, None): return template, data, content_type links = req.chrome.get('links',{}) #replace favicon if appropriate if self.env.project_icon == 'common/trac.ico': bh_icon = 'theme/img/bh.ico' new_icon = {'href': req.href.chrome(bh_icon), 'type': get_mimetype(bh_icon)} if links.get('icon'): links.get('icon')[0].update(new_icon) if links.get('shortcut icon'): links.get('shortcut icon')[0].update(new_icon) if self.disable_all_trac_css and self.is_active_theme: if self.disable_all_trac_css: stylesheets = links.get('stylesheet',[]) if stylesheets: path = req.base_path + '/chrome/common/css/' _iter = ([ss, ss.get('href', '')] for ss in stylesheets) links['stylesheet'] = [ss for ss, href in _iter if not href.startswith(path) or href.rsplit('/', 1)[-1] in self.ZURB_KEEP_CSS] template, modifier = self.ZURB_TEMPLATE_MAP.get( template, (template, None)) if modifier is not None: modifier = getattr(self, modifier) modifier(req, template, data, content_type, self.is_active_theme) # if is_active_theme and data is not None: # data['responsive_layout'] = self.env.config.getbool( # 'bloodhound', 'responsive_layout', 'true') return template, data, content_type