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


Python URLObject.without_query方法代码示例

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


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

示例1: urls_are_equal

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import without_query [as 别名]
def urls_are_equal(url1, url2):
    """
    Compare to URLs for equality, ignoring the ordering of non-ordered elements.
    """
    url1 = URLObject(url1)
    url2 = URLObject(url2)
    return (
        url1.without_query() == url2.without_query() and
        url1.query_multi_dict == url2.query_multi_dict
    )
开发者ID:edx,项目名称:pa11ycrawler,代码行数:12,代码来源:test_spider.py

示例2: test_login_url

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import without_query [as 别名]
def test_login_url():
    app, _ = make_app()
    with app.test_client() as client:
        resp = client.get(
            "/login/test-service",
            base_url="https://a.b.c",
            follow_redirects=False,
        )
        # check that we saved the state in the session
        assert flask.session["test-service_oauth_state"] == "random-string"
    # check that we redirected the client
    assert resp.status_code == 302
    location = URLObject(resp.headers["Location"])
    assert location.without_query() == "https://example.com/oauth/authorize"
    assert location.query_dict["client_id"] == "client_id"
    assert location.query_dict["redirect_uri"] == "https://a.b.c/login/test-service/authorized"
    assert location.query_dict["scope"] == "admin"
    assert location.query_dict["state"] == "random-string"
开发者ID:harisk74,项目名称:flask-dance,代码行数:20,代码来源:test_oauth2.py

示例3: URLObjectModificationTest

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import without_query [as 别名]

#.........这里部分代码省略.........
        assert (self.url.with_port(24) ==
                'https://github.com:24/zacharyvoase/urlobject?spam=eggs#foo')

    def test_with_port_replaces_port_number(self):
        url = URLObject('https://github.com:59/')
        assert url.with_port(67) == 'https://github.com:67/'

    def test_without_port_removes_port_number(self):
        url = URLObject('https://github.com:59/')
        assert url.without_port() == 'https://github.com/'

    def test_with_path_replaces_path(self):
        assert (self.url.with_path('/dvxhouse/intessa') ==
                'https://github.com/dvxhouse/intessa?spam=eggs#foo')

    def test_root_goes_to_root_path(self):
        assert self.url.root == 'https://github.com/?spam=eggs#foo'

    def test_parent_jumps_up_one_level(self):
        url = URLObject('https://github.com/zacharyvoase/urlobject')
        assert url.parent == 'https://github.com/zacharyvoase/'
        assert url.parent.parent == 'https://github.com/'

    def test_add_path_segment_adds_a_path_segment(self):
        url = URLObject('https://github.com/zacharyvoase/urlobject')
        assert (url.add_path_segment('tree') ==
                'https://github.com/zacharyvoase/urlobject/tree')
        assert (url.add_path_segment('tree/master') ==
                'https://github.com/zacharyvoase/urlobject/tree%2Fmaster')

    def test_add_path_adds_a_partial_path(self):
        url = URLObject('https://github.com/zacharyvoase/urlobject')
        assert (url.add_path('tree') ==
                'https://github.com/zacharyvoase/urlobject/tree')
        assert (url.add_path('tree/master') ==
                'https://github.com/zacharyvoase/urlobject/tree/master')

    def test_is_leaf(self):
        assert URLObject('https://github.com/zacharyvoase/urlobject').is_leaf
        assert not URLObject('https://github.com/zacharyvoase/').is_leaf

    def test_with_query_replaces_query(self):
        assert (self.url.with_query('spam-ham-eggs') ==
                'https://github.com/zacharyvoase/urlobject?spam-ham-eggs#foo')

    def test_without_query_removes_query(self):
        assert (self.url.without_query() ==
                'https://github.com/zacharyvoase/urlobject#foo')

    def test_add_query_param_adds_one_query_parameter(self):
        assert (self.url.add_query_param('spam', 'ham') ==
                'https://github.com/zacharyvoase/urlobject?spam=eggs&spam=ham#foo')

    def test_add_query_params_adds_multiple_query_parameters(self):
        assert (self.url.add_query_params([('spam', 'ham'), ('foo', 'bar')]) ==
                'https://github.com/zacharyvoase/urlobject?spam=eggs&spam=ham&foo=bar#foo')

    def test_add_query_params_with_multiple_values_adds_the_same_query_parameter_multiple_times(self):
        assert (self.url.add_query_params({'foo': ['bar', 'baz']}) ==
                'https://github.com/zacharyvoase/urlobject?spam=eggs&foo=bar&foo=baz#foo')

    def test_set_query_param_adds_or_replaces_one_query_parameter(self):
        assert (self.url.set_query_param('spam', 'ham') ==
                'https://github.com/zacharyvoase/urlobject?spam=ham#foo')

    def test_set_query_params_adds_or_replaces_multiple_query_parameters(self):
        assert (self.url.set_query_params({'foo': 'bar'}, spam='ham') ==
                'https://github.com/zacharyvoase/urlobject?foo=bar&spam=ham#foo')

    def test_set_query_params_with_multiple_values_adds_or_replaces_the_same_parameter_multiple_times(self):
        assert (self.url.set_query_params({'spam': ['bar', 'baz']}) ==
                'https://github.com/zacharyvoase/urlobject?spam=bar&spam=baz#foo')
        assert (self.url.set_query_params({'foo': ['bar', 'baz']}) ==
                'https://github.com/zacharyvoase/urlobject?spam=eggs&foo=bar&foo=baz#foo')
        # Ensure it removes all appearances of an existing name before adding
        # the new ones.
        url = URLObject('https://github.com/zacharyvoase/urlobject?foo=bar&foo=baz#foo')
        assert (url.set_query_params({'foo': ['spam', 'ham']}) ==
                'https://github.com/zacharyvoase/urlobject?foo=spam&foo=ham#foo')

    def test_del_query_param_removes_one_query_parameter(self):
        assert (self.url.del_query_param('spam') ==
                'https://github.com/zacharyvoase/urlobject#foo')

    def test_del_query_params_removes_multiple_query_parameters(self):
        url = URLObject('https://github.com/zacharyvoase/urlobject?foo=bar&baz=spam#foo')
        assert (url.del_query_params(['foo', 'baz']) ==
                'https://github.com/zacharyvoase/urlobject#foo')

    def test_with_fragment_replaces_fragment(self):
        assert (self.url.with_fragment('part') ==
                'https://github.com/zacharyvoase/urlobject?spam=eggs#part')

    def test_with_fragment_encodes_fragment_correctly(self):
        assert (self.url.with_fragment('foo bar#baz') ==
                'https://github.com/zacharyvoase/urlobject?spam=eggs#foo%20bar%23baz')

    def test_without_fragment_removes_fragment(self):
        assert (self.url.without_fragment() ==
                'https://github.com/zacharyvoase/urlobject?spam=eggs')
开发者ID:vmalloc,项目名称:urlobject,代码行数:104,代码来源:urlobject_test.py

示例4: unauthorized_handler

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import without_query [as 别名]
def unauthorized_handler():
    user_unauthorized.send(user_unauthorized.send(current_app._get_current_object()))
    url = URLObject(login_url(login_manager.login_view, request.url))
    prev_param = make_next_param(url.without_query(), request.referrer or "/")
    return redirect(url.add_query_param("prev", prev_param).add_query_param("mode", "action"))
开发者ID:paulvisen,项目名称:flask-todo,代码行数:7,代码来源:auth.py


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