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


Python Template.decode方法代码示例

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


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

示例1: refresh

# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import decode [as 别名]
    def refresh(self):
        out = StringIO()
        compiler.Compiler(StringIO(str(self.parent.editor.text().toUtf8())), out).compile()
        static = 'file://' + self.api.CWD + 'templates/static'
        path = 'file://' + self.parent.tree.currentPage.path
        try:
            content = Template(out.getvalue()).substitute(static=static, path=path)
        except:
            content = out.getvalue()

        if hasattr(self.parent.tree.currentPage, 'config') and hasattr(self.parent.tree.currentPage.config, 'template'):
            tpl = self.parent.tree.currentPage.config.template
        else:
            tpl = API().config.options.app.default_template
        with file(self.api.CWD + 'templates/html/%s' % tpl) as f:
            page = Template(f.read()).substitute(static=static, content=content, path=path)

        enc = BeautifulSoup(page).originalEncoding
        print enc
        if enc is None:
            enc = 'utf8'

        content = page.decode(enc)

        if enc == 'ISO-8859-2':
            content = page.decode('cp1251')

        self.setHtml(content)
        self.js('reloadStylesheets()')
开发者ID:averrin,项目名称:demesne_old,代码行数:31,代码来源:ravenClasses.py

示例2: built_title

# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import decode [as 别名]
def built_title(study_info):
    ## 0. Needed variables
    title = study_info['title']
    #summary = study_info['summary']
    author = study_info['author']
    #date = study_info['date']

    ## 1. Applying to the template
    this_dir, this_filename = os.path.split(os.path.abspath(__file__))
    templ_fl = join(this_dir, '../data/templates/tex/portada.txt')
    file_ = open(templ_fl, "r")
    filecode = file_.read()
    filetext = Template(filecode).safe_substitute(title=title, author=author,
                                                  date='')
    filetext = filetext.decode('utf-8')
    return filetext
开发者ID:tgquintela,项目名称:Mscthesis,代码行数:18,代码来源:output_to_latex.py

示例3: create

# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import decode [as 别名]
 def create(self):
     fileList, totalSize = self.getBuildDirContents(OUT_DIR)
     print "Total size eq: {}".format(totalSize)
     installFiles = self.prepareInstallListTemplate(fileList) 
     uninstallFiles = self.prepareDeleteListTemplate(fileList)
     
     if os.path.isfile(SETUP_SCRIPT_PATH):
         raise RuntimeError("Cannot create setup script, file exists at {}".format(SETUP_SCRIPT_PATH))
     contents =  Template(NSIS_SCRIPT_TEMPLATE).substitute(
                                                           version = syncplay.version,
                                                           uninstallFiles = uninstallFiles,
                                                           installFiles = installFiles,
                                                           totalSize = totalSize,
                                                           )
     with codecs.open(SETUP_SCRIPT_PATH, "w", "utf-8-sig") as outfile:
         outfile.write(contents.decode('utf-8'))
开发者ID:wiiaboo,项目名称:syncplay,代码行数:18,代码来源:buildPy2exe.py

示例4: translate

# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import decode [as 别名]
  def translate(self):
    """
    Return the translated message. If the original is a string object,
    the return value is a string object. If it is a unicode object,
    the return value is a unicode object.
    """
    message = self.message
    if self.domain is None:
      # Map the translated string with given parameters
      if type(self.mapping) is dict:
        if isinstance(message, unicode) :
          message = message.encode('utf-8')
        message = Template(message).substitute(self.mapping)
    else:
      from Products.ERP5.ERP5Site import getSite
      request = Globals.get_request()
      translation_service = getGlobalTranslationService()
      if self.mapping:
        unicode_mapping = {}
        for k, v in self.mapping.iteritems():
          if isinstance(v, str):
            v = v.decode('utf-8')
          unicode_mapping[k] = v
      else:
        unicode_mapping = self.mapping
      translated_message = translation_service.translate(
                                             self.domain,
                                             message,
                                             mapping=unicode_mapping,
                                             context=getSite(request),
                                             default=self.default)
      if translated_message is not None:
        message = translated_message

    if isinstance(self.message, str):
      if isinstance(message, unicode):
        message = message.encode('utf-8')
    elif isinstance(message, str):
      message = message.decode('utf-8')

    return message
