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


Python query_string.QueryString类代码示例

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


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


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