def __init__(self, template): """\brief Initialize the class \param (\c string) xml template instance as string buffer """ Template.__init__(self, template) self.__compvars = {} self.__topovars = {} self.__get_vars()
def __init__(self, template): Template.__init__(self, template) self.__distcomp = self.dom.getElementsByTagName("distcomposition")[0] self.__topo = Topology( self.__distcomp.getElementsByTagName("topology")[0]) self.__comps = [ Composition(c) for c in self.__distcomp.getElementsByTagName("composition") ]
def _render_page(path, page_data, get, post, variables, load_regions = True): # Get paths for the template and controller for the page template_path = page_data.get('template', False) controller_module = page_data.get('controller', False) if not template_path: raise ServerError('Path not configured correctly: ' + path) # Read the template file try: template = Template(template_path) except IOError: raise ServerError('Template file does not exist: ' + template_path) template_data = {} # Import the controller (if specified) if controller_module: try: controller_module = importlib.import_module(controller_module) except ImportError as e: raise ServerError('Error importing controller for path "%s": %s' % (path, str(e))) # Get data to inject into the template template_data = controller_module.get_page_data(path, get, post, variables) # Add the page's title, if no title is set if not template_data.get('title', False): template_data['title'] = page_data.get('title', '') # Load predefined regions given in the paths file if load_regions: regions = paths.get('*', {'regions': {}}).get('regions', {}) for (name, region) in regions.items(): if not template_data.get(name, False): template_data[name] = _render_page(path, region, get, post, variables, False) return template.render(template_data)
def error401(): status = 401 body = Template('error/401.html').render() return Response(status=status, headers={'WWW-Authenticate': 'Basic realm="this realm"'}, body=body)
def get(self): return Template('hello/form.html', self.kwargs).render()
def post(self): return Template('hello/index.html', self.kwargs).render()
"--github-user", action="store", dest="github_user", required=True, help="Github Username") parser.add_argument("-gr", "--github-repo", action="store", dest="github_repo", required=True, help="Github Repository name") args = parser.parse_args() g = Github(token, args.github_user, args.github_repo) t = Template(args.template, output_dir, g) p = PDF(output_dir, t) css_file = "templates/{}/vulnerabilities.css".format(args.template) customer = json.loads(g.get_file("infos.json")) template_frozen_opts = t.get_frozen_opts() frozen_opts = {"{{DATE}}": date.today().strftime("%d/%m/%Y")} frozen_opts.update(customer) frozen_opts.update(template_frozen_opts) report_name = "{}-pentest-final-report-by-{}.pdf".format( frozen_opts["{{CUSTOMER}}"].lower(), frozen_opts["{{PENTESTER_NAME}}"].lower().replace(" ", "_")) b = Build(output_dir, frozen_opts, p, g, t)
def test_it_should_autoload_file(self): template = Template(self.filename) self.assertIsInstance(template.template, _Template)
def test_it_should_raise_an_exception_if_file_does_not_exists(self): with self.assertRaises(NotSuchTemplateFileException) as e: Template(self.faulty_filename).render() self.assertEqual(e.exception.code, '0')
def test_it_should_load_the_file(self): output = Template().get_template_file(self.filename) self.assertIsInstance(output, StringType) self.assertTrue(len(output) > 0)