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


Python domain.Domain类代码示例

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


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

示例1: load

    def load(self,template,vars):
        dp=os.path.dirname(template)
        if dp != '':
            self.domain=dp
            
        filename=os.path.basename(template)

        try:
            d=Domain(self.domain, quoting=None, errors=4) # fixme: what do we really want for quoting?
            t=Domain(self.domain, errors=4).get_template(filename, quoting="str") # fixme: why create two Domains?
        except Exception as e:
            print "(domain is %s)" % self.domain
            raise e

        evars=evoque_dict()             # special dict that returns missing keys as "${key}"
        evars.update(vars)
        yaml_txt=t.evoque(evars)

        # fix eval errors:
        # fixed_yaml=re.sub('\[EvalError\(([a-z_]+)\)]', "${\g<1>}", yaml_txt) # ooh, magic! great.
        # fixed_yaml=re.sub('\[NameError: name &#39; ([a-z_]+)\)]', "${\g<1>}", yaml_txt) # ooh, magic! great.
        # fixed_yaml=re.sub('&lt;built-in function ([a-z_]+)&gt;', "${\g<1>}", fixed_yaml) # christ, more magic

#        warn("syml.load: fixed_yaml is %s" % fixed_yaml)
        d=yaml.load(yaml_txt)
            
        # "fix" config; ie, resolve referenced values
        d=self._fix_hash(d,d)
        return d
开发者ID:iandriver,项目名称:Rnaseq,代码行数:29,代码来源:superyaml.py

示例2: test_overlay

 def test_overlay(self):
     td = Domain(DEFAULT_DIR)
     t = td.get_template('overlay.html')
     self.assertEqual(
             eval("dict(%s)"%(t.eval_overlay)), dict(name="base.html"))
     space, overlay = t.get_space_overlay()
     self.failUnless(space is True)
     self.failUnless(t.labels == ["content"])
     # t.evoque(title="positive overlay test", parametrized="and happy")
     
     chain_pos = td.get_template('overlay_chain_pos.html')
     self.assertEqual(
         eval("dict(%s)"%(chain_pos.eval_overlay)), dict(name="overlay_mid.html"))
     space, overlay = chain_pos.get_space_overlay()
     self.failUnless(space is True)
     self.failUnless(chain_pos.labels == ["content"])
     # chain_pos.evoque(title="positive overlay test", parametrized="and happy")
     
     chain_neg = td.get_template('overlay_chain_neg.html')
     self.assertEqual(eval("dict(%s)"%(chain_neg.eval_overlay)), 
         dict(name="overlay_mid.html", space="negative"))
     space, overlay = chain_neg.get_space_overlay()
     self.failUnless(space is False)
     self.failUnless(chain_neg.labels == ["content", "footer"])
     # chain_neg.evoque(title="negative overlay test", parametrized="and happy")
     
     b = td.get_template('base.html')
     self.failUnless(b.labels == ["header", "content", "footer"])
     self.failIf(b.eval_overlay is not None)
     self.assertRaises((TypeError,), b.get_space_overlay)
开发者ID:DamnWidget,项目名称:goliat,代码行数:30,代码来源:test_overlay.py

示例3: load

    def load(self):
        # get globals if necessary
        if (self.globals == {}) and self.globals_file:
            f = open(self.globals_file, "r")
            self.globals = yaml.load(f)
            f.close

        # read config template (with globals)
        if not self.config_file:
            raise Exception("no config_file")

        if not self.domain:
            try:
                self.domain = self.globals["domain"]
            except:
                self.domain = os.getcwd()
                print "warning: looking for globals.yml in local directory!"

        try:
            t = Domain(self.domain).get_template(self.config_file)
        except Exception as e:
            print "(domain is %s)" % self.domain
            raise e

        conf_yaml = t.evoque(self.globals)
        conf = yaml.load(conf_yaml)

        # "fix" config; ie, resolve referenced values
        conf = self._fix_hash(conf, conf)
        conf.update({"globals": self.globals})

        self.config = conf
开发者ID:phonybone,项目名称:rna-seq-scripts,代码行数:32,代码来源:__init__.py

示例4: test_literals

 def test_literals(self):
     td = Domain(DEFAULT_DIR, restricted=RESTRICTED, errors=ERRORS)
     name = "template.html"
     t = td.get_template(name + "#literals")
     r = "<p>a $ dollar, a literal ${expr}, a % percent... { } ! \ etc.</p>"
     self.assertEqual(r, t.evoque())
     self.assertRaises((SyntaxError,), td.get_template, name+"#unescaped")