开发者ID:,项目名称:,代码行数:43,代码来源:

示例5: page_builder

# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import decode [as 别名]
def page_builder(info, study_info):
    ## 0. Needed variables
    varname = info['variables_name'].decode('utf-8').encode('utf-8')
    variables = info['variables']
    vardesc = info['Description'].decode('utf-8').encode('utf-8')

    typevar = info['type'].lower()
    if typevar in ['discrete', 'categorical']:
        tables = cat_tables(info)
        plots = cat_plots(info, study_info)
    elif typevar == 'continuous':
        tables = cont_tables(info)
        plots = cont_plots(info, study_info)
    elif typevar == 'coordinates':
        tables = coord_tables(info)
        plots = coord_plots(info, study_info)
    elif typevar in ['time', 'temporal']:
        tables = coord_tables(info)
        plots = coord_plots(info, study_info)
    elif typevar == 'tmpdist':
        tables = coord_tables(info)
        plots = coord_plots(info, study_info)
    else:
        print typevar, info['variables']

    ## 1. Applying to the template
    this_dir, this_filename = os.path.split(os.path.abspath(__file__))
    templ_fl = join(this_dir, '../data/templates/tex/page.txt')
    file_ = open(templ_fl, "r")
    filecode = file_.read()
    filetext = Template(filecode).safe_substitute(varname=varname,
                                                  variables=variables,
                                                  vardesc=vardesc,
                                                  tables=tables,
                                                  plots=plots,
                                                  comments='',
                                                  artificialcomments='')
    filetext = filetext.decode('utf-8')
    return filetext
开发者ID:tgquintela,项目名称:Mscthesis,代码行数:41,代码来源:output_to_latex.py

示例6: run

# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import decode [as 别名]
    def run(self, impl, dependList, appname):
        impl.log.info("step: self-defined step %s!" % appname)
        inputInfo = self.results[dependList[0]].output
        
        result = bundle(output=bundle(),script=bundle()) 
        
        #extend program path
        if self.self_defined[appname].has_key('program'):
            self.self_defined[appname].program = impl.expath(self.Path.prgDir, self.self_defined[appname].program)
        else:
            self.self_defined[appname].program = ''
        
        checkstatus = 'if [ $? -ne 0 ]; then\n\techo "[WARNING]  ${SAMPLE} - %s failed." >> %s\n\texit 1\nelse\n' %(appname,self.logfile)
        checkstatus += '\techo "[INFO   ]  ${SAMPLE} - %s complete." >> %s\nfi' % (appname,self.logfile)
        ParamDict = self.file.copy()
        ParamDict.update(self.option)
        ParamDict.update({
                "program": self.self_defined[appname].program,
                "checkstatus" : checkstatus
            })

        commandStr = self.self_defined[appname]['command'].strip()
        cmdStr = ''
        for l in commandStr.split('\n'):
            cmdStr += l.strip() + '\n'
        cmdStr = Template(cmdStr.decode('string-escape')).safe_substitute(ParamDict)
        
        output = self.self_defined[appname].get('output') and self.self_defined[appname]['output'] or ''
        
        JobParamList = []
        if self.self_defined[appname].get('summary'):
            scriptsdir = impl.mkdir(self.scriptsDir, 'standalone', self.option.multiSampleName)
            JobParamList.append({
                "SAMPLE": self.option.multiSampleName,
                "SCRDIR": scriptsdir
            })
        else:
            for sampleName in inputInfo:
                scriptsdir = impl.mkdir(self.scriptsDir,'standalone',sampleName)
                if output:
                    outputDict = {
                          "WORKDIR":self.option.workdir,
                          "SAMPLE":sampleName
                        }
                    output = Template(output).safe_substitute(outputDict)
                    result.output[sampleName] = output

                JobParamList.append({
                        "SAMPLE":sampleName,
                        "SCRDIR":scriptsdir,
                        "INPUT": inputInfo[sampleName],
                        "OUTPUT": output
                        })
            
        #write script
        scriptPath = \
        impl.write_scripts(
                name = appname,
                commands=cmdStr,
                JobParamList=JobParamList)
            
        #result
        result.script.update(scriptPath)
        return result
开发者ID:huangzhibo,项目名称:HelloWorld,代码行数:66,代码来源:S_self_defined.py


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