def hints(self): filename = self.module.replace( '__init__.pyc', self.__class__.hint_filename ).replace( '__init__.py', self.__class__.hint_filename ) f = open(filename) template = PageTemplate(f.read().replace('#{','${').replace("condition=","tal:condition=")) dictionary = dict(self.__dict__, **globals()) dictionary['answer'] = self.answer() return [x.replace('<p>','').replace('</p>','') for x in re.sub("\n+","\n",template.render(**dictionary)).split( "</p>\n<p>" )]
def text(self): filename = self.module.replace( '__init__.pyc', 'text.html' ).replace( '__init__.py', 'text.html' ) f = open(filename) template = PageTemplate(f.read().replace('#{','${').replace("condition=","tal:condition=")) dictionary = dict(self.__dict__, **globals()) dictionary['answer'] = self.answer() return template.render(**dictionary)
def SayHello(self, request, context): tmpl = PageTemplate(BIGTABLE_ZPT) data = {} num_of_cols = 15 num_of_rows = 10 if request.name == "record": msg = 'Hello, %s!' % responses[0] num_of_cols = 15 num_of_rows = 10 elif request.name == "replay": msg = 'Hello, %s!' % responses[1] num_of_cols = 10 num_of_rows = 15 else: msg = 'Hello, %s!' % request.name for i in range(num_of_cols): data[str(i)] = i table = [data for x in range(num_of_rows)] options = {'table': table} data = tmpl.render(options=options) return helloworld_pb2.HelloReply(message=msg)
def text(self): filename = self.module.replace('__init__.pyc', 'text.html').replace( '__init__.py', 'text.html') f = open(filename) template = PageTemplate(f.read().replace('#{', '${').replace( "condition=", "tal:condition=")) dictionary = dict(self.__dict__, **globals()) dictionary['answer'] = self.answer() return template.render(**dictionary)
def render_logo(locale, default_src=None): request = self.mk_request(locale_name=locale) self.views = CmsViews(request) if default_src: define = 'tal:define="img_attrs view.get_logo_attributes' \ '(default_image_src=\'%s\')"' % default_src else: define = '' template = '<div metal:use-macro="view.logo_template" %s></div>' template = PageTemplate(template % define) return template.render(view=self.views, request=request)
def __call__(self, field, **kwargs): params = html_params(name=field.name, **kwargs) request = field.meta.request registry = request.app.config.template_engine_registry macros = registry._template_loaders['.pt'].macros template = PageTemplate(f""" <div {params}> <div metal:use-macro="macros['{field.macro}']"/> </div> """, macros=macros) translate = request.get_translate(for_chameleon=True) return HTMLString(template.render(translate=translate))
def hints(self): filename = self.module.replace('__init__.pyc', self.__class__.hint_filename).replace( '__init__.py', self.__class__.hint_filename) f = open(filename) template = PageTemplate(f.read().replace('#{', '${').replace( "condition=", "tal:condition=")) dictionary = dict(self.__dict__, **globals()) dictionary['answer'] = self.answer() return [ x.replace('<p>', '').replace('</p>', '') for x in re.sub("\n+", "\n", template.render( **dictionary)).split("</p>\n<p>") ]
def main(req: func.HttpRequest) -> func.HttpResponse: num_of_rows = req.params.get('num_of_rows') num_of_cols = req.params.get('num_of_cols') start = time() tmpl = PageTemplate(BIGTABLE_ZPT) data = {} for i in range(num_of_cols): data[str(i)] = i table = [data for x in range(num_of_rows)] options = {'table': table} data = tmpl.render(options=options) latency = time() - start return func.HttpResponse(str(latency))
def lambda_handler(event, context): num_of_rows = event['num_of_rows'] num_of_cols = event['num_of_cols'] start = time() tmpl = PageTemplate(BIGTABLE_ZPT) data = {} for i in range(num_of_cols): data[str(i)] = i table = [data for x in range(num_of_rows)] options = {'table': table} data = tmpl.render(options=options) latency = time() - start result = json.dumps({'latency': latency, 'data': data}) return result
def main(args): global cold was_cold = cold cold = False num_of_rows = int(args.get("num_of_rows", 10)) num_of_cols = int(args.get("num_of_cols", 10)) start = time() tmpl = PageTemplate(BIGTABLE_ZPT) data = {} for i in range(num_of_cols): data[str(i)] = i table = [data for x in range(num_of_rows)] options = {'table': table} data = tmpl.render(options=options) latency = time() - start return {"body": {'latency': latency, 'data': data, "cold": was_cold}}
def test_mako(count): template = PageTemplate(CONTENT_TEMPLATE) base = PageTemplate(BASE_TEMPLATE) page = PageTemplate(PAGE_TEMPLATE) table = [range(150) for i in range(150)] paragraphs = range(50) title = 'Hello world!' times = [] for i in range(count): t0 = time.time() data = template.render( table=table, paragraphs=paragraphs, lorem=LOREM_IPSUM, title=title, img_count=50, base=base, page=page, ) t1 = time.time() times.append(t1-t0) return times
def test_mako(count): template = PageTemplate(CONTENT_TEMPLATE) base = PageTemplate(BASE_TEMPLATE) page = PageTemplate(PAGE_TEMPLATE) table = [xrange(150) for i in xrange(150)] paragraphs = xrange(50) title = 'Hello world!' times = [] for i in range(count): t0 = time.time() data = template.render( table=table, paragraphs=paragraphs, lorem=LOREM_IPSUM, title=title, img_count=50, base=base, page=page, ) t1 = time.time() times.append(t1 - t0) return times
def function_handler(request): request_json = request.get_json(silent=True) num_of_rows = request_json['num_of_rows'] num_of_cols = request_json['num_of_cols'] message = generate(length_of_message) # 128-bit key (16 bytes) KEY = b'\xa1\xf6%\x8c\x87}_\xcd\x89dHE8\xbf\xc9,' start = time() tmpl = PageTemplate(BIGTABLE_ZPT) data = {} for i in range(num_of_cols): data[str(i)] = i table = [data for x in range(num_of_rows)] options = {'table': table} data = tmpl.render(options=options) latency = time() - start return "latency : " + str(latency)