本文整理汇总了Python中werkzeug.datastructures.MultiDict方法的典型用法代码示例。如果您正苦于以下问题:Python datastructures.MultiDict方法的具体用法?Python datastructures.MultiDict怎么用?Python datastructures.MultiDict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.datastructures
的用法示例。
在下文中一共展示了datastructures.MultiDict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import MultiDict [as 别名]
def __init__(self, stream_factory=None, charset='utf-8', errors='replace',
max_form_memory_size=None, cls=None, buffer_size=64 * 1024):
self.stream_factory = stream_factory
self.charset = charset
self.errors = errors
self.max_form_memory_size = max_form_memory_size
if stream_factory is None:
stream_factory = default_stream_factory
if cls is None:
cls = MultiDict
self.cls = cls
# make sure the buffer size is divisible by four so that we can base64
# decode chunk by chunk
assert buffer_size % 4 == 0, 'buffer size has to be divisible by 4'
# also the buffer size has to be at least 1024 bytes long or long headers
# will freak out the system
assert buffer_size >= 1024, 'buffer size has to be at least 1KB'
self.buffer_size = buffer_size
示例2: source
# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import MultiDict [as 别名]
def source(self, request):
"""
Pulls values off the request in the provided location
:param request: The flask request object to parse arguments from
"""
if isinstance(self.location, six.string_types):
value = getattr(request, self.location, MultiDict())
if callable(value):
value = value()
if value is not None:
return value
else:
values = MultiDict()
for l in self.location:
value = getattr(request, l, None)
if callable(value):
value = value()
if value is not None:
values.update(value)
return values
return MultiDict()
示例3: __init__
# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import MultiDict [as 别名]
def __init__(self, stream_factory=None, charset='utf-8', errors='replace',
max_form_memory_size=None, cls=None, buffer_size=64 * 1024):
self.charset = charset
self.errors = errors
self.max_form_memory_size = max_form_memory_size
self.stream_factory = default_stream_factory if stream_factory is None else stream_factory
self.cls = MultiDict if cls is None else cls
# make sure the buffer size is divisible by four so that we can base64
# decode chunk by chunk
assert buffer_size % 4 == 0, 'buffer size has to be divisible by 4'
# also the buffer size has to be at least 1024 bytes long or long headers
# will freak out the system
assert buffer_size >= 1024, 'buffer size has to be at least 1KB'
self.buffer_size = buffer_size
示例4: send_login
# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import MultiDict [as 别名]
def send_login():
"""View function that sends login instructions for passwordless login"""
form_class = _security.passwordless_login_form
if request.is_json:
form = form_class(MultiDict(request.get_json()), meta=suppress_form_csrf())
else:
form = form_class(meta=suppress_form_csrf())
if form.validate_on_submit():
send_login_instructions(form.user)
if not _security._want_json(request):
do_flash(*get_message("LOGIN_EMAIL_SENT", email=form.user.email))
if _security._want_json(request):
return base_render_json(form)
return _security.render_template(
config_value("SEND_LOGIN_TEMPLATE"), send_login_form=form, **_ctx("send_login")
)
示例5: send_confirmation
# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import MultiDict [as 别名]
def send_confirmation():
"""View function which sends confirmation instructions."""
form_class = _security.send_confirmation_form
if request.is_json:
form = form_class(MultiDict(request.get_json()), meta=suppress_form_csrf())
else:
form = form_class(meta=suppress_form_csrf())
if form.validate_on_submit():
send_confirmation_instructions(form.user)
if not _security._want_json(request):
do_flash(*get_message("CONFIRMATION_REQUEST", email=form.user.email))
if _security._want_json(request):
return base_render_json(form)
return _security.render_template(
config_value("SEND_CONFIRMATION_TEMPLATE"),
send_confirmation_form=form,
**_ctx("send_confirmation")
)
示例6: forgot_password
# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import MultiDict [as 别名]
def forgot_password():
"""View function that handles a forgotten password request."""
form_class = _security.forgot_password_form
if request.is_json:
form = form_class(MultiDict(request.get_json()), meta=suppress_form_csrf())
else:
form = form_class(meta=suppress_form_csrf())
if form.validate_on_submit():
send_reset_password_instructions(form.user)
if not _security._want_json(request):
do_flash(*get_message("PASSWORD_RESET_REQUEST", email=form.user.email))
if _security._want_json(request):
return base_render_json(form, include_user=False)
return _security.render_template(
config_value("FORGOT_PASSWORD_TEMPLATE"),
forgot_password_form=form,
**_ctx("forgot_password")
)
示例7: test_with_valid_dates
# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import MultiDict [as 别名]
def test_with_valid_dates(self):
Fake, FakeForm = self.factory()
start = date.today() - timedelta(days=1)
end = date.today()
expected = ' - '.join([to_iso_date(start), to_iso_date(end)])
fake = Fake()
form = FakeForm(MultiDict({
'daterange': expected
}))
form.validate()
self.assertEqual(form.errors, {})
form.populate_obj(fake)
self.assertEqual(fake.daterange, db.DateRange(start=start, end=end))
示例8: test_with_valid_organization
# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import MultiDict [as 别名]
def test_with_valid_organization(self):
Ownable, OwnableForm = self.factory()
user = UserFactory()
member = Member(user=user, role='editor')
org = OrganizationFactory(members=[member])
login_user(user)
form = OwnableForm(MultiDict({
'organization': str(org.id)
}))
self.assertEqual(form.owner.data, user)
self.assertEqual(form.organization.data, org)
form.validate()
self.assertEqual(form.errors, {})
self.assertIsNone(form.owner.data)
self.assertEqual(form.organization.data, org)
ownable = Ownable()
form.populate_obj(ownable)
self.assertIsNone(ownable.owner)
self.assertEqual(ownable.organization, org)
示例9: test_with_initial_and_both_member
# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import MultiDict [as 别名]
def test_with_initial_and_both_member(self):
Ownable, OwnableForm = self.factory()
user = UserFactory()
org = OrganizationFactory(members=[Member(user=user, role='editor')])
neworg = OrganizationFactory(
members=[Member(user=user, role='editor')])
ownable = Ownable(organization=org)
form = OwnableForm(MultiDict({
'organization': str(neworg.id)
}), obj=ownable)
self.assertEqual(form.organization.data, neworg)
login_user(user)
form.validate()
self.assertEqual(form.errors, {})
form.populate_obj(ownable)
self.assertIsNone(ownable.owner)
self.assertEqual(ownable.organization, neworg)
示例10: test_with_initial_and_not_member
# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import MultiDict [as 别名]
def test_with_initial_and_not_member(self):
Ownable, OwnableForm = self.factory()
user = UserFactory()
org = OrganizationFactory(members=[Member(user=user, role='editor')])
neworg = OrganizationFactory()
ownable = Ownable(organization=org)
form = OwnableForm(MultiDict({
'organization': str(neworg.id)
}), obj=ownable)
self.assertEqual(form.organization.data, neworg)
login_user(user)
form.validate()
self.assertIn('organization', form.errors)
self.assertEqual(len(form.errors['organization']), 1)
示例11: test_not_member
# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import MultiDict [as 别名]
def test_not_member(self):
Ownable, OwnableForm = self.factory()
member = Member(user=UserFactory(), role='editor')
org = OrganizationFactory(members=[member])
login_user(UserFactory())
form = OwnableForm(MultiDict({
'organization': str(org.id)
}))
self.assertEqual(form.organization.data, org)
self.assertFalse(form.validate())
self.assertIn('organization', form.errors)
self.assertEqual(len(form.errors['organization']), 1)
示例12: test_admin_can_set_owner
# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import MultiDict [as 别名]
def test_admin_can_set_owner(self):
Ownable, OwnableForm = self.factory()
user = UserFactory()
org = OrganizationFactory()
ownable = Ownable(organization=org)
login_user(AdminFactory())
form = OwnableForm(MultiDict({
'owner': str(user.id)
}), obj=ownable)
self.assertEqual(form.owner.data, user)
self.assertEqual(form.organization.data, org)
self.assertTrue(form.validate())
self.assertEqual(form.errors, {})
self.assertEqual(form.owner.data, user)
self.assertIsNone(form.organization.data)
form.populate_obj(ownable)
self.assertEqual(ownable.owner, user)
self.assertIsNone(ownable.organization)
示例13: test_admin_can_set_organization
# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import MultiDict [as 别名]
def test_admin_can_set_organization(self):
Ownable, OwnableForm = self.factory()
user = UserFactory()
org = OrganizationFactory()
ownable = Ownable(owner=user)
login_user(AdminFactory())
form = OwnableForm(MultiDict({
'organization': str(org.id)
}), obj=ownable)
self.assertEqual(form.owner.data, user)
self.assertEqual(form.organization.data, org)
self.assertTrue(form.validate())
self.assertEqual(form.errors, {})
self.assertIsNone(form.owner.data)
self.assertEqual(form.organization.data, org)
form.populate_obj(ownable)
self.assertIsNone(ownable.owner)
self.assertEqual(ownable.organization, org)
示例14: test_with_initial_org_and_no_data_provided
# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import MultiDict [as 别名]
def test_with_initial_org_and_no_data_provided(self):
Ownable, OwnableForm = self.factory()
user = UserFactory()
org = OrganizationFactory(members=[Member(user=user, role='editor')])
ownable = Ownable(organization=org)
form = OwnableForm(MultiDict({}), obj=ownable)
self.assertEqual(form.organization.data, org)
login_user(user)
form.validate()
self.assertEqual(form.errors, {})
form.populate_obj(ownable)
self.assertIsNone(ownable.owner)
self.assertEqual(ownable.organization, org)
示例15: test_with_initial_owner_and_no_data_provided
# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import MultiDict [as 别名]
def test_with_initial_owner_and_no_data_provided(self):
Ownable, OwnableForm = self.factory()
user = UserFactory()
ownable = Ownable(owner=user)
form = OwnableForm(MultiDict({}), obj=ownable)
self.assertEqual(form.owner.data, user)
login_user(user)
form.validate()
self.assertEqual(form.errors, {})
form.populate_obj(ownable)
self.assertEqual(ownable.owner, user)
self.assertIsNone(ownable.organization)