• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python query_string.QueryString类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中urlobject.query_string.QueryString的典型用法代码示例。如果您正苦于以下问题:Python QueryString类的具体用法?Python QueryString怎么用?Python QueryString使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: test_set_params_with_multiple_values_sets_the_same_name_multiple_times

 def test_set_params_with_multiple_values_sets_the_same_name_multiple_times(self):
     s = QueryString(u'foo=spam')
     assert (s.set_params({u'foo': [u'bar', u'baz']}) ==
             u'foo=bar&foo=baz')
     s2 = QueryString(u'foo=bar&foo=baz')
     assert (s2.set_params({u'foo': [u'spam', u'ham']}) ==
             u'foo=spam&foo=ham')
开发者ID:sebzur,项目名称:urlobject,代码行数:7,代码来源:querystring_test.py


示例2: handle_active_mquery

    def handle_active_mquery(self, value):



        active = None

        query_to_trigger = self.prepare_value(value)
        if isinstance(query_to_trigger, basestring):
            query_to_trigger = QueryString(query_to_trigger).dict
        current_query = self.url.query.dict

        for key, value in query_to_trigger.items():

            # exact match of query -> unset it
            if key in current_query and query_to_trigger[key] == current_query[key]:
                active = True

            # check if current query has multiple items
            try:
                ext = current_query[key]
                ext = ext.split(',')
            except Exception as e:
                ext = None

            if ext and len(ext) > 1:

                if key in current_query and value in ext:
                    active = True

        self.url = active
开发者ID:hzlf,项目名称:openbroadcast.org,代码行数:30,代码来源:spurl.py


示例3: test_add_params_accepts_the_same_args_as_dict

 def test_add_params_accepts_the_same_args_as_dict(self):
     s = QueryString("")
     added = s.add_params({"abc": "123"}, foo="bar", xyz="456")
     assert added.dict == {"abc": "123", "foo": "bar", "xyz": "456"}
     added2 = s.add_params([("abc", "123")], foo="bar", xyz="456")
     assert added2.dict == {"abc": "123", "foo": "bar", "xyz": "456"}
     # It also has to fail in the same way as `dict`. If you pass more than
     # one positional argument it should raise a TypeError.
     self.assertRaises(TypeError, s.add_params, {"abc": "123"}, {"foo": "bar"})
开发者ID:discogs,项目名称:urlobject,代码行数:9,代码来源:querystring_test.py


示例4: test_add_params_accepts_the_same_args_as_dict

 def test_add_params_accepts_the_same_args_as_dict(self):
     s = QueryString(u'')
     added = s.add_params({u'abc': u'123'}, foo=u'bar', xyz='456')
     assert added.dict == {u'abc': u'123', u'foo': u'bar', u'xyz': u'456'}
     added2 = s.add_params([(u'abc', u'123')], foo=u'bar', xyz='456')
     assert added2.dict == {u'abc': u'123', u'foo': u'bar', u'xyz': u'456'}
     # It also has to fail in the same way as `dict`. If you pass more than
     # one positional argument it should raise a TypeError.
     self.assertRaises(TypeError,
                       s.add_params, {'abc': '123'}, {'foo': 'bar'})
开发者ID:sebzur,项目名称:urlobject,代码行数:10,代码来源:querystring_test.py


示例5: handle_active_query

    def handle_active_query(self, value):
        query_to_toggle = self.prepare_value(value)
        if isinstance(query_to_toggle, basestring):
            query_to_toggle = QueryString(query_to_toggle).dict
        current_query = self.url.query.dict
        for key, value in query_to_toggle.items():

            if key in current_query and value in current_query[key]:
                self.url = True
            else:
                self.url = False
开发者ID:hzlf,项目名称:openbroadcast.org,代码行数:11,代码来源:spurl.py


示例6: handle_toggle_query

 def handle_toggle_query(self, value):
     query_to_toggle = self.prepare_value(value)
     if isinstance(query_to_toggle, six.string_types):
         query_to_toggle = QueryString(query_to_toggle).dict
     current_query = self.url.query.dict
     for key, value in list(query_to_toggle.items()):
         if isinstance(value, six.string_types):
             value = value.split(',')
         first, second = value
         if key in current_query and first in current_query[key]:
             self.url = self.url.set_query_param(key, second)
         else:
             self.url = self.url.set_query_param(key, first)
开发者ID:albertkoch,项目名称:django-spurl,代码行数:13,代码来源:spurl.py


示例7: handle_trigger_query

    def handle_trigger_query(self, value):
        query_to_trigger = self.prepare_value(value)
        if isinstance(query_to_trigger, basestring):
            query_to_trigger = QueryString(query_to_trigger).dict
        current_query = self.url.query.dict
        for key, value in query_to_trigger.items():

            if isinstance(value, basestring):
                value = value

            if key in current_query and value in current_query[key]:
                # unset
                self.url = self.url.del_query_param(key)
            else:
                # set
                self.url = self.url.set_query_param(key, value)
开发者ID:hzlf,项目名称:openbroadcast.org,代码行数:16,代码来源:spurl.py


