本文整理汇总了Python中webob.multidict.MultiDict方法的典型用法代码示例。如果您正苦于以下问题:Python multidict.MultiDict方法的具体用法?Python multidict.MultiDict怎么用?Python multidict.MultiDict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webob.multidict
的用法示例。
在下文中一共展示了multidict.MultiDict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_post
# 需要导入模块: from webob import multidict [as 别名]
# 或者: from webob.multidict import MultiDict [as 别名]
def test_post(self):
request = webapp2.Request.blank(
'/blobstore',
method='POST',
POST=multidict.MultiDict([('blob_key', 'a'),
('blob_key', 'b')]))
response = webapp2.Response()
handler = blobstore_viewer.BlobstoreRequestHandler(request, response)
self.mox.StubOutWithMock(blobstore, 'delete')
blobstore.delete(['a', 'b'])
self.mox.ReplayAll()
handler.post()
self.mox.VerifyAll()
self.assertEqual(302, response.status_int)
self.assertEqual('http://localhost/blobstore',
response.headers.get('Location'))
示例2: transform
# 需要导入模块: from webob import multidict [as 别名]
# 或者: from webob.multidict import MultiDict [as 别名]
def transform(self, fn, decode=False):
"""Accepts a function, getting a key, val and returning
a new pair of key, val and applies the function to all
header, value pairs in the message.
"""
changed = [False]
def tracking_fn(key, val):
new_key, new_val = fn(key, val)
if new_val != val or new_key != key:
changed[0] = True
return new_key, new_val
v = MultiDict(tracking_fn(key, val) for key, val in self.iteritems(raw=not decode))
if changed[0]:
self._v = v
self.changed = True
示例3: test_multiple__convert_to_dict_list__order_also_same
# 需要导入模块: from webob import multidict [as 别名]
# 或者: from webob.multidict import MultiDict [as 别名]
def test_multiple__convert_to_dict_list__order_also_same():
from webob.multidict import MultiDict
mdict = MultiDict(
[
("name", "foo"),
("country", "jp"),
("name", "bar"),
("country", "us"),
("name", "boo"),
("country", "ch"),
]
)
result = _callFUT(mdict)
assert result == [
{"name": "foo", "country": "jp"},
{"name": "bar", "country": "us"},
{"name": "boo", "country": "ch"},
]
示例4: test_multiple2__convert_to_dict_list__order_also_same
# 需要导入模块: from webob import multidict [as 别名]
# 或者: from webob.multidict import MultiDict [as 别名]
def test_multiple2__convert_to_dict_list__order_also_same():
from webob.multidict import MultiDict
mdict = MultiDict(
[
("name", "foo"),
("name", "bar"),
("name", "boo"),
("country", "jp"),
("country", "us"),
("country", "ch"),
]
)
result = _callFUT(mdict)
assert result == [
{"name": "foo", "country": "jp"},
{"name": "bar", "country": "us"},
{"name": "boo", "country": "ch"},
]
示例5: test_post
# 需要导入模块: from webob import multidict [as 别名]
# 或者: from webob.multidict import MultiDict [as 别名]
def test_post(self):
request = webapp2.Request.blank(
'/blobstore',
method='POST',
POST=multidict.MultiDict([('blob_key', 'a'),
('blob_key', 'b')]))
response = webapp2.Response()
handler = blobstore_viewer.BlobstoreRequestHandler(request, response)
admin_request_handler.AdminRequestHandler(handler).post()
self.mox.StubOutWithMock(blobstore, 'delete')
blobstore.delete(['a', 'b'])
self.mox.ReplayAll()
handler.post()
self.mox.VerifyAll()
self.assertEqual(302, response.status_int)
self.assertEqual('http://localhost/blobstore',
response.headers.get('Location'))
示例6: test_03_search_url_multiple_words
# 需要导入模块: from webob import multidict [as 别名]
# 或者: from webob.multidict import MultiDict [as 别名]
def test_03_search_url_multiple_words(self):
fields = UnicodeMultiDict(MultiDict(url='e'))
fields.add('url', 'f')
urls = self.res_search(fields=fields)
assert set([self.ef]) == urls, urls
示例7: __init__
# 需要导入模块: from webob import multidict [as 别名]
# 或者: from webob.multidict import MultiDict [as 别名]
def __init__(self, items=()):
self._v = MultiDict([(normalize(key), remove_newlines(val))
for (key, val) in items])
self.changed = False
self.num_prepends = 0
示例8: transform
# 需要导入模块: from webob import multidict [as 别名]
# 或者: from webob.multidict import MultiDict [as 别名]
def transform(self, func):
changed = [False]
def wrapped_func(key, value):
new_key, new_value = func(key, value)
if new_value != value or new_key != key:
changed[0] = True
return new_key, new_value
transformed_headers = [wrapped_func(k, v) for k, v in self._m.items()]
if changed[0]:
self._m._headers = transformed_headers
self._v = MultiDict([(normalize(k), remove_newlines(v))
for k, v in transformed_headers])
self.changed = True
示例9: __make_request_params
# 需要导入模块: from webob import multidict [as 别名]
# 或者: from webob.multidict import MultiDict [as 别名]
def __make_request_params(kwargs):
params = MultiDict()
for key, val in kwargs.iteritems():
assert isinstance(key, basestring)
if isinstance(val, basestring):
params[key] = val
else:
assert isinstance(val, (list, tuple))
for v in val:
assert isinstance(v, basestring)
params.add(key, v)
return params
示例10: _sanitizer
# 需要导入模块: from webob import multidict [as 别名]
# 或者: from webob.multidict import MultiDict [as 别名]
def _sanitizer(self, obj):
"""Sanitizer method that will be passed to jsonutils.dumps."""
if hasattr(obj, "to_dict"):
return obj.to_dict()
if isinstance(obj, multidict.MultiDict):
return obj.mixed()
return jsonutils.to_primitive(obj)
示例11: __init__
# 需要导入模块: from webob import multidict [as 别名]
# 或者: from webob.multidict import MultiDict [as 别名]
def __init__(self, **kw):
super(EnhancedDummyRequest, self).__init__(**kw)
self.GET = MultiDict(self.GET)
# Make sure content_type attr exists is not passed in via **kw
self.content_type = getattr(self, 'content_type', None)
示例12: test_view
# 需要导入模块: from webob import multidict [as 别名]
# 或者: from webob.multidict import MultiDict [as 别名]
def test_view(self, by_resource_id):
from pyramid.httpexceptions import HTTPFound
AccomodationsView._get_title = lambda x, y=None: 'test'
view = AccomodationsView(
DummyResource(), DummyRequest(params=MultiDict({'rid': 1}))
)
self.assertIsInstance(view.view(), HTTPFound)
AccomodationsView.edit = lambda x=None: {}
view = AccomodationsView(DummyResource(), DummyRequest())
self.assertSetEqual({'title', 'readonly'}, set(view.view().keys()))
示例13: test_form_invalid
# 需要导入模块: from webob import multidict [as 别名]
# 或者: from webob.multidict import MultiDict [as 别名]
def test_form_invalid(self):
request = DummyRequest(
params=MultiDict({'address': 'a'})
)
form = AddressForm(request)
self.assertFalse(form.validate())
self.assertIn('location_id', form._errors)
self.assertIn('zip_code', form._errors)
self.assertIn('address', form._errors)
示例14: test_form_valid
# 需要导入模块: from webob import multidict [as 别名]
# 或者: from webob.multidict import MultiDict [as 别名]
def test_form_valid(self):
request = DummyRequest()
csrf_token = request.session.get_csrf_token()
request.params = (
MultiDict({
'csrf_token': csrf_token,
'location_id': 10,
'zip_code': '02121',
'address': 'test'
})
)
form = AddressForm(request)
form.validate()
self.assertTrue(form.validate())
示例15: test_form_invalid
# 需要导入模块: from webob import multidict [as 别名]
# 或者: from webob.multidict import MultiDict [as 别名]
def test_form_invalid(self):
request = DummyRequest(params=MultiDict())
form = AdvsourceForm(request)
self.assertFalse(form.validate())
self.assertIn('name', form._errors)