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


Python escape.xhtml_escape方法代碼示例

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


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

示例1: _render_parts

# 需要導入模塊: from tornado import escape [as 別名]
# 或者: from tornado.escape import xhtml_escape [as 別名]
def _render_parts(self, value, parts=[]):
        if isinstance(value, (unicode, bytes)):
            parts.append(escape.xhtml_escape(value))
        elif isinstance(value, int) or isinstance(value, long):
            parts.append(str(value))
        elif isinstance(value, datetime.datetime):
            parts.append(value.strftime("%Y-%m-%dT%H:%M:%S.000Z"))
        elif isinstance(value, dict):
            for name, subvalue in value.iteritems():
                if not isinstance(subvalue, list):
                    subvalue = [subvalue]
                for subsubvalue in subvalue:
                    parts.append('<' + escape.utf8(name) + '>')
                    self._render_parts(subsubvalue, parts)
                    parts.append('</' + escape.utf8(name) + '>')
        else:
            raise Exception("Unknown S3 value type %r", value) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:19,代碼來源:s3server.py

示例2: __init__

# 需要導入模塊: from tornado import escape [as 別名]
# 或者: from tornado.escape import xhtml_escape [as 別名]
def __init__(self, autoescape=_DEFAULT_AUTOESCAPE, namespace=None,
                 whitespace=None):
        """構造一個模板加載器.

        :arg str autoescape: 在模板命名空間中的函數名, 例如 "xhtml_escape",
            或默認情況下為 ``None`` 來禁用自動轉義.
        :arg dict namespace: 一個被加入默認模板命名空間中的字典或 ``None``.
        :arg str whitespace: 一個指定模板中whitespace默認行為的字符串;
            參見 `filter_whitespace` 查看可選項. 默認是 "single" 對於
            ".html" 和 ".js" 文件的結束, "all" 是為了其他文件.

        .. versionchanged:: 4.3
           添加 ``whitespace`` 參數.
        """
        self.autoescape = autoescape
        self.namespace = namespace or {}
        self.whitespace = whitespace
        self.templates = {}
        # self.lock protects self.templates.  It's a reentrant lock
        # because templates may load other templates via `include` or
        # `extends`.  Note that thanks to the GIL this code would be safe
        # even without the lock, but could lead to wasted work as multiple
        # threads tried to compile the same template simultaneously.
        self.lock = threading.RLock() 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:26,代碼來源:template.py

示例3: render_linked_js

# 需要導入模塊: from tornado import escape [as 別名]
# 或者: from tornado.escape import xhtml_escape [as 別名]
def render_linked_js(self, js_files: Iterable[str]) -> str:
        """Default method used to render the final js links for the
        rendered webpage.

        Override this method in a sub-classed controller to change the output.
        """
        paths = []
        unique_paths = set()  # type: Set[str]

        for path in js_files:
            if not is_absolute(path):
                path = self.static_url(path)
            if path not in unique_paths:
                paths.append(path)
                unique_paths.add(path)

        return "".join(
            '<script src="'
            + escape.xhtml_escape(p)
            + '" type="text/javascript"></script>'
            for p in paths
        ) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:24,代碼來源:web.py

示例4: render_linked_css

# 需要導入模塊: from tornado import escape [as 別名]
# 或者: from tornado.escape import xhtml_escape [as 別名]
def render_linked_css(self, css_files: Iterable[str]) -> str:
        """Default method used to render the final css links for the
        rendered webpage.

        Override this method in a sub-classed controller to change the output.
        """
        paths = []
        unique_paths = set()  # type: Set[str]

        for path in css_files:
            if not is_absolute(path):
                path = self.static_url(path)
            if path not in unique_paths:
                paths.append(path)
                unique_paths.add(path)

        return "".join(
            '<link href="' + escape.xhtml_escape(p) + '" '
            'type="text/css" rel="stylesheet"/>'
            for p in paths
        ) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:23,代碼來源:web.py

示例5: xsrf_form_html