开发者ID:DamnWidget,项目名称:goliat,代码行数:7,代码来源:test_evoque.py

示例5: test_evoque_local_nested_from_string

 def test_evoque_local_nested_from_string(self):
     td = Domain(DEFAULT_DIR, restricted=RESTRICTED, errors=ERRORS)
     src = open(join(DEFAULT_DIR, "evoque_local_nested.html")).read()
     name = "fromstr"
     nested_name = name + "#label"
     data = dict(title="A Title", param="A Param")
     r = "<h1>A Title</h1><p>some A Param text</p>"
     # Load a from_string template that locally-nests another template
     td.set_template(name, src=src, from_string=True)
     t1 = td.get_template(name)
     # Verify nested template is not yet loaded
     self.assertEqual(False, t1.collection.has_template(nested_name))
     # Evoque, and verify response (multiple times, ensure data stays ok)
     self.assertEqual(r, t1.evoque(data)) # data as locals
     self.assertEqual(r, t1.evoque(**data)) # data as kw
     self.assertEqual(r, t1.evoque(data)) # data as locals
     self.assertEqual(r, t1.evoque(**data)) # data as kw
     # Verify nested template is now loaded
     self.assertEqual(True, t1.collection.has_template(nested_name))
     # Verify that tring to set nested template will fail
     self.assertRaises((ValueError,), td.set_template, nested_name, 
             src=src, from_string=True)
     t2 = td.get_template(nested_name)
     self.assertEqual(t2.ts, "<h1>%(title)s</h1><p>some %(param)s text</p>")
     self.assertEqual(r, t2.evoque(**data))
开发者ID:DamnWidget,项目名称:goliat,代码行数:25,代码来源:test_evoque.py

示例6: test_raw_nested

    def test_raw_nested(self):
        if not xml:
            return 
        td = Domain(DEFAULT_DIR, restricted=RESTRICTED, errors=ERRORS)
        t = td.get_template('raw_nested.html')
        self.assertEqual(t.evoque()[:87], """
$begin{table_row}
    $for{ col in row }
        &lt;td&gt;${col}&lt;/td&gt;
    $else""")
        self.failUnless(isinstance(t.evoque(), xml))
        # template #snapshot is already loaded with raw=True, quoting=str
        snap = td.get_template('raw_nested.html#snapshot')
        self.failUnless(snap.raw)
        self.failUnless(snap.qsclass is unistr)
        self.failUnless(isinstance(snap.evoque(), unistr))
        # template #snapshot is still already loaded...
        snapx = td.get_template('raw_nested.html#snapshot_xml')
        self.failUnless(isinstance(snapx.evoque(), xml))
        self.failUnless(snap.qsclass is unistr)
        self.failUnless(isinstance(snap.evoque(), unistr))
        snap.unload()
        self.failUnless(isinstance(snapx.evoque(), xml)) # reloads #snapshot
        snap = td.get_template('raw_nested.html#snapshot')
        self.failUnless(snap.qsclass is xml)
        self.failUnless(isinstance(snap.evoque(raw=True), xml))
开发者ID:DamnWidget,项目名称:goliat,代码行数:26,代码来源:test_evoque.py

示例7: test_get_mixed_name_src

 def test_get_mixed_name_src(self):
     td = Domain(DEFAULT_DIR, restricted=RESTRICTED, errors=ERRORS)
     name = '#label'
     src = 'evoque_local_nested.html'
     # Load a nested template and evoque it
     t = td.get_template(name, src)
     self.assertEqual(t.ts, "<h1>%(title)s</h1><p>some %(param)s text</p>")
开发者ID:DamnWidget,项目名称:goliat,代码行数:7,代码来源:test_evoque.py

示例8: write_rnaseq_script

def write_rnaseq_script(globals,pipeline,sample):
    domain=globals['domain']
    d=Domain(domain)
    t=d.get_template(globals['rnaseq_template'])

    # build up list of rnaseq.steps to be included in the final script:

    # augment globals hash with rnaseq vars:
    vars={'globals_file':'globals.yml',
          'rnaseq_steps':pipeline.as_python(),
          'steps_syml':os.path.join(globals['python_lib'],'pipeline.steps.syml'),     # hardcoded (for now?)
          'sample_yml':sample.conf_file,
          'timestamp':sample.timestamp(),
          }
    vars.update(globals)
    rnaseq_script=t.evoque(vars)

    # write script:
    os.mkdir(os.path.join(sample.working_dir(),'starflow','rnaseq'))
    fn=pipeline.script_filename('starflow/rnaseq','rnaseq','py')
    f=open(fn, 'w')
    f.write(rnaseq_script)
    f.close
    print "%s written" % fn
    return fn