示例8: test_add_params_with_multiple_values_adds_the_same_parameter_multiple_times

 def test_add_params_with_multiple_values_adds_the_same_parameter_multiple_times(self):
     s = QueryString(u'')
     assert (s.add_params({u'foo': [u'bar', u'baz']}) ==
             s.add_param(u'foo', u'bar').add_param(u'foo', u'baz'))
开发者ID:sebzur,项目名称:urlobject,代码行数:4,代码来源:querystring_test.py


示例9: test_add_param_accepts_int

 def test_add_param_accepts_int(self):
     s = QueryString("")
     assert s.add_param("abc", 123) == "abc=123"
开发者ID:discogs,项目名称:urlobject,代码行数:3,代码来源:querystring_test.py


示例10: test_add_param_encodes_utf8

 def test_add_param_encodes_utf8(self):
     s = QueryString(u'abc=123')
     assert s.add_param(u'foo', u'\ufffd') == u'abc=123&foo=%EF%BF%BD'
开发者ID:sebzur,项目名称:urlobject,代码行数:3,代码来源:querystring_test.py


示例11: test_add_param_encodes_special_characters

 def test_add_param_encodes_special_characters(self):
     s = QueryString(u'abc=123')
     assert s.add_param(u'd e f', u'4+5#6') == u'abc=123&d%20e%20f=4%2B5%236'
开发者ID:sebzur,项目名称:urlobject,代码行数:3,代码来源:querystring_test.py


示例12: test_add_param_encodes_and_adds_the_given_parameter_to_the_QueryString

 def test_add_param_encodes_and_adds_the_given_parameter_to_the_QueryString(self):
     s = QueryString(u'')
     assert s.add_param(u'abc', u'123') == u'abc=123'
     assert (s.add_param(u'abc', u'123')
              .add_param(u'def', u'456') == u'abc=123&def=456')
开发者ID:sebzur,项目名称:urlobject,代码行数:5,代码来源:querystring_test.py


示例13: test_add_param_can_add_empty_valued_parameters

 def test_add_param_can_add_empty_valued_parameters(self):
     s = QueryString(u'abc=123')
     assert s.add_param(u'def', u'') == u'abc=123&def='
开发者ID:sebzur,项目名称:urlobject,代码行数:3,代码来源:querystring_test.py


示例14: test_add_param_allows_the_same_parameter_name_to_be_added_twice

 def test_add_param_allows_the_same_parameter_name_to_be_added_twice(self):
     s = QueryString("abc=123")
     assert s.add_param("abc", "456") == "abc=123&abc=456"
开发者ID:discogs,项目名称:urlobject,代码行数:3,代码来源:querystring_test.py


示例15: test_set_params_is_equivalent_to_calling_set_param_multiple_times

 def test_set_params_is_equivalent_to_calling_set_param_multiple_times(self):
     s = QueryString(u'')
     assert (s.set_params([(u'abc', u'123'), (u'def', u'456')]) ==
             s.set_param(u'abc', u'123').set_param(u'def', u'456'))
开发者ID:sebzur,项目名称:urlobject,代码行数:4,代码来源:querystring_test.py


示例16: test_del_param_removes_all_instances_of_the_parameter_from_the_QueryString

 def test_del_param_removes_all_instances_of_the_parameter_from_the_QueryString(self):
     s = QueryString("abc=123&def=456&abc=789")
     assert s.del_param("abc") == "def=456"
     assert s.del_param("def") == "abc=123&abc=789"
开发者ID:discogs,项目名称:urlobject,代码行数:4,代码来源:querystring_test.py


示例17: test_set_param_replaces_existing_parameter_names

 def test_set_param_replaces_existing_parameter_names(self):
     s = QueryString("abc=123&abc=456")
     assert s.set_param("abc", "789") == "abc=789"
开发者ID:discogs,项目名称:urlobject,代码行数:3,代码来源:querystring_test.py


示例18: test_add_param_encodes_special_characters

 def test_add_param_encodes_special_characters(self):
     s = QueryString("abc=123")
     assert s.add_param("d e f", "4+5#6") == "abc=123&d+e+f=4%2B5%236"
开发者ID:discogs,项目名称:urlobject,代码行数:3,代码来源:querystring_test.py


示例19: test_set_params_accepts_the_same_args_as_dict

 def test_set_params_accepts_the_same_args_as_dict(self):
     s = QueryString(u'')
     added = s.set_params({u'abc': u'123'}, abc='456')
     assert added.dict == {u'abc': u'456'}
     added2 = s.set_params([(u'abc', u'123')], abc=u'456')
     assert added2.dict == {u'abc': u'456'}
开发者ID:sebzur,项目名称:urlobject,代码行数:6,代码来源:querystring_test.py


示例20: test_del_params_accepts_an_iterable_and_removes_all_listed_parameters

 def test_del_params_accepts_an_iterable_and_removes_all_listed_parameters(self):
     s = QueryString(u'abc=123&def=456&xyz=789')
     assert s.del_params((u'abc', u'xyz')) == u'def=456'
开发者ID:sebzur,项目名称:urlobject,代码行数:3,代码来源:querystring_test.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python views.route函数代码示例发布时间:2022-05-27
下一篇:
Python urlobject.URLObject类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap