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


Python Template.compile方法代码示例

本文整理汇总了Python中Cheetah.Template.Template.compile方法的典型用法代码示例。如果您正苦于以下问题:Python Template.compile方法的具体用法?Python Template.compile怎么用?Python Template.compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cheetah.Template.Template的用法示例。


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

示例1: get

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import compile [as 别名]
    def get(self, resource):
        resid = resource 
	l_skel = Skel()
	l_skel.title = "Smashed.in :: OverHeards"

        meme_query = UserMemeDb.query(UserMemeDb.resid == resid)
        memes = meme_query.fetch(1)
        meme = memes[0]
        template_values = {
            'memeurl':   '/res/download/%s' % meme.blobid,
            'conturl':   '/oh/%s' % meme.resid,
            'localid':   '%s' % meme.resid,
            'mode'   :   '%s' %meme.mode,
            'shareid':   '%s' % meme.shareid,
            'currentid': '%s' % meme.resid,
            'commentid': '%s' % meme.commentid,
            'isLoggedIn': '%s' %self.logged_in,
            'tags'      : ','.join(meme.tags)
            
            }

	#Head
	head_path = os.path.join (os.path.dirname(__file__), 'templates/ohview-head.tmpl')
	l_skel.addtohead(str((Template.compile(file=head_path)(searchList=template_values))))

	#body
        path = os.path.join (os.path.dirname (__file__), 'templates/ohview-body.tmpl')
	l_skel.addtobody (str((Template.compile(file=path)(searchList=template_values))))

        self.response.out.write(l_skel.gethtml())
开发者ID:thejasvibhat,项目名称:smashed,代码行数:32,代码来源:meme.py

示例2: get

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import compile [as 别名]
    def get(self):
        l_skel = Skel()
        l_skel.title = "Smashed.in :: About Us"
        #Head
        head_path = os.path.join (os.path.dirname (__file__), 'templates/about-head.tmpl')
        l_skel.addtohead (str((Template.compile(file=head_path) (searchList={}))))

        #Body
        path = os.path.join (os.path.dirname (__file__), 'templates/about-body.tmpl')
        l_skel.addtobody (str((Template.compile(file=path) (searchList={}))))

        self.response.out.write(l_skel.gethtml())
开发者ID:thejasvibhat,项目名称:smashed,代码行数:14,代码来源:sitepages.py

示例3: runTest

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import compile [as 别名]
    def runTest(self):
        t = Template.compile(source="""Main file with |$v|

        $other""")

        otherT = Template.compile(source="Other template with |$v|")
        other = otherT()
        t.other = other

        t.v = u'Unicode String'
        t.other.v = u'Unicode String'

        assert unicode(t())
开发者ID:resa89,项目名称:imusite,代码行数:15,代码来源:Unicode.py

示例4: runTest

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import compile [as 别名]
    def runTest(self):
        t = Template.compile(source="""Main file with |$v|

        $other""")

        otherT = Template.compile(source="Other template with |$v|")
        other = otherT()
        t.other = other

        t.v = 'Unicode String with eacute é'
        t.other.v = 'Unicode String and an eacute é'

        assert str(t())
开发者ID:tiarno,项目名称:cheetah,代码行数:15,代码来源:Unicode.py

示例5: test_moduleNameArg

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import compile [as 别名]
    def test_moduleNameArg(self):
        klass = Template.compile(source='$foo', moduleName='foo99')
        mod = sys.modules['foo99']
        assert klass.__name__=='foo99'
        t = klass(namespaces={'foo':1234})
        assert str(t)=='1234'


        klass = Template.compile(source='$foo',
                                 moduleName='foo1',
                                 className='foo2')
        mod = sys.modules['foo1']
        assert klass.__name__=='foo2'
        t = klass(namespaces={'foo':1234})
        assert str(t)=='1234'
开发者ID:andrenalin1981,项目名称:qpkg-sickbeard,代码行数:17,代码来源:Template.py

示例6: test_moduleGlobalsArg

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import compile [as 别名]
    def test_moduleGlobalsArg(self):
        klass = Template.compile(source='$foo',
                                 moduleGlobals={'foo':1234})
        t = klass()
        assert str(t)=='1234'

        klass2 = Template.compile(source='$foo', baseclass='Test1',
                                  moduleGlobals={'Test1':dict})
        t = klass2({'foo':1234})
        assert str(t)=='1234'

        klass3 = Template.compile(source='$foo', baseclass='Test1',
                                  moduleGlobals={'Test1':dict, 'foo':1234})
        t = klass3()
        assert str(t)=='1234'
开发者ID:andrenalin1981,项目名称:qpkg-sickbeard,代码行数:17,代码来源:Template.py

