当前位置: 首页>>代码示例>>Python>>正文


Python template.Template类代码示例

本文整理汇总了Python中tornado.template.Template的典型用法代码示例。如果您正苦于以下问题:Python Template类的具体用法?Python Template怎么用?Python Template使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Template类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Requestlink_list

 def Requestlink_list(self, ResourceListName, ResourceList, PluginInfo):
     link_list = []
     for Name, Resource in ResourceList:
         Chunks = Resource.split('###POST###')
         URL = Chunks[0]
         POST = None
         Method = 'GET'
         if len(Chunks) > 1:  # POST
             Method = 'POST'
             POST = Chunks[1]
             Transaction = self.requester.get_transaction(True, URL, Method, POST)
             if Transaction is not None and Transaction.found:
                 RawHTML = Transaction.get_raw_response_body()
                 FilteredHTML = self.reporter.sanitize_html(RawHTML)
                 NotSandboxedPath = self.plugin_handler.dump_output_file("NOT_SANDBOXED_%s.html" % Name, FilteredHTML,
                                                                         PluginInfo)
                 logging.info("File: NOT_SANDBOXED_%s.html saved to: %s", Name, NotSandboxedPath)
                 iframe_template = Template("""
                     <iframe src="{{ NotSandboxedPath }}" sandbox="" security="restricted"  frameborder='0'
                     style="overflow-y:auto; overflow-x:hidden;width:100%;height:100%;" >
                     Your browser does not support iframes
                     </iframe>
                     """)
                 iframe = iframe_template.generate(NotSandboxedPath=NotSandboxedPath.split('/')[-1])
                 SandboxedPath = self.plugin_handler.dump_output_file("SANDBOXED_%s.html" % Name, iframe, PluginInfo)
                 logging.info("File: SANDBOXED_%s.html saved to: %s", Name, SandboxedPath)
                 link_list.append((Name, SandboxedPath))
     plugin_output = dict(PLUGIN_OUTPUT)
     plugin_output["type"] = "Requestlink_list"
     plugin_output["output"] = {"ResourceListName": ResourceListName, "link_list": link_list}
     return ([plugin_output])
开发者ID:owtf,项目名称:owtf,代码行数:31,代码来源:plugin_helper.py

示例2: send_thanks

def send_thanks(recepient, fundraiser_name, amount, donation_date):

    # bit messy, make this cleaner
    donation_date = (donation_date + timedelta(hours=10)).strftime('%H:%M:%S %Y-%m-%d  AEST')
    basepath = os.path.dirname(__file__)
    filepath = os.path.join(basepath, 'email.html')

    with open(filepath) as f:
        raw_template = f.read()

    t = Template(raw_template)
    parsed_template = t.generate(title='{} - Thank you'.format(fundraiser_name),
                                 donation_date=donation_date,
                                 fundraiser_name=fundraiser_name,
                                 donation_amount=amount)

    message = MIMEMultipart('related')
    msg_html = MIMEText(parsed_template, 'html')

    message.attach(msg_html)

    message['Subject'] = '{} - Thank you'.format(fundraiser_name)
    message['From'] = FROM
    message['To'] = recepient

    send(recepient, FROM, message.as_string())
开发者ID:ppau,项目名称:bounty,代码行数:26,代码来源:chip_email.py

示例3: post

    def post(self):
        error = None
        try:
            username = self.request.arguments['username'][0]
            if len(username) == 0:
                raise Exception('bad username')

            """if get_user(username) == True:
                error = 'Username already exists.'
                raise Exception()"""
        except:
            if not error == None:
                error = 'A non-zero length username is required.'

        try:
            password = self.request.arguments['password'][0]
            if len(password) == 0:
                raise Exception('bad password')
        except:
            if not error == None:
                error = 'A non-zero length password is required.'
        print username
        """add_account(username, password)"""

        if error == None:
            t = Template(open('templates/client_sample.html',
                'r').read())
            client_sample_code = t.generate(username=username)

            self.render('templates/index.html', code=client_sample_code)
        else:
            self.render('templates/register.html', error=error)
开发者ID:dash1291,项目名称:crunch-web,代码行数:32,代码来源:webserver.py