# 需要導入模塊: from tornado import escape [as 別名]
# 或者: from tornado.escape import xhtml_escape [as 別名]
def xsrf_form_html(self) -> str:
        """An HTML ``<input/>`` element to be included with all POST forms.

        It defines the ``_xsrf`` input value, which we check on all POST
        requests to prevent cross-site request forgery. If you have set
        the ``xsrf_cookies`` application setting, you must include this
        HTML within all of your HTML forms.

        In a template, this method should be called with ``{% module
        xsrf_form_html() %}``

        See `check_xsrf_cookie()` above for more information.
        """
        return (
            '<input type="hidden" name="_xsrf" value="'
            + escape.xhtml_escape(self.xsrf_token)
            + '"/>'
        ) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:20,代碼來源:web.py

示例6: render_linked_js

# 需要導入模塊: from tornado import escape [as 別名]
# 或者: from tornado.escape import xhtml_escape [as 別名]
def render_linked_js(self, js_files):
        """Default method used to render the final js links for the
        rendered webpage.

        Override this method in a sub-classed controller to change the output.
        """
        paths = []
        unique_paths = set()

        for path in js_files:
            if not is_absolute(path):
                path = self.static_url(path)
            if path not in unique_paths:
                paths.append(path)
                unique_paths.add(path)

        return ''.join('<script src="' + escape.xhtml_escape(p) +
                       '" type="text/javascript"></script>'
                       for p in paths) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:21,代碼來源:web.py

示例7: render_linked_css

# 需要導入模塊: from tornado import escape [as 別名]
# 或者: from tornado.escape import xhtml_escape [as 別名]
def render_linked_css(self, css_files):
        """Default method used to render the final css links for the
        rendered webpage.

        Override this method in a sub-classed controller to change the output.
        """
        paths = []
        unique_paths = set()

        for path in css_files:
            if not is_absolute(path):
                path = self.static_url(path)
            if path not in unique_paths:
                paths.append(path)
                unique_paths.add(path)

        return ''.join('<link href="' + escape.xhtml_escape(p) + '" '
                       'type="text/css" rel="stylesheet"/>'
                       for p in paths) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:21,代碼來源:web.py

示例8: _render_parts

# 需要導入模塊: from tornado import escape [as 別名]
# 或者: from tornado.escape import xhtml_escape [as 別名]
def _render_parts(self, value, parts=[]):
        if isinstance(value, (unicode, bytes_type)):
            parts.append(escape.xhtml_escape(value))
        elif isinstance(value, int) or isinstance(value, long):
            parts.append(str(value))
        elif isinstance(value, datetime.datetime):
            parts.append(value.strftime("%Y-%m-%dT%H:%M:%S.000Z"))
        elif isinstance(value, dict):
            for name, subvalue in value.iteritems():
                if not isinstance(subvalue, list):
                    subvalue = [subvalue]
                for subsubvalue in subvalue:
                    parts.append('<' + escape.utf8(name) + '>')
                    self._render_parts(subsubvalue, parts)
                    parts.append('</' + escape.utf8(name) + '>')
        else:
            raise Exception("Unknown S3 value type %r", value) 
開發者ID:omererdem,項目名稱:honeything,代碼行數:19,代碼來源:s3server.py

示例9: __init__

# 需要導入模塊: from tornado import escape [as 別名]
# 或者: from tornado.escape import xhtml_escape [as 別名]
def __init__(self, autoescape=_DEFAULT_AUTOESCAPE, namespace=None):
        """Creates a template loader.

        root_directory may be the empty string if this loader does not
        use the filesystem.

        autoescape must be either None or a string naming a function
        in the template namespace, such as "xhtml_escape".
        """
        self.autoescape = autoescape
        self.namespace = namespace or {}
        self.templates = {}
        # self.lock protects self.templates.  It's a reentrant lock
        # because templates may load other templates via `include` or
        # `extends`.  Note that thanks to the GIL this code would be safe
        # even without the lock, but could lead to wasted work as multiple
        # threads tried to compile the same template simultaneously.
        self.lock = threading.RLock() 
開發者ID:omererdem,項目名稱:honeything,代碼行數:20,代碼來源:template.py

示例10: init_app