示例7: get

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import compile [as 别名]
    def get(self):
        self.user_gatekeeper ()
        data = []
#Head
        data.append('<div id="oh" title="Record Overheard" style="width:1080px;" >')
        data.append('<div>')
        head_path = os.path.join (os.path.dirname (__file__), 'templates/createoh-head.tmpl')
        data.append (str((Template.compile(file=head_path) (searchList={}))))

        #Body
        template_values = {}
        path = os.path.join (os.path.dirname (__file__), 'templates/createoh-body.tmpl')
        data.append (str((Template.compile(file=path) (searchList=template_values))))
        data.append('</div>')
        data.append('</div>')
        self.response.out.write("\n".join (data))
开发者ID:thejasvibhat,项目名称:smashed,代码行数:18,代码来源:creatememe.py

示例8: test_normalizePreprocessorArgVariants

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import compile [as 别名]
    def test_normalizePreprocessorArgVariants(self):
        src='%set foo = 12\n%%comment\n$(@foo*10)'

        class Settings1: tokens = '@ %' 
        Settings1 = Settings1()
            
        from Cheetah.Template import TemplatePreprocessor
        settings = Template._normalizePreprocessorSettings(Settings1)
        preprocObj = TemplatePreprocessor(settings)

        def preprocFunc(source, file):
            return '$(12*10)', None

        class TemplateSubclass(Template):
            pass

        compilerSettings = {'cheetahVarStartToken':'@',
                            'directiveStartToken':'%',
                            'commentStartToken':'%%',
                            }
        
        for arg in ['@ %',
                    {'tokens':'@ %'},
                    {'compilerSettings':compilerSettings},
                    {'compilerSettings':compilerSettings,
                     'templateInitArgs':{}},
                    {'tokens':'@ %',
                     'templateAPIClass':TemplateSubclass},
                    Settings1,
                    preprocObj,
                    preprocFunc,                    
                    ]:
            
            klass = Template.compile(src, preprocessors=arg)
            assert str(klass())=='120'
开发者ID:andrenalin1981,项目名称:qpkg-sickbeard,代码行数:37,代码来源:Template.py

示例9: test_baseclassArg

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import compile [as 别名]
    def test_baseclassArg(self):
        klass = Template.compile(source='$foo', baseclass=dict)
        t = klass({'foo':1234})
        assert str(t)=='1234'

        klass2 = Template.compile(source='$foo', baseclass=klass)
        t = klass2({'foo':1234})
        assert str(t)=='1234'

        klass3 = Template.compile(source='#implements dummy\n$bar', baseclass=klass2)
        t = klass3({'foo':1234})
        assert str(t)=='1234'

        klass4 = Template.compile(source='$foo', baseclass='dict')
        t = klass4({'foo':1234})
        assert str(t)=='1234'
开发者ID:andrenalin1981,项目名称:qpkg-sickbeard,代码行数:18,代码来源:Template.py

示例10: generate

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import compile [as 别名]
def generate(namespace):
	name = namespace['name']
	lname = name.lower()
	output_files = { 
			"%splugin.h" % (lname,) : 'plugin.h.template',
			"%splugin.cpp" % (lname,) : 'plugin.cpp.template',
			"%splugin_config.h.in" % (lname,) : 'plugin_config.h.in.template',
			"%sexecutive.h" % (lname,) : 'executive.h.template',
			"%sexecutive.cpp" % (lname,) : 'executive.cpp.template',
			"%sexecutivereply.h" % (lname,) : 'executivereply.h.template',
			"%sexecutivereply.cpp" % (lname,) : 'executivereply.cpp.template',
			"CMakeLists.txt"  : 'CMakeLists.txt.template',
			"webexplugin_%s.desktop" % (lname,) : 'desktop.template',
			}

	if namespace['kcm'] :
		output_files["%skcm.h" % (lname,)] =  'kcm.h.template'
		output_files["%skcm.cpp" % (lname,)] =  'kcm.cpp.template'
		output_files["webexplugin_%s_kcm.desktop" % (lname,)] = 'kcm.desktop.template'


	for (of,of_template) in output_files.iteritems():
		tclass =  Template.compile(file=of_template)
		res = tclass(namespaces = namespace)
		fo = open("".join([output_dir,'/',of]),"w")
		fo.write(str(res))
		#print res
		# .ui file should not be parsed with cheetah
		# Instead we simply copy it
	if namespace['kcm'] :
		if namespace['kcm_ui']:
			output_ui_file_name = "".join([output_dir,'/',"kcm.ui"])
			subprocess.call(['cp', 'kcm.ui' , output_ui_file_name])