示例4: get

 def get(self, id):
     try:
         dog = db_session.query(Dog).filter(Dog.id == id).one()
         t = Template('<img alt="dog_image" src="data:image/jpeg;base64,{{ img }}" />')
         self.write(t.generate(img=dog.image))
     except:
         self.write("Dog not found")
开发者ID:sonnguyenthai,项目名称:dog_test,代码行数:7,代码来源:api.py

示例5: RequestLinkList

 def RequestLinkList(self, ResourceListName, ResourceList, PluginInfo):
     # for Name, Resource in Core.Config.GetResources('PassiveRobotsAnalysisHTTPRequests'):
     LinkList = []
     for Name, Resource in ResourceList:
         Chunks = Resource.split('###POST###')
         URL = Chunks[0]
         POST = None
         Method = 'GET'
         if len(Chunks) > 1:  # POST
             Method = 'POST'
             POST = Chunks[1]
             Transaction = self.requester.GetTransaction(True, URL, Method, POST)
         if Transaction.Found:
             RawHTML = Transaction.GetRawResponseBody()
             FilteredHTML = self.reporter.sanitize_html(RawHTML)
             NotSandboxedPath = self.plugin_handler.DumpOutputFile("NOT_SANDBOXED_" + Name + ".html",
                                                                   FilteredHTML, PluginInfo)
             logging.info("File: " + "NOT_SANDBOXED_" + Name + ".html" + " saved to: " + NotSandboxedPath)
             iframe_template = Template("""
                     <iframe src="{{ NotSandboxedPath }}" sandbox="" security="restricted"  frameborder = '0' style = "overflow-y:auto; overflow-x:hidden;width:100%;height:100%;" >
                     Your browser does not support iframes
                     </iframe>
                     """)
             iframe = iframe_template.generate(NotSandboxedPath=NotSandboxedPath.split('/')[-1])
             SandboxedPath = self.plugin_handler.DumpOutputFile("SANDBOXED_" + Name + ".html", iframe,
                                                                PluginInfo)
             logging.info("File: " + "SANDBOXED_" + Name + ".html" + " saved to: " + SandboxedPath)
             LinkList.append(( Name, SandboxedPath ))
     plugin_output = dict(PLUGIN_OUTPUT)
     plugin_output["type"] = "RequestLinkList"
     plugin_output["output"] = {"ResourceListName": ResourceListName, "LinkList": LinkList}
     return ([plugin_output])
开发者ID:DePierre,项目名称:owtf,代码行数:32,代码来源:plugin_helper.py

示例6: new

def new():
    '''Create a new ticket.

    $EDITOR will be opened and used to edit the case. The case
    template has an "header" in .yaml format. "Title", "Project",
    "Area", "Files", etc. are all available fields.
    The body of the ticket is separated by "---".

    Example:
    >>> new
    '''

    tmpl = Template('''Title: <title>
Project: <project>
# Area: <area>
# Assign to: {{ user.fullname }}
# Priority: Need to fix
# Parent: <id>
# Milestone: Infrastructure and Internal Errors
# Tags: <list>

---

<Insert description here>

''')  # noqa

    header = tmpl.generate(user=CURRENT_USER).decode('utf-8')
    with editor.writing(header=header) as text:
        editor.abort_if_empty(text)
        params = text.get_params_for_new()
        FBCase.new(**params)
开发者ID:didiercrunch,项目名称:fbcli,代码行数:32,代码来源:cli.py

示例7: render

def render(template_file, data=None):

    if (data is None):
        data = {}

    t = Template(open("public/views/{0}".format(template_file), "r").read())
    return t.generate(**data)
开发者ID:k-pom,项目名称:turbo-adventure,代码行数:7,代码来源:template.py

示例8: _show_login_window

 def _show_login_window(self, next="/", message=None, login_template=None):
     if not login_template:
         login_template = self.settings.get('login_template', LOGIN_PAGE_TEMPLATE)
     t = Template(login_template)
     html = t.generate(next=next, message=message)
     self.write(html)
     self.finish()
开发者ID:kuasha,项目名称:cosmos,代码行数:7,代码来源:auth.py