# 需要導入模塊: from tornado import escape [as 別名]
# 或者: from tornado.escape import xhtml_escape [as 別名]
def init_app(cls, application, jinja_options=None):
        """Init the application."""
        app_settings = application.settings

        _loader = FileSystemLoader(
            app_settings.get('template_path', 'templates')
        )

        _jinja_config = {
            'extensions': ['jinja2.ext.autoescape', 'jinja2.ext.with_'],
            'auto_reload': app_settings.get('autoreload', False),
            'loader': _loader,
            'cache_size': 50 if app_settings.get('compiled_template_cache', True) else 0,
            'autoescape': app_settings.get('autoescape', 'xhtml_escape') == "xhtml_escape"
        }

        _jinja_config.update(**(jinja_options or {}))
        environment = Environment(**_jinja_config)

        application.jinja_environment = environment
        app_settings['jinja_environment'] = environment
        environment.filters.update(tojson=tojson_filter, xhtml_escape=xhtml_escape, url_escape=url_escape, squeeze=squeeze, linkify=linkify)

        return environment 
開發者ID:DistributedSystemsGroup,項目名稱:zoe,代碼行數:26,代碼來源:request_handler.py

示例11: get_description

# 需要導入模塊: from tornado import escape [as 別名]
# 或者: from tornado.escape import xhtml_escape [as 別名]
def get_description(self, raw=False):
        """
        Returns desciption, escapes double quotes if sans_quotes is True, used
        for rendering description inside fields.
        """
        description = self.description
        if not description:
            description = ''

        if not raw:
            #description = escape.xhtml_escape(description)
            extra_params = 'target="_blank" rel="nofollow"'

            description = escape.linkify(description, True,
                extra_params=extra_params)

            #re_hash = re.compile(r'#[0-9a-zA-Z+]*',re.IGNORECASE)
            #for iterator in re_hash.finditer(description):

            description = re.sub(r'(\A|\s)#(\w+)', r'\1<a href="/tag/\2">#\2</a>', description)

            description = description.replace('\n', '<br>')
        return description 
開發者ID:MLTSHP,項目名稱:mltshp,代碼行數:25,代碼來源:sharedfile.py

示例12: xsrf_form_html

# 需要導入模塊: from tornado import escape [as 別名]
# 或者: from tornado.escape import xhtml_escape [as 別名]
def xsrf_form_html(self):
        """一個將被包含在所有POST表單中的HTML ``<input/>`` 標簽.

        它定義了我們在所有POST請求中為了預防偽造跨站請求所檢查的
        ``_xsrf`` 的輸入值. 如果你設置了 ``xsrf_cookies`` application設置,
        你必須包含這個HTML 在你所有的HTML表單.

        在一個模板中, 這個方法應該使用 ``{% module xsrf_form_html() %}``
        這種方式調用

        查看上麵的 `check_xsrf_cookie()` 了解更多信息.
        """
        return '<input type="hidden" name="_xsrf" value="' + \
            escape.xhtml_escape(self.xsrf_token) + '"/>' 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:16,代碼來源:web.py

示例13: generate

# 需要導入模塊: from tornado import escape [as 別名]
# 或者: from tornado.escape import xhtml_escape [as 別名]
def generate(self, **kwargs):
        """用給定參數生成此模板."""
        namespace = {
            "escape": escape.xhtml_escape,
            "xhtml_escape": escape.xhtml_escape,
            "url_escape": escape.url_escape,
            "json_encode": escape.json_encode,
            "squeeze": escape.squeeze,
            "linkify": escape.linkify,
            "datetime": datetime,
            "_tt_utf8": escape.utf8,  # for internal use
            "_tt_string_types": (unicode_type, bytes),
            # __name__ and __loader__ allow the traceback mechanism to find
            # the generated source code.
            "__name__": self.name.replace('.', '_'),
            "__loader__": ObjectDict(get_source=lambda name: self.code),
        }
        namespace.update(self.namespace)
        namespace.update(kwargs)
        exec_in(self.compiled, namespace)
        execute = namespace["_tt_execute"]
        # Clear the traceback module's cache of source data now that
        # we've generated a new template (mainly for this module's
        # unittests, where different tests reuse the same name).
        linecache.clearcache()
        return execute() 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:28,代碼來源:template.py

示例14: test_escape_return_types

# 需要導入模塊: from tornado import escape [as 別名]
# 或者: from tornado.escape import xhtml_escape [as 別名]
def test_escape_return_types(self):
        # On python2 the escape methods should generally return the same
        # type as their argument
        self.assertEqual(type(xhtml_escape("foo")), str)
        self.assertEqual(type(xhtml_escape(u("foo"))), unicode_type) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:7,代碼來源:escape_test.py


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