开发者ID:icefoxx,项目名称:rna-seq-scripts,代码行数:25,代码来源:pipeline0.py

示例9: test_overlay_kwargs

 def test_overlay_kwargs(self):
     td = Domain(DEFAULT_DIR)
     r = "<base>base content!</base>"
     r_neg = ""
     responses = [ r, r, r, r, r_neg ]
     t = td.get_template('overlay_kwargs.html')
     for i, s in enumerate(t.test()):
         self.assertEqual(responses[i], s)
开发者ID:DamnWidget,项目名称:goliat,代码行数:8,代码来源:test_overlay.py

示例10: test_from_string_td

 def test_from_string_td(self):
     td = Domain(DEFAULT_DIR, restricted=RESTRICTED, errors=ERRORS)
     src = "<h1>${title}</h1><p>some ${param} text</p>"
     data = dict(title="A Title", param="A Param")
     r = "<h1>A Title</h1><p>some A Param text</p>"
     td.set_template("fromstr", src=src, from_string=True)
     t = td.get_template("fromstr")
     self.assertEqual(r, t.evoque(**data))
开发者ID:DamnWidget,项目名称:goliat,代码行数:8,代码来源:test_evoque.py

示例11: test_typical_usage_via_domain_implied_collection

 def test_typical_usage_via_domain_implied_collection(self):
     td = Domain(DEFAULT_DIR, restricted=RESTRICTED, errors=ERRORS)
     name = 'template.html'
     t = td.get_template(name)
     self.failUnless(t.collection is td.get_collection())
     self.failUnless(t.collection is td.collections[""])
     self.failUnless(t is t.collection.get_template(name))
     self.failUnless(t is t.collection.domain.get_template(name, 
             collection=t.collection))
开发者ID:DamnWidget,项目名称:goliat,代码行数:9,代码来源:test_evoque.py

示例12: test_evoque_raw

 def test_evoque_raw(self):
     td = Domain(DEFAULT_DIR, restricted=RESTRICTED, errors=ERRORS)
     name = 'evoque_local_nested.html#label'
     r = "<h1>${title}</h1><p>some ${param} text</p>"
     t = td.get_template(name, raw=True)
     self.assertEqual([], list(t.test()))
     self.assertEqual(None, t.ts)
     self.assertEqual(r, t.evoque(raw=True))
     self.assertEqual(r, t.evoque())
开发者ID:DamnWidget,项目名称:goliat,代码行数:9,代码来源:test_evoque.py

示例13: test_evoque_kwargs

 def test_evoque_kwargs(self):
     td = Domain(DEFAULT_DIR, restricted=RESTRICTED, errors=4)
     r = "<h1>TITLE</h1><p>some PARAM text</p>"
     r_raw = "<h1>${title}</h1><p>some ${param} text</p>"
     r_q_str = "&lt;h1&gt;TITLE&lt;/h1&gt;&lt;p&gt;some PARAM text&lt;/p&gt;"
     responses = [ r, r, r, r, r, r_raw, r, r_q_str, r ]
     t = td.get_template('evoque_kwargs.html')
     for i, s in enumerate(t.test()):
         self.assertEqual(responses[i], s)
开发者ID:DamnWidget,项目名称:goliat,代码行数:9,代码来源:test_evoque.py

示例14: test_manual_quoting

 def test_manual_quoting(self):
     td = Domain(DEFAULT_DIR, restricted=RESTRICTED, errors=ERRORS, quoting="str")
     name = "template.html#label"
     t = td.get_template(name)
     self.failUnless(unistr is t.qsclass)
     self.failUnless(unistr is t.evoque(title="str", param="<str/>").__class__)
     from cgi import escape
     self.assertEqual(self.r_xml_escaped, 
             t.evoque(title="q-xml", param=escape("<in>rm *</in>")))
开发者ID:DamnWidget,项目名称:goliat,代码行数:9,代码来源:test_evoque.py

示例15: test_file_addressing_collection_root_relative

 def test_file_addressing_collection_root_relative(self):
     td = Domain(DEFAULT_DIR, restricted=RESTRICTED, errors=ERRORS)
     name = '/template.html'
     src = '/template.html'
     self.assertRaises((LookupError,), td.get_template, name)
     self.assertRaises((LookupError,), td.get_template, name, src)
     # can have names start with "/" as long as the c-rel locator does not
     src = 'template.html'
     t = td.get_template(name, src=src)
     self.assertEqual(t.name, name) 
开发者ID:DamnWidget,项目名称:goliat,代码行数:10,代码来源:test_evoque.py


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