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


Python escape.url_escape方法代码示例

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


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

示例1: _check_group_whitelist

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import url_escape [as 别名]
def _check_group_whitelist(self, user_id, access_token):
        http_client = AsyncHTTPClient()
        headers = _api_headers(access_token)
        # Check if user is a member of any group in the whitelist
        for group in map(url_escape, self.gitlab_group_whitelist):
            url = "%s/groups/%s/members/%s%d" % (
                self.gitlab_api,
                quote(group, safe=''),
                self.member_api_variant,
                user_id,
            )
            req = HTTPRequest(url, method="GET", headers=headers)
            resp = await http_client.fetch(req, raise_error=False)
            if resp.code == 200:
                return True  # user _is_ in group
        return False 
开发者ID:jupyterhub,项目名称:oauthenticator,代码行数:18,代码来源:gitlab.py

示例2: _render

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import url_escape [as 别名]
def _render(self, login_error=None, username=None):
        self._register_template_path()
        return self.render_template(
            'native-login.html',
            next=url_escape(self.get_argument('next', default='')),
            username=username,
            login_error=login_error,
            custom_html=self.authenticator.custom_html,
            login_url=self.settings['login_url'],
            enable_signup=self.authenticator.enable_signup,
            two_factor_auth=self.authenticator.allow_2fa,
            authenticator_login_url=url_concat(
                self.authenticator.login_url(self.hub.base_url),
                {'next': self.get_argument('next', '')},
            ),
        ) 
开发者ID:jupyterhub,项目名称:nativeauthenticator,代码行数:18,代码来源:handlers.py

示例3: init_app

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import url_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

示例4: fetch

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import url_escape [as 别名]
def fetch(request, *parts, **kwargs):
    # Handle URL strings

    # Since base_url is already escaped, unescape it.
    path = url_escape(url_path_join(*parts), plus=False)

    # Make request.
    method = 'GET'
    if 'method' in kwargs and kwargs['method']:
        method = kwargs['method']

    body = None
    if 'body' in kwargs and kwargs['body']:
        body = kwargs['body']

    return request(method, path, data=body)
# END - Remove once transition to jupyter_server occurs 
开发者ID:elyra-ai,项目名称:elyra,代码行数:19,代码来源:conftest.py

示例5: make_oembed_url

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import url_escape [as 别名]
def make_oembed_url(url):
        url_parsed = None
        try:
            url_parsed = urlparse(url)
        except:
            return None

        if url_parsed.hostname.lower() not in ['youtube.com', 'www.youtube.com', 'vimeo.com', 'www.vimeo.com', 'youtu.be', 'flic.kr', 'flickr.com', 'www.flickr.com']:
            return None

        oembed_url = None
        if url_parsed.hostname.lower() in ['youtube.com', 'www.youtube.com', 'youtu.be']:
            to_url = 'https://%s%s?%s' % (url_parsed.hostname, url_parsed.path, url_parsed.query)
            oembed_url = 'https://www.youtube.com/oembed?url=%s&maxwidth=550&format=json' % (url_escape(to_url))
        elif url_parsed.hostname.lower() in ['vimeo.com', 'www.vimeo.com']:
            to_url = 'https://%s%s' % (url_parsed.hostname, url_parsed.path)
            oembed_url = 'https://vimeo.com/api/oembed.json?url=%s&maxwidth=550' % (url_escape(to_url))
        elif url_parsed.hostname.lower() in ['flic.kr', 'flickr.com', 'www.flickr.com']:
            to_url = 'https://%s%s' % (url_parsed.hostname, url_parsed.path)
            oembed_url = 'https://www.flickr.com/services/oembed/?url=%s&maxwidth=550&format=json' % (url_escape(to_url))
        return oembed_url 
开发者ID:MLTSHP,项目名称:mltshp,代码行数:23,代码来源:sourcefile.py

示例6: test_another_user_commenting_will_update_the_files_activity_at

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import url_escape [as 别名]
def test_another_user_commenting_will_update_the_files_activity_at(self):
        request = HTTPRequest(self.get_url('/p/%s/comment' % self.shf.share_key), 'POST', {'Cookie':'_xsrf=%s;sid=%s' % (self.xsrf, self.sid)}, "body=%s&_xsrf=%s" % (url_escape("a comment"), self.xsrf))
        self.http_client.fetch(request, self.stop)
        response = self.wait()

        time.sleep(1)

        
        sf = Sharedfile.get('id=%s', self.shf.id)
        activity_one = sf.activity_at

        request = HTTPRequest(self.get_url('/p/%s/comment' % self.shf.share_key), 'POST', {'Cookie':'_xsrf=%s;sid=%s' % (self.xsrf, self.sid)}, "body=%s&_xsrf=%s" % (url_escape("a second comment"), self.xsrf))
        self.http_client.fetch(request, self.stop)
        response = self.wait()

        
        sf = Sharedfile.get('id=%s', self.shf.id)
        activity_two = sf.activity_at

        self.assertTrue(activity_two > activity_one) 
开发者ID:MLTSHP,项目名称:mltshp,代码行数:22,代码来源:conversations_tests.py

