本文整理汇总了Python中werkzeug.datastructures.CombinedMultiDict方法的典型用法代码示例。如果您正苦于以下问题:Python datastructures.CombinedMultiDict方法的具体用法?Python datastructures.CombinedMultiDict怎么用?Python datastructures.CombinedMultiDict使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.datastructures
的用法示例。
在下文中一共展示了datastructures.CombinedMultiDict方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: values
# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import CombinedMultiDict [as 别名]
def values(self) -> CombinedMultiDict:
form = await self.form
return CombinedMultiDict([self.args, form])
示例2: post
# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import CombinedMultiDict [as 别名]
def post():
form = PhotoForm(CombinedMultiDict((request.files, request.form)))
if request.method == 'POST' and form.validate():
with tempfile.NamedTemporaryFile() as temp:
form.input_photo.data.save(temp)
temp.flush()
result = detect_objects(temp.name)
photo_form = PhotoForm(request.form)
return render_template('upload.html',
photo_form=photo_form, result=result)
else:
return redirect(url_for('upload'))
示例3: wrap_formdata
# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import CombinedMultiDict [as 别名]
def wrap_formdata(self, form, formdata):
if formdata is _Auto:
if _is_submitted():
if request.files:
return CombinedMultiDict((
request.files, request.form
))
elif request.form:
return request.form
elif request.get_json():
return ImmutableMultiDict(request.get_json())
return None
return formdata
示例4: post
# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import CombinedMultiDict [as 别名]
def post():
form = PhotoForm(CombinedMultiDict((request.files, request.form)))
if request.method == 'POST' and form.validate():
filename = '%s.%s' % (str(uuid.uuid4()),
secure_filename(form.input_photo.data.filename))
content_type = content_types[filename.split('.')[-1]]
write_retry_params = gcs.RetryParams(backoff_factor=1.1)
gcs_file = gcs.open('/%s/%s' % (bucket_name, filename), 'w',
retry_params=write_retry_params,
content_type=content_type,
options={'x-goog-acl': 'authenticated-read'})
for _ in form.input_photo.data.stream:
gcs_file.write(_)
gcs_file.close()
labels = get_labels(filename)
tags = [translate_text(label.description) for label in labels]
entity = Photo(id=filename, tags=tags,
parent=ndb.Key('User', 'default'))
entity.put()
for tag in tags:
entity = ndb.Key('User', 'default', 'Tags', tag).get()
if entity:
entity.count += 1
else:
entity = Tags(count=1, id=tag,
parent=ndb.Key('User', 'default'))
entity.put()
return render_template('post.html', storage_path=storage_path,
filename=filename, tags=tags)
else:
return redirect(url_for('photos'))
示例5: upload
# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import CombinedMultiDict [as 别名]
def upload():
upload_form = forms.UploadForm(CombinedMultiDict((flask.request.files, flask.request.form)))
upload_form.category.choices = _create_upload_category_choices()
show_ratelimit = False
next_upload_time = None
ratelimit_count = 0
# Anonymous uploaders and non-trusted uploaders
no_or_new_account = (not flask.g.user
or (flask.g.user.age < app.config['RATELIMIT_ACCOUNT_AGE']
and not flask.g.user.is_trusted))
if app.config['RATELIMIT_UPLOADS'] and no_or_new_account:
now, ratelimit_count, next_upload_time = backend.check_uploader_ratelimit(flask.g.user)
show_ratelimit = ratelimit_count >= app.config['MAX_UPLOAD_BURST']
next_upload_time = next_upload_time if next_upload_time > now else None
if flask.request.method == 'POST' and upload_form.validate():
try:
torrent = backend.handle_torrent_upload(upload_form, flask.g.user)
return flask.redirect(flask.url_for('torrents.view', torrent_id=torrent.id))
except backend.TorrentExtraValidationException:
pass
# If we get here with a POST, it means the form data was invalid: return a non-okay status
status_code = 400 if flask.request.method == 'POST' else 200
return flask.render_template('upload.html',
upload_form=upload_form,
show_ratelimit=show_ratelimit,
ratelimit_count=ratelimit_count,
next_upload_time=next_upload_time), status_code
示例6: test_iterables
# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import CombinedMultiDict [as 别名]
def test_iterables(self):
a = datastructures.MultiDict((("key_a", "value_a"),))
b = datastructures.MultiDict((("key_b", "value_b"),))
ab = datastructures.CombinedMultiDict((a,b))
self.assert_equal(sorted(ab.lists()), [('key_a', ['value_a']), ('key_b', ['value_b'])])
self.assert_equal(sorted(ab.listvalues()), [['value_a'], ['value_b']])
self.assert_equal(sorted(ab.keys()), ["key_a", "key_b"])
self.assert_equal(sorted(iterlists(ab)), [('key_a', ['value_a']), ('key_b', ['value_b'])])
self.assert_equal(sorted(iterlistvalues(ab)), [['value_a'], ['value_b']])
self.assert_equal(sorted(iterkeys(ab)), ["key_a", "key_b"])