本文整理汇总了Python中werkzeug.datastructures.CombinedMultiDict类的典型用法代码示例。如果您正苦于以下问题:Python CombinedMultiDict类的具体用法?Python CombinedMultiDict怎么用?Python CombinedMultiDict使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CombinedMultiDict类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_start_page
def test_start_page(self):
request_values = CombinedMultiDict([ImmutableMultiDict([('page', '2')]), ImmutableMultiDict([])])
expected = deepcopy(QueryBuilderSimple.DEFAULT_COMPONENTS)
expected['start'] = str((int(request_values.get('page')) - 1) * int(config.SEARCH_DEFAULT_ROWS))
actual = QueryBuilderSimple.build(request_values)
self.assertEqual(actual, expected)
示例2: get_environ
def get_environ(self):
"""返回内置环境。"""
input_stream = self.input_stream
content_length = self.content_length
content_type = self.content_type
if input_stream is not None:
start_pos = input_stream.tell()
input_stream.seek(0, 2)
end_pos = input_stream.tell()
input_stream.seek(start_pos)
content_length = end_pos - start_pos
elif content_type == "multipart/form-data":
values = CombinedMultiDict([self.form, self.files])
input_stream, content_length, boundary = stream_encode_multipart(values, charset=self.charset)
content_type += '; boundary="%s"' % boundary
elif content_type == "application/x-www-form-urlencoded":
# py2v3 review
values = url_encode(self.form, charset=self.charset)
values = values.encode("ascii")
content_length = len(values)
input_stream = BytesIO(values)
else:
input_stream = _empty_stream
result = {}
if self.environ_base:
result.update(self.environ_base)
def _path_encode(x):
return wsgi_encoding_dance(url_unquote(x, self.charset), self.charset)
qs = wsgi_encoding_dance(self.query_string)
result.update(
{
"REQUEST_METHOD": self.method,
"SCRIPT_NAME": _path_encode(self.script_root),
"PATH_INFO": _path_encode(self.path),
"QUERY_STRING": qs,
"SERVER_NAME": self.server_name,
"SERVER_PORT": str(self.server_port),
"HTTP_HOST": self.host,
"SERVER_PROTOCOL": self.server_protocol,
"CONTENT_TYPE": content_type or "",
"CONTENT_LENGTH": str(content_length or "0"),
"wsgi.version": self.wsgi_version,
"wsgi.url_scheme": self.url_scheme,
"wsgi.input": input_stream,
"wsgi.errors": self.errors_stream,
"wsgi.multithread": self.multithread,
"wsgi.multiprocess": self.multiprocess,
"wsgi.run_once": self.run_once,
}
)
for key, value in self.headers.to_wsgi_list():
result["HTTP_%s" % key.upper().replace("-", "_")] = value
if self.environ_overrides:
result.update(self.environ_overrides)
return result
示例3: reload
def reload(self):
"""Reload user login information and saves them."""
data = self._login(self.uid, force=True)
acc = self._precache(data, force=True)
self.info.update(data)
CombinedMultiDict.__init__(self, [self.req, self.info, acc, dict(CFG_USER_DEFAULT_INFO)])
self.save()
示例4: get_environ
def get_environ(self):
"""Return the built environ."""
input_stream = self.input_stream
content_length = self.content_length
content_type = self.content_type
if input_stream is not None:
start_pos = input_stream.tell()
input_stream.seek(0, 2)
end_pos = input_stream.tell()
input_stream.seek(start_pos)
content_length = end_pos - start_pos
elif content_type == 'multipart/form-data':
values = CombinedMultiDict([self.form, self.files])
input_stream, content_length, boundary = \
stream_encode_multipart(values, charset=self.charset)
content_type += '; boundary="%s"' % boundary
elif content_type == 'application/x-www-form-urlencoded':
#py2v3 review
values = url_encode(self.form, charset=self.charset)
values = values.encode('ascii')
content_length = len(values)
input_stream = BytesIO(values)
else:
input_stream = _empty_stream
result = {}
if self.environ_base:
result.update(self.environ_base)
def _path_encode(x):
return wsgi_encoding_dance(url_unquote(x, self.charset), self.charset)
qs = wsgi_encoding_dance(self.query_string)
result.update({
'REQUEST_METHOD': self.method,
'SCRIPT_NAME': _path_encode(self.script_root),
'PATH_INFO': _path_encode(self.path),
'QUERY_STRING': qs,
'SERVER_NAME': self.server_name,
'SERVER_PORT': str(self.server_port),
'HTTP_HOST': self.host,
'SERVER_PROTOCOL': self.server_protocol,
'CONTENT_TYPE': content_type or '',
'CONTENT_LENGTH': str(content_length or '0'),
'wsgi.version': self.wsgi_version,
'wsgi.url_scheme': self.url_scheme,
'wsgi.input': input_stream,
'wsgi.errors': self.errors_stream,
'wsgi.multithread': self.multithread,
'wsgi.multiprocess': self.multiprocess,
'wsgi.run_once': self.run_once
})
for key, value in self.headers.to_wsgi_list():
result['HTTP_%s' % key.upper().replace('-', '_')] = value
if self.environ_overrides:
result.update(self.environ_overrides)
return result
示例5: __init__
def __init__(self, uid=None, force=False):
"""Retrieve information about user."""
def on_update(self):
"""Change own status when the user info is modified."""
self.modified = True
self.modified = False
self.uid = uid
self.req = self._get_request_info()
acc = {}
if uid is not None and uid > 0:
data = self._login(uid, force)
acc = self._precache(data, force)
else:
data = self._create_guest()
self.info = CallbackDict(data, on_update)
# FIXME remove req after everybody start using flask request.
CombinedMultiDict.__init__(self, [self.req, self.info, acc,
dict(CFG_USER_DEFAULT_INFO)])
self.save()
示例6: test_combined_multidict
def test_combined_multidict():
"""Combined multidict behavior"""
d1 = MultiDict([('foo', '1')])
d2 = MultiDict([('bar', '2'), ('bar', '3')])
d = CombinedMultiDict([d1, d2])
# lookup
assert d['foo'] == '1'
assert d['bar'] == '2'
assert d.getlist('bar') == ['2', '3']
assert sorted(d.items()) == [('bar', '2'), ('foo', '1')], d.items()
assert sorted(d.items(multi=True)) == [('bar', '2'), ('bar', '3'), ('foo', '1')]
assert 'missingkey' not in d
assert 'foo' in d
# type lookup
assert d.get('foo', type=int) == 1
assert d.getlist('bar', type=int) == [2, 3]
# get key errors for missing stuff
assert_raises(KeyError, lambda: d["missing"])
# make sure that they are immutable
def test_assign():
d['foo'] = 'blub'
assert_raises(TypeError, test_assign)
# copies are immutable
d = d.copy()
assert_raises(TypeError, test_assign)
# make sure lists merges
md1 = MultiDict((("foo", "bar"),))
md2 = MultiDict((("foo", "blafasel"),))
x = CombinedMultiDict((md1, md2))
assert x.lists() == [('foo', ['bar', 'blafasel'])]
示例7: isinstance
if not isinstance(field, Field):
raise TypeError, 'field must be instance of class Field'
if field.name in self.field_by_name:
raise ValueError, 'a field named \'%s\' already exists' % field.name
self.field_names.append(field.name)
self.field_by_name[field.name] = field
def get_data(self, with_view_args=True, is_json=True, copy=False):
if is_json:
try:
data = request.get_json() or {}
except Exception, exc:
raise InvalidUsage(_('error decoding json from incoming request'))
else:
data = request.values
data = CombinedMultiDict([data, request.files])
output = {}
if copy:
# for some reason, following statement doesn't work
# output.update(data)
# so we have to use following statement
for k in data.keys():
output[k] = data[k]
if with_view_args:
output.update(request.view_args)
for key in self.field_names:
f = self.field_by_name[key]
f.validate(data, output)
return output