示例9: test_unicode_literal_expression

 def test_unicode_literal_expression(self):
     # Unicode literals should be usable in templates.  Note that this
     # test simulates unicode characters appearing directly in the
     # template file (with utf8 encoding), i.e. \u escapes would not
     # be used in the template file itself.
     template = Template(utf8(u'{{ "\u00e9" }}'))
     self.assertEqual(template.generate(), utf8(u"\u00e9"))
开发者ID:leeclemens,项目名称:tornado,代码行数:7,代码来源:template_test.py

示例10: get

 def get(self):
     b = Template(string)
     books=['Learning Python', 'Programming Collective Intelligence', 
            'Restful Web Services']
     content = b.generate(title='Home Page', 
                          header='Books that are great', 
                          books=books)
     self.write(content)
开发者ID:Rockyzsu,项目名称:base_function,代码行数:8,代码来源:模板语法.py

示例11: _entry_to_html

 def _entry_to_html(self, entry):
     t = Template(self._html_entry)
     return text_type(t.generate(source=entry.source,
             anchor=entry.anchor, id=entry.id,
             link=entry.link, title=entry.title,
             author=entry.author, updated=entry.updated,
             updated_str=self._date_to_str(entry.updated),
             content=entry.content), 'UTF-8')
开发者ID:sjlongland,项目名称:tornado-news,代码行数:8,代码来源:tornadonews.py

示例12: generate

def generate(codes, output_path = './qrmaster',
             url='http://test.com', title='',
             img_path=None):
    """codes are tuples in the form: (code, id)"""
    
    module_path, _ = path.split(__file__)
    css_file_name = 'style.css'
    
    template_path = path.join(module_path, 'template.html')
    css_path = path.join(module_path, css_file_name)
    
    output_file = path.join(output_path, 'qrmaster.html')
    o_css_path = path.join(output_path, css_file_name)
    
    files_path = path.join(output_path, 'qrmaster')
    if not path.exists(files_path):
        makedirs(files_path)
    
    if img_path:
        _, img_file_name = path.split(img_path)
        o_img_path = path.join(output_path, img_file_name)
        copyfile(img_path, o_img_path)
    else:
        o_img_path = ''
    
    copyfile(css_path, o_css_path)
        
    data = []
    for c in codes:
        qr = qrcode.QRCode(
            version = 1,
            box_size = 5,
            border = 0,
            error_correction = 
                qrcode.constants.ERROR_CORRECT_H
        )
        full_url = urljoin(url, c[0])
        c.append(full_url)
        data.append(c)
        qr.add_data(full_url)
        qr.make()
        qr_path = path.join(files_path, c[0]+'.svg')
        qr.make_image(
            image_factory=qrcode.image.svg.SvgImage).save(
                qr_path)

    with open(template_path, 'r') as f:
        tmp = f.read()
        
    html = Template(tmp).generate(data=data,
                                  files_path=files_path,
                                  title=title,
                                  img_path=img_file_name)
    
    with open(output_file, 'w') as f:
        f.write(
            html.decode('utf-8')
        )
开发者ID:soulrevenges,项目名称:artificialAlan,代码行数:58,代码来源:generate.py

示例13: render

 def render(tpl_text, **kwargs):
     """
     render a template
     :param tpl_text: template text
     :param context: dict object
     :return: str
     """
     tpl = Template(tpl_text)
     return tpl.generate(**kwargs).decode("utf-8")
开发者ID:tinyms,项目名称:TanYue,代码行数:9,代码来源:util.py

示例14: test_try

    def test_try(self):
        template = Template(utf8("""{% try %}
try{% set y = 1/x %}
{% except %}-except
{% else %}-else
{% finally %}-finally
{% end %}"""))
        self.assertEqual(template.generate(x=1), b"\ntry\n-else\n-finally\n")
        self.assertEqual(template.generate(x=0), b"\ntry-except\n-finally\n")
开发者ID:102hailan,项目名称:tornado,代码行数:9,代码来源:template_test.py

示例15: render

 def render(tpl_text, context):
     """
     render a template
     :param tpl_text: template text
     :param context: dict object
     :return: str
     """
     tpl = Template(tpl_text)
     return tpl.generate(context)
开发者ID:tinyms,项目名称:Matty,代码行数:9,代码来源:common.py


注:本文中的tornado.template.Template类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。