开发者ID:KDE,项目名称:nepomuk-web-extractor,代码行数:35,代码来源:newplugin.py

示例11: create_project

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import compile [as 别名]
def create_project(shortname, dest, path='skel', **config):
	for filename in pkg.resource_listdir('modu', path):
		if(filename.startswith('__init__.py')):
			continue
		
		resource_path = os.path.join(path, filename)
		
		if(pkg.resource_isdir('modu', resource_path)):
			directory = filename
			if(directory.startswith('.')):
				continue
			if(directory.startswith('project')):
				directory = directory.replace('project', shortname)
			
			new_dest = os.path.join(dest, directory)
			
			if not(os.path.isdir(new_dest)):
				os.makedirs(new_dest)
			create_project(shortname, new_dest, resource_path, **config)
		else:
			if(filename.startswith('.')):
				continue
			
			new_file = None
			output_file = None
			file_stream = pkg.resource_stream('modu', resource_path)
			try:
				if(filename.endswith('.tmpl')):
					template_class = Template.compile(file=file_stream)
					
					variables = dict(
						project_name = shortname,
						project_description = config.get('longname', shortname),
						copyright_holder = config.get('author', shortname),
						year = time.strftime('%Y')
					)
					
					output = str(template_class(searchList=[variables]))
					new_filename = filename[:-5]
					if(new_filename.startswith('project')):
						new_filename = new_filename.replace('project', shortname)
					new_path = os.path.join(dest, new_filename)
					
					new_file = open(new_path, 'w')
					new_file.write(output)
					new_file.close()
				else:
					# copy the file
					output_filename = os.path.join(dest, filename)
					output_file = open(output_filename, 'w')
					shutil.copyfileobj(file_stream, output_file)
					output_file.close()
			finally:
				if(new_file and not new_file.closed):
					new_file.close()
				if(output_file and not output_file.closed):
					output_file.close()
				file_stream.close()
开发者ID:philchristensen,项目名称:modu,代码行数:60,代码来源:__init__.py

示例12: get

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import compile [as 别名]
    def get(self):
        self.user_gatekeeper ()
        self._gatekeeper ()
        l_skel = Skel()
        l_skel.title = "Smashed.in :: Write a Review"

            #Head
        head_path = os.path.join (os.path.dirname (__file__), 'templates/upload-head.tmpl')
        l_skel.addtohead (str((Template.compile(file=head_path) (searchList={}))))

            #Body
        upload_url = blobstore.create_upload_url ('/api/b/upload')

        path = os.path.join (os.path.dirname (__file__), 'templates/upload-body.tmpl')
        template_values = {'upload_url': upload_url}
        l_skel.addtobody (str((Template.compile(file=path) (searchList=template_values))))

        self.response.out.write(l_skel.gethtml())
开发者ID:thejasvibhat,项目名称:smashed,代码行数:20,代码来源:storereview.py

示例13: render_template

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import compile [as 别名]
def render_template(template_path, **kw):
    '''Renders the template file located at template_path, using the variables defined by kw, and
       returns the result as a string'''

    template = Template.compile(
        file=template_path,
        compilerSettings=dict(directiveStartToken="//#", directiveEndToken="//#",
                              commentStartToken="//##"), baseclass=dict, useCache=False)
    return str(template(**kw))
开发者ID:acmorrow,项目名称:mongo,代码行数:11,代码来源:generate_error_codes.py

示例14: get

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import compile [as 别名]
    def get(self):
        if self.logged_in:
            self.redirect('/oh')
        else:
            l_skel = Skel()
            l_skel.title = "Smashed.In"

            #Head
            head_path = os.path.join (os.path.dirname (__file__), 'templates/landing-head.tmpl')
            l_skel.addtohead (str((Template.compile(file=head_path) (searchList={}))))

            path = os.path.join (os.path.dirname (__file__), 'templates/landing-body.tmpl')
            l_skel.addtobody (str((Template.compile(file=path) (searchList={}))))

            #logging.error ("SESSION digging %s" % self.session)
            #logging.error ("AUTH digging %s" % self.auth.get_session_data())

            self.response.out.write(l_skel.gethtml())
开发者ID:thejasvibhat,项目名称:smashed,代码行数:20,代码来源:landing.py

示例15: get

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import compile [as 别名]
    def get(self):
        template_values = {}
        path = os.path.join(os.path.dirname(__file__), 'templates/comingsoon.tmpl')
        tclass = Template.compile (file = path)

        logging.info (self.logged_in)
        t = tclass(searchList=template_values)

        self.response.out.write(t)
开发者ID:thejasvibhat,项目名称:smashed,代码行数:11,代码来源:smashed.py


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