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


Python loaders.FileSystemLoader方法代码示例

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


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

示例1: main

# 需要导入模块: from jinja2 import loaders [as 别名]
# 或者: from jinja2.loaders import FileSystemLoader [as 别名]
def main():
    parser = argparse.ArgumentParser(description='Example OIDC Provider.')
    parser.add_argument("-p", "--port", default=80, type=int)
    parser.add_argument("-b", "--base", default="https://localhost", type=str)
    parser.add_argument("-d", "--debug", action="store_true")
    parser.add_argument("settings")
    args = parser.parse_args()

    # Load configuration
    with open(args.settings, "r") as f:
        settings = yaml.load(f)

    issuer = args.base.rstrip("/")

    template_dirs = settings["server"].get("template_dirs", "templates")
    jinja_env = Environment(loader=FileSystemLoader(template_dirs))
    authn_broker, auth_routing = setup_authentication_methods(
        settings["authn"], jinja_env)

    # Setup userinfo
    userinfo_conf = settings["userinfo"]
    cls = make_cls_from_name(userinfo_conf["class"])
    i = cls(**userinfo_conf["kwargs"])
    userinfo = UserInfo(i)

    client_db = {}
    provider = Provider(issuer, SessionDB(issuer), client_db, authn_broker,
                        userinfo, AuthzHandling(), verify_client, None)
    provider.baseurl = issuer
    provider.symkey = rndstr(16)

    # Setup keys
    path = os.path.join(os.path.dirname(__file__), "static")
    try:
        os.makedirs(path)
    except OSError, e:
        if e.errno != errno.EEXIST:
            raise e
        pass 
开发者ID:ga4gh,项目名称:ga4gh-server,代码行数:41,代码来源:server.py

示例2: setUp

# 需要导入模块: from jinja2 import loaders [as 别名]
# 或者: from jinja2.loaders import FileSystemLoader [as 别名]
def setUp(self):
        self.loader = FileSystemLoader(self.TEMPLATE_PATH)
        self.env = Environment(loader=self.loader,
                               autoescape=True,
                               extensions=['jinja2.ext.with_', 'jinja2.ext.autoescape'])
        self.temp_dir = tempfile.mkdtemp() 
开发者ID:jonbretman,项目名称:jinja-to-js,代码行数:8,代码来源:test_jinja_to_js.py

示例3: run

# 需要导入模块: from jinja2 import loaders [as 别名]
# 或者: from jinja2.loaders import FileSystemLoader [as 别名]
def run(self, results):
        """Writes report.
        @param results: Cuckoo results dict.
        @raise CuckooReportError: if fails to write report.
        """
        if not HAVE_JINJA2:
            raise CuckooReportError("Failed to generate HTML report: "
                                    "Jinja2 Python library is not installed")

        shots_path = os.path.join(self.analysis_path, "shots")
        if os.path.exists(shots_path):
            shots = []
            counter = 1
            for shot_name in os.listdir(shots_path):
                if not shot_name.endswith(".jpg"):
                    continue

                shot_path = os.path.join(shots_path, shot_name)

                if os.path.getsize(shot_path) == 0:
                    continue

                shot = {}
                shot["id"] = os.path.splitext(File(shot_path).get_name())[0]
                shot["data"] = base64.b64encode(open(shot_path, "rb").read())
                shots.append(shot)

                counter += 1

            shots.sort(key=lambda shot: shot["id"])
            results["screenshots"] = shots
        else:
            results["screenshots"] = []

        env = Environment(autoescape=True)
        env.loader = FileSystemLoader(os.path.join(CUCKOO_ROOT,
                                                   "data", "html"))

        try:
            tpl = env.get_template("report.html")
            html = tpl.render({"results": results})
        except Exception as e:
            raise CuckooReportError("Failed to generate HTML report: %s" % e)
        
        try:
            with codecs.open(os.path.join(self.reports_path, "report.html"), "w", encoding="utf-8") as report:
                report.write(html)
        except (TypeError, IOError) as e:
            raise CuckooReportError("Failed to write HTML report: %s" % e)

        return True 
开发者ID:davidoren,项目名称:CuckooSploit,代码行数:53,代码来源:reporthtml.py


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