示例7: connect_kernel

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import url_escape [as 别名]
def connect_kernel():
    # TODO check status busy/idle
    run_sync(manager.list_kernels())
    kernels = {
        kernel_id: dateparser.parse(kernel["last_activity"])
        for kernel_id, kernel in manager._kernels.items()
    }
    kernel_id = url_escape(sorted(kernels, key=kernels.get)[0])
    client = GatewayClient.instance()
    url = url_path_join(client.ws_url, client.kernels_endpoint, kernel_id, "channels")
    ws_req = HTTPRequest(url=url)
    return run_sync(websocket_connect(ws_req)) 
开发者ID:materialsproject,项目名称:MPContribs,代码行数:14,代码来源:views.py

示例8: post

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import url_escape [as 别名]
def post(self) -> None:
        lexer = self.get_body_argument("lexer")
        raw = self.get_body_argument("code", strip=False)
        expiry = self.get_body_argument("expiry")
        filename = self.get_body_argument("filename", None)

        if not raw.strip():
            log.info("APINew.post: a paste was submitted without content")
            raise tornado.web.HTTPError(400)

        if lexer not in utility.list_languages():
            log.info("APINew.post: a paste was submitted with an invalid lexer")
            raise tornado.web.HTTPError(400)

        if expiry not in utility.expiries:
            log.info(
                "APINew.post: a paste was submitted with an invalid expiry"
            )
            raise tornado.web.HTTPError(400)

        paste = database.Paste(
            utility.slug_create(), utility.expiries[expiry], "deprecated-api"
        )
        paste.files.append(database.File(paste.slug, raw, lexer, filename))

        with database.session() as session:
            session.add(paste)
            session.commit()

            req_url = self.request.full_url()
            location = paste.slug
            if filename:
                location += "#" + url_escape(filename)
            self.write(
                {
                    "paste_id": paste.slug,
                    "removal_id": paste.removal,
                    "paste_url": urljoin(req_url, f"/{location}"),
                    "raw_url": urljoin(req_url, f"/raw/{paste.files[0].slug}"),
                }
            ) 
开发者ID:supakeen,项目名称:pinnwand,代码行数:43,代码来源:api_deprecated.py

示例9: reverse

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import url_escape [as 别名]
def reverse(self, *args):
        assert self._path is not None, \
            "Cannot reverse url regex " + self.regex.pattern
        assert len(args) == self._group_count, "required number of arguments "\
            "not found"
        if not len(args):
            return self._path
        converted_args = []
        for a in args:
            if not isinstance(a, (unicode_type, bytes)):
                a = str(a)
            converted_args.append(escape.url_escape(utf8(a), plus=False))
        return self._path % tuple(converted_args) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:15,代码来源:web.py

示例10: generate

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import url_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

示例11: test_task_handler

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import url_escape [as 别名]
def test_task_handler(self):
        response = self.fetch('/task?url=%s' % url_escape(self.get_url('/sequence')))
        self.assertEqual(response.body, b"got response: 123") 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:5,代码来源:gen_test.py

示例12: test_url_escape_unicode

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import url_escape [as 别名]
def test_url_escape_unicode(self):
        tests = [
            # byte strings are passed through as-is
            (u('\u00e9').encode('utf8'), '%C3%A9'),
            (u('\u00e9').encode('latin1'), '%E9'),

            # unicode strings become utf8
            (u('\u00e9'), '%C3%A9'),
        ]
        for unescaped, escaped in tests:
            self.assertEqual(url_escape(unescaped), escaped) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:13,代码来源:escape_test.py

示例13: test_url_escape_quote_plus

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import url_escape [as 别名]
def test_url_escape_quote_plus(self):
        unescaped = '+ #%'
        plus_escaped = '%2B+%23%25'
        escaped = '%2B%20%23%25'
        self.assertEqual(url_escape(unescaped), plus_escaped)
        self.assertEqual(url_escape(unescaped, plus=False), escaped)
        self.assertEqual(url_unescape(plus_escaped), unescaped)
        self.assertEqual(url_unescape(escaped, plus=False), unescaped)
        self.assertEqual(url_unescape(plus_escaped, encoding=None),
                         utf8(unescaped))
        self.assertEqual(url_unescape(escaped, encoding=None, plus=False),
                         utf8(unescaped)) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:14,代码来源:escape_test.py

示例14: _star

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import url_escape [as 别名]
def _star(self, notebook_name, note_name, star, redir=True):
        starred = self.get_starred()
        full_name = u'%s/%s' % (notebook_name, note_name)
        if star == 'set' and full_name not in starred:
            starred.append(full_name)
        elif star == 'unset' and full_name in starred:
            starred.remove(full_name)
        self.set_cookie('starred_notes',
                        b64encode(','.join(starred).encode('utf8')),
                        expires_days=365)
        if redir:
            self.redirect('/%s/%s' % (url_escape(notebook_name).replace('#', '%23'), url_escape(note_name).replace('#', '%23'))) 
开发者ID:charlesthomas,项目名称:magpie,代码行数:14,代码来源:note.py

示例15: generate

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import url_escape [as 别名]
def generate(self, **kwargs: Any) -> bytes:
        """Generate this template with the given arguments."""
        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 = typing.cast(Callable[[], bytes], 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:opendevops-cn,项目名称:opendevops,代码行数:28,代码来源:template.py


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