當前位置: 首頁>>代碼示例>>Python>>正文


Python sandbox.SandboxedEnvironment方法代碼示例

本文整理匯總了Python中jinja2.sandbox.SandboxedEnvironment方法的典型用法代碼示例。如果您正苦於以下問題:Python sandbox.SandboxedEnvironment方法的具體用法?Python sandbox.SandboxedEnvironment怎麽用?Python sandbox.SandboxedEnvironment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在jinja2.sandbox的用法示例。


在下文中一共展示了sandbox.SandboxedEnvironment方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: from jinja2 import sandbox [as 別名]
# 或者: from jinja2.sandbox import SandboxedEnvironment [as 別名]
def main():
    """Regenerate pages listed in global `REGEN` list."""
    env = SandboxedEnvironment(undefined=StrictUndefined)
    for target, get_data, template in REGEN:
        print("Regenerating", target)
        data = get_data()
        template_text = requests.get(template).text
        try:
            rendered = env.from_string(template_text).render(**data)
        except TemplateError as error:
            print("Error while regenerating", target)
            print(error)
            return 1
        with open(target, "w") as target:
            target.write(rendered)
    return 0 
開發者ID:pawamoy,項目名稱:mkdocstrings,代碼行數:18,代碼來源:regen_docs.py

示例2: main

# 需要導入模塊: from jinja2 import sandbox [as 別名]
# 或者: from jinja2.sandbox import SandboxedEnvironment [as 別名]
def main():
    """Regenerate pages listed in global `REGEN` list."""
    env = SandboxedEnvironment(undefined=StrictUndefined)
    for target, get_data, template in REGEN:
        print("Regenerating", target)
        data = get_data()
        if Path(template).exists():
            with open(template) as fd:
                template_text = fd.read()
        else:
            template_text = requests.get(template).text
        try:
            rendered = env.from_string(template_text).render(**data)
        except TemplateError as error:
            print("Error while regenerating", target)
            print(error)
            return 1
        with open(target, "w") as target:
            target.write(rendered)
    return 0 
開發者ID:pawamoy,項目名稱:aria2p,代碼行數:22,代碼來源:regen_docs.py

示例3: __init__

# 需要導入模塊: from jinja2 import sandbox [as 別名]
# 或者: from jinja2.sandbox import SandboxedEnvironment [as 別名]
def __init__(self, outpath, tmpltpath):
        """
        Parameters
        ----------
        outpath : string
          Directory path for RST output files
        tmpltpath : string
          Directory path for autosummary template files
        """

        self.outpath = outpath
        self.template_loader = FileSystemLoader(tmpltpath)
        self.template_env = SandboxedEnvironment(loader=self.template_loader)
        self.template_env.filters['underline'] = _underline
        self.template_env.filters['escape'] = rst_escape
        self.template_env.filters['e'] = rst_escape
        self.template = self.template_env.get_template('module.rst') 
開發者ID:bwohlberg,項目名稱:sporco,代碼行數:19,代碼來源:automodule.py

示例4: __init__

# 需要導入模塊: from jinja2 import sandbox [as 別名]
# 或者: from jinja2.sandbox import SandboxedEnvironment [as 別名]
def __init__(self, app, extra_context):
        template_loader = BuiltinTemplateLoader()
        template_loader.init(app.builder)
        template_env = SandboxedEnvironment(loader=template_loader)
        template_env.filters['rst_escape'] = rst_escape_filter
        template_env.filters['underline'] = underline_filter
        template_env.filters['as_extlink'] = as_extlink_filter
        template_env.filters['prefixes'] = prefixes_filter
        template_env.filters['rst_link'] = rst_link_filter
        self.env = template_env
        self.templates: Dict[str, Any] = {}
        self.extra_context = extra_context 
開發者ID:bioconda,項目名稱:bioconda-utils,代碼行數:14,代碼來源:sphinxext.py

示例5: render

# 需要導入模塊: from jinja2 import sandbox [as 別名]
# 或者: from jinja2.sandbox import SandboxedEnvironment [as 別名]
def render(self, context, language_code=DEFAULT_LANG):
        """
        Render this notification template with given context and language

        Returns a dict containing all content fields of the template. Example:

        {'subject': 'bar', 'body': 'baz', 'html_body': '<b>foobar</b>'}

        """

        env = SandboxedEnvironment(trim_blocks=True, lstrip_blocks=True, undefined=StrictUndefined)
        env.filters['format_datetime'] = format_datetime

        logger.debug('Rendering template for notification %s' % self.type)

        activate(language_code)

        try:
            rendered_notification = {
                attr: env.from_string(getattr(self, attr)).render(context)
                for attr in ('subject', 'html_body')
            }
            if self.body:
                rendered_notification['body'] = env.from_string(self.body).render(context)
            else:
                # if text body is empty use html body without tags as text body
                rendered_notification['body'] = strip_tags(rendered_notification['html_body'])
            return rendered_notification
        except TemplateError as e:
            raise NotificationTemplateException(e) from e 
開發者ID:City-of-Helsinki,項目名稱:linkedevents,代碼行數:32,代碼來源:models.py

示例6: __init__

# 需要導入模塊: from jinja2 import sandbox [as 別名]
# 或者: from jinja2.sandbox import SandboxedEnvironment [as 別名]
def __init__(self, engine):
        # Autoescape needs to be False to avoid html-encoding ampersands in emails. This
        # does not create security vulns as on the frontend, html is escaped using Handlebars,
        # and in emails, html is allowed and ampersands are escaped with markdown's renderer.
        self.env = SandboxedEnvironment(autoescape=False)

        self.engine = engine
        self.active = {}
        self.data = {} 
開發者ID:linkedin,項目名稱:iris,代碼行數:11,代碼來源:cache.py

示例7: test_sanitize_unicode_dict

# 需要導入模塊: from jinja2 import sandbox [as 別名]
# 或者: from jinja2.sandbox import SandboxedEnvironment [as 別名]
def test_sanitize_unicode_dict():
    from jinja2.sandbox import SandboxedEnvironment
    from iris.utils import sanitize_unicode_dict

    # Use jinja the same way as in sender
    env = SandboxedEnvironment(autoescape=False)
    template = env.from_string('{{var}} {{var2}} {{nested.nest}}')
    bad_context = {'var': b'\xe2\x80\x99', 'var2': 2, 'nested': {'nest': b'\xe2\x80\x99'}}

    assert '\\xe2' in template.render(**bad_context)

    good_render = template.render(**sanitize_unicode_dict(bad_context))
    assert '\\xe2' not in good_render
    assert b'\xe2\x80\x99'.decode('utf-8') in good_render 
開發者ID:linkedin,項目名稱:iris,代碼行數:16,代碼來源:test_sender.py

示例8: test_item_and_attribute

# 需要導入模塊: from jinja2 import sandbox [as 別名]
# 或者: from jinja2.sandbox import SandboxedEnvironment [as 別名]
def test_item_and_attribute(self):
        from jinja2.sandbox import SandboxedEnvironment

        for env in Environment(), SandboxedEnvironment():
            # the |list is necessary for python3
            tmpl = env.from_string('{{ foo.items()|list }}')
            assert tmpl.render(foo={'items': 42}) == "[('items', 42)]"
            tmpl = env.from_string('{{ foo|attr("items")()|list }}')
            assert tmpl.render(foo={'items': 42}) == "[('items', 42)]"
            tmpl = env.from_string('{{ foo["items"] }}')
            assert tmpl.render(foo={'items': 42}) == '42' 
開發者ID:chalasr,項目名稱:Flask-P2P,代碼行數:13,代碼來源:api.py

示例9: __init__

# 需要導入模塊: from jinja2 import sandbox [as 別名]
# 或者: from jinja2.sandbox import SandboxedEnvironment [as 別名]
def __init__(self,
                 job_name,
                 query_project=None,
                 location='US',
                 default_project=None,
                 default_dataset=None,
                 json_credentials_path=None):
        """
        :param job_name: used as job name prefix
        :param query_project: project used to submit queries
        :param location: BigQuery defaults to 'US'
        :param default_project: project to use when tablespec does not specify
            project
        :param default_dataset: dataset to use when tablespec does not specify
            dataset, if default_project is also set
        :param json_credentials_path: (optional) path to service account JSON
            credentials file
        """
        self.job_id_prefix = job_name + '-'
        self.query_project = query_project
        self.location = location
        if default_project is None and query_project is not None:
            self.default_project = query_project
        else:
            self.default_project = default_project
        self.json_credentials_path = json_credentials_path
        self.default_dataset = default_dataset
        self.bq = None
        self.jinja2 = SandboxedEnvironment() 
開發者ID:GoogleCloudPlatform,項目名稱:professional-services,代碼行數:31,代碼來源:bqpipeline.py

示例10: process_template

# 需要導入模塊: from jinja2 import sandbox [as 別名]
# 或者: from jinja2.sandbox import SandboxedEnvironment [as 別名]
def process_template(content: str) -> str:
    env = SandboxedEnvironment()
    template = env.from_string(content)
    context = {
        "current_user_id": ExtraCache.current_user_id,
        "current_username": ExtraCache.current_username,
    }
    return template.render(context) 
開發者ID:apache,項目名稱:incubator-superset,代碼行數:10,代碼來源:tags.py

示例11: __init__

# 需要導入模塊: from jinja2 import sandbox [as 別名]
# 或者: from jinja2.sandbox import SandboxedEnvironment [as 別名]
def __init__(
        self,
        database: "Database",
        query: Optional["Query"] = None,
        table: Optional["SqlaTable"] = None,
        extra_cache_keys: Optional[List[Any]] = None,
        **kwargs: Any,
    ) -> None:
        self.database = database
        self.query = query
        self.schema = None
        if query and query.schema:
            self.schema = query.schema
        elif table:
            self.schema = table.schema

        extra_cache = ExtraCache(extra_cache_keys)

        self.context = {
            "url_param": extra_cache.url_param,
            "current_user_id": extra_cache.current_user_id,
            "current_username": extra_cache.current_username,
            "cache_key_wrapper": extra_cache.cache_key_wrapper,
            "filter_values": filter_values,
            "form_data": {},
        }
        self.context.update(kwargs)
        self.context.update(jinja_base_context)
        if self.engine:
            self.context[self.engine] = self
        self.env = SandboxedEnvironment() 
開發者ID:apache,項目名稱:incubator-superset,代碼行數:33,代碼來源:jinja_context.py


注:本文中的jinja2.sandbox.SandboxedEnvironment方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。