Esempio n. 1
0
def reload_modules(updated):
    for module in updated:
        cherrypy.log("Reloading %s" % module)
        ext = updated[module][0].rsplit('.', 1)[1]
        
        if ext=='kid':
            compile_file(updated[module][0])
            reload(sys.modules[module])
        elif ext=='py':
            reload(sys.modules[module])
        else:
            raise 'unknown module type'
Esempio n. 2
0
def test_tracking_2():
    """Check error tracking when importing a Kid template."""
    from kid.compiler import compile_file
    f = KidFileWriter()
    xml = """<!-- test1 -->
        <?python ok = 1/2 ?>
        <!-- test2 -->
        <?python oops = 1/0 ?>
        <xml>
        <title>import fails</title>
        </xml>"""
    f.write(xml)
    try:
        e = compile_file(file=f.filename(True))
    except Exception:
        e = None
    assert e == True, 'This file cannot be compiled properly.'
    for call in (kid.load_template, kid.Template):
        f.write(xml)
        e = str(raises(ZeroDivisionError, call, file=f.filename()))
        assert 'integer division or modulo by zero' in e
        if python24:
            assert 'Error location in template file ' in e
            assert f.filename() in e
            assert 'between line 4, column 8 and line 5, column 8:' in e
            assert '<?python oops = 1/0 ?>' in e
        assert 'xml>' not in e and 'title>' not in e
        assert 'import fails' not in e
Esempio n. 3
0
def test_tracking_2():
    """Check error tracking when importing a Kid template."""
    from kid.compiler import compile_file
    f = KidFileWriter()
    xml = """<!-- test1 -->
        <?python ok = 1/2 ?>
        <!-- test2 -->
        <?python oops = 1/0 ?>
        <xml>
        <title>import fails</title>
        </xml>"""
    f.write(xml)
    try:
        e = compile_file(file=f.filename(True))
    except Exception:
        e = None
    assert e == True, 'This file cannot be compiled properly.'
    for call in (kid.load_template, kid.Template):
        f.write(xml)
        e = str(raises(ZeroDivisionError, call, file=f.filename()))
        assert 'integer division or modulo by zero' in e
        if python24:
            assert 'Error location in template file ' in e
            assert f.filename() in e
            assert 'between line 4, column 8 and line 5, column 8:' in e
            assert '<?python oops = 1/0 ?>' in e
        assert 'xml>' not in e and 'title>' not in e
        assert 'import fails' not in e
Esempio n. 4
0
 def byte_compile(self, files):
     """Byte-compile all Python modules and all Kid templates."""
     build_py.byte_compile(self, files)
     kid_files = [f for f in files if f.endswith('.kid')]
     if not kid_files:
         return
     from distutils import log
     try:
         from kid.compiler import compile_file
     except ImportError:
         log.warn("Kid templates cannot be compiled,"
             " because Kid is not installed.")
         return
     if self.dry_run:
         return
     for kid_file in kid_files:
         if compile_file(kid_file, force=self.force):
             log.info("byte-compiling %s", kid_file)
         else:
             log.debug("skipping byte-compilation of %s", kid_file)
Esempio n. 5
0
 def byte_compile(self, files):
     """Byte-compile all Python modules and all Kid templates."""
     build_py.byte_compile(self, files)
     kid_files = [f for f in files if f.endswith('.kid')]
     if not kid_files:
         return
     from distutils import log
     try:
         from kid.compiler import compile_file
     except ImportError:
         log.warn("Kid templates cannot be compiled,"
             " because Kid is not installed.")
         return
     if self.dry_run:
         return
     for kid_file in kid_files:
         if compile_file(kid_file, force=self.force):
             log.info("byte-compiling %s", kid_file)
         else:
             log.debug("skipping byte-compilation of %s", kid_file)