示例#1
0
 def _compile_from_file(self, path, filename):
     if path is not None:
         util.verify_directory(os.path.dirname(path))
         filemtime = os.stat(filename)[stat.ST_MTIME]
         if (not os.path.exists(path)
                 or os.stat(path)[stat.ST_MTIME] < filemtime):
             data = util.read_file(filename)
             _compile_module_file(self, data, filename, path,
                                  self.module_writer)
         module = compat.load_module(self.module_id, path)
         del sys.modules[self.module_id]
         if module._magic_number != codegen.MAGIC_NUMBER:
             data = util.read_file(filename)
             _compile_module_file(self, data, filename, path,
                                  self.module_writer)
             module = compat.load_module(self.module_id, path)
             del sys.modules[self.module_id]
         ModuleInfo(module, path, self, filename, None, None)
     else:
         # template filename and no module directory, compile code
         # in memory
         data = util.read_file(filename)
         code, module = _compile_text(self, data, filename)
         self._source = None
         self._code = code
         ModuleInfo(module, None, self, filename, code, None)
     return module
示例#2
0
    def test_load_module(self):
        fn = os.path.join(os.path.dirname(__file__), "test_util.py")
        sys.modules.pop("mako.template")
        module = compat.load_module("mako.template", fn)
        self.assertNotIn("mako.template", sys.modules)
        self.assertIn("UtilTest", dir(module))
        import mako.template

        self.assertNotEqual(module, mako.template)
示例#3
0
    def test_load_module(self):
        path = os.path.join(os.path.dirname(__file__), "module_to_import.py")
        some_module = compat.load_module("test.module_to_import", path)

        not_in("test.module_to_import", sys.modules)
        in_("some_function", dir(some_module))
        import test.module_to_import

        ne_(some_module, test.module_to_import)
示例#4
0
文件: test_util.py 项目: zzzeek/mako
    def test_load_module(self):
        path = os.path.join(os.path.dirname(__file__), "module_to_import.py")
        some_module = compat.load_module("test.module_to_import", path)

        self.assertNotIn("test.module_to_import", sys.modules)
        self.assertIn("some_function", dir(some_module))
        import test.module_to_import

        self.assertNotEqual(some_module, test.module_to_import)
示例#5
0
文件: template.py 项目: jchalex/xcat
 def _compile_from_file(self, path, filename):
     if path is not None:
         util.verify_directory(os.path.dirname(path))
         filemtime = os.stat(filename)[stat.ST_MTIME]
         if not os.path.exists(path) or \
                     os.stat(path)[stat.ST_MTIME] < filemtime:
             data = util.read_file(filename)
             _compile_module_file(
                         self,
                         data,
                         filename,
                         path,
                         self.module_writer)
         module = compat.load_module(self.module_id, path)
         del sys.modules[self.module_id]
         if module._magic_number != codegen.MAGIC_NUMBER:
             data = util.read_file(filename)
             _compile_module_file(
                         self,
                         data,
                         filename,
                         path,
                         self.module_writer)
             module = compat.load_module(self.module_id, path)
             del sys.modules[self.module_id]
         ModuleInfo(module, path, self, filename, None, None)
     else:
         # template filename and no module directory, compile code
         # in memory
         data = util.read_file(filename)
         code, module = _compile_text(
                             self,
                             data,
                             filename)
         self._source = None
         self._code = code
         ModuleInfo(module, None, self, filename, code, None)
     return module
示例#6
0
    def test_load_module(self):
        fn = os.path.join(os.path.dirname(__file__), "test_util.py")
        module = compat.load_module("mako.template", fn)
        import mako.template

        self.assertEqual(module, mako.template)
示例#7
0
文件: test_util.py 项目: 10sr/hue
 def test_load_module(self):
     fn = os.path.join(os.path.dirname(__file__), 'test_util.py')
     module = compat.load_module('mako.template', fn)
     import mako.template
     self.assertEqual(module, mako.template)