本文整理汇总了Python中werkzeug.datastructures.MultiDict类的典型用法代码示例。如果您正苦于以下问题:Python MultiDict类的具体用法?Python MultiDict怎么用?Python MultiDict使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MultiDict类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: linreg2
def linreg2():
global final_html
global df,origin_df
lin_reg_key = list()
firstkey = ""
if request.method == 'POST':
Listkey1 = list(MultiDict(request.form).values())
Listkey2 = MultiDict(request.form)
DV_lin_reg = Listkey2.get('DV')
df1 = df
for key1 in Listkey1:
if(key1 <> "Build Linear Regression Model" and key1 <> DV_lin_reg):
lin_reg_key.append(key1)
df1 = df.loc[:,lin_reg_key]
df2 = df1.values
temp_count = 0
Y = df[DV_lin_reg]
linreg = linear_model.LinearRegression()
fit1 = linreg.fit(df2,Y.values)
s = fit1.coef_
temp_df = df[0:15]
t = """</div><div style="float:right;"><br> Linear Regression Result <br>"""
final_html = template.s1 + t + s + "</div><br><br><br>" + temp_df.to_html()
return final_html
return 'helloo'
示例2: get_form
def get_form(self, formdata=None, load_draft=True,
validate_draft=False):
"""
Create form instance with draft data and form data if provided.
:param formdata: Incoming form data.
:param files: Files to ingest into form
:param load_draft: True to initialize form with draft data.
:param validate_draft: Set to true to validate draft data, when no form
data is provided.
"""
if not self.has_form():
raise FormDoesNotExists(self.id)
draft_data = unicodifier(self.values) if load_draft else {}
formdata = MultiDict(formdata or {})
form = self.form_class(
formdata=formdata, **draft_data
)
if formdata:
form.reset_field_data(exclude=formdata.keys())
# Set field flags
if load_draft and self.flags:
form.set_flags(self.flags)
if validate_draft and draft_data and formdata is None:
form.validate()
return form
示例3: register
def register():
data = MultiDict(mapping=request.json)
inputs = RegistrationForm(data, csrf_enabled=False)
if not inputs.validate():
return transform(300, message="Invalid inputs")
else:
firstName = data.get('first_name')
lastName = data.get('last_name')
email = data.get('email')
password = data.get('password')
user = User(email, password, firstName, lastName)
auth = AuthToken()
user.tokens.append(auth)
try:
db.session.add(user)
# db.session.add(auth)
db.session.commit()
except IntegrityError as e:
return jsonify({"error": "email already taken"})
response = auth.__repr__()
response.update({
'user_id': user.id,
'first_name': user.first_name,
'last_name': user.last_name
})
return jsonify(response)
示例4: tree3
def tree3():
global final_html
global df,df_train,df_test,test_train_created,origin_df
chi_key = list()
init_style_string = template.style_string
if request.method == 'POST':
Listkey1 = list(MultiDict(request.form).values())
Listkey2 = MultiDict(request.form)
DV_tree = Listkey2.get('DV')
df1 = df
for key1 in Listkey1:
if(key1 <> "Build Tree" and key1 <> DV_tree):
chi_key.append(key1)
df1 = df.loc[:,chi_key]
df2 = df1.values
Y = df[DV_tree]
clf = tree.DecisionTreeClassifier()
clf = clf.fit(df2,Y.values)
dot_data = StringIO()
tree.export_graphviz(clf, out_file=dot_data)
k = dot_data.getvalue()
left_px = 600
width_px = 150
top_px = 50
height_px = 309
s = build_tree_html(k,init_style_string,left_px,width_px,top_px,height_px)
temp_df = df[0:15]
t = """</div><div style="width:600px; height:700px; position: absolute; top: 20px; left:500px;"><br> Decision Tree result <br>"""
final_html = template.s1 + t + k + "<br><br></div>" + temp_df.to_html()
return final_html
return 'helloo'
示例5: treat
def treat():
global final_html
global df,df_train,df_test,test_train_created,origin_df
firstkey = False
secondkey = False
if request.method == 'POST':
try:
Listkey1 = list(MultiDict(request.form).values())
Listkey2 = MultiDict(request.form)
for key1 in Listkey1:
if(key1 == "Replace nulls,NAs with zeros"):
firstkey = True
secondkey = False
elif(key1 == "Custom: Enter values to replace"):
secondkey = True
firstkey = False
if(secondkey):
replace_str = str(Listkey2.get('changeval'))
for key1 in Listkey1:
if(key1 <> "Replace nulls,NAs with zeros" and key1 <> replace_str and key1 <> "Custom: Enter values to replace"):
df[key1].fillna(replace_str)
elif(firstkey):
replace_str = str(Listkey2.get('changeval'))
for key1 in Listkey1:
if(key1 <> "Replace nulls,NAs with zeros" and key1 <> replace_str and key1 <> "Custom: Enter values to replace"):
df[key1].fillna(0)
temp_df = df[1:15]
final_html = template.s1 + "<br>Null values were replaced!!<br><br></div>" + temp_df.to_html()
return final_html
except:
final_html = template.s1 + """<br><font color="lightcoral"> Something went wrong. Please try again !! <font><br><br></div>""" + df[1:15].to_html()
return final_html
return 'helloo'
示例6: cheat
def cheat():
args = MultiDict()
args.update(flask.request.form)
if flask.request.method == "GET":
args.update(flask.request.args)
form = CheatForm(args)
if flask.request.method == "POST" and form.validate():
user = User.objects.with_id(form.name.data)
m = False
if form.item.data and form.quantity.data:
m = True
q = user.inventory.get(form.item.data, 0) + form.quantity.data
user.inventory[form.item.data] = q
flask.flash("Added {} item{}".format(form.quantity.data,
"s" if form.quantity.data > 1 else ""))
if form.coin.data:
m = True
user.balance += form.coin.data
flask.flash("Added {} coin{}".format(form.coin.data,
"s" if form.coin.data > 1 else ""))
if not m:
flask.flash("No changes made!","error")
else:
user.save()
return flask.redirect(flask.url_for(".single_user", name=user.name))
return flask.render_template("form.html", form=form)
示例7: test1
def test1():
global final_html
global df,df_train,df_test,test_train_created,origin_df
unique_count = 0
err_key=0
if request.method == 'POST':
try:
Listkey1 = list(MultiDict(request.form).values())
Listkey2 = MultiDict(request.form)
test_per = int(Listkey2.get('test_percent'))
temp_df = df[1:15]
if(float(test_per) < 0 or float(test_per) > 100):
err_key = 1
if(err_key==0):
prop_test = float(test_per)/float(100)
msk = np.random.rand(len(df)) < prop_test
df_train = df[~msk]
df_test = df[msk]
print "Length of Train",len(df_train)
print "Length of Test",len(df_test)
test_train_created = True
final_html = template.s1 + "</div><br><br> Test and Train datasets created <br> " + temp_df.to_html()
elif(err_key==1):
final_html = template.s1 + """<br><br> <font color="red"> Please enter a valid percentage value </font> <br></div> """ + temp_df.to_html()
return final_html
except ValueError:
final_html = template.s1 + """<br><br><font color="lightcoral"> Error. Please enter proper value to create Test and Train dataset. </font><br> </div>""" + df[1:15].to_html()
return 'helloo'
示例8: peek_query
def peek_query(args):
if not isinstance(args, MultiDict):
args = MultiDict(args)
text = args.get('q', '').strip()
q = text_query(text)
filters = parse_filters(args)
for entity in args.getlist('entity'):
filters.append(('entities.id', entity))
q = filter_query(q, filters, [])
q = add_filter(q, {
'not': {
'terms': {
'collection_id': authz.collections(authz.READ)
}
}
})
q = {
'query': q,
'size': 0,
'aggregations': {
'collections': {
'terms': {'field': 'collection_id', 'size': 30}
}
},
'_source': False
}
# import json
# print json.dumps(q, indent=2)
result = get_es().search(index=get_es_index(), body=q,
doc_type=TYPE_DOCUMENT)
aggs = result.get('aggregations', {}).get('collections', {})
buckets = aggs.get('buckets', [])
q = Collection.all_by_ids([b['key'] for b in buckets])
q = q.filter(Collection.creator_id != None) # noqa
objs = {o.id: o for o in q.all()}
roles = {}
for bucket in buckets:
collection = objs.get(bucket.get('key'))
if collection is None or collection.private:
continue
if collection.creator_id in roles:
roles[collection.creator_id]['total'] += bucket.get('doc_count')
else:
roles[collection.creator_id] = {
'name': collection.creator.name,
'email': collection.creator.email,
'total': bucket.get('doc_count')
}
roles = sorted(roles.values(), key=lambda r: r['total'], reverse=True)
roles = [format_total(r) for r in roles]
total = result.get('hits', {}).get('total')
return format_total({
'roles': roles,
'active': total > 0,
'total': total
})
示例9: payload
def payload():
""" Performs sanity checks or decoding depending on the Content-Type,
then returns the request payload as a dict. If request Content-Type is
unsupported, aborts with a 400 (Bad Request).
.. versionchanged:: 0.7
Allow 'multipart/form-data' form fields to be JSON encoded, once the
MULTIPART_FORM_FIELDS_AS_JSON setting was been set.
.. versionchanged:: 0.3
Allow 'multipart/form-data' content type.
.. versionchanged:: 0.1.1
Payload returned as a standard python dict regardless of request content
type.
.. versionchanged:: 0.0.9
More informative error messages.
request.get_json() replaces the now deprecated request.json
.. versionchanged:: 0.0.7
Native Flask request.json preferred over json.loads.
.. versionadded: 0.0.5
"""
content_type = request.headers.get('Content-Type', '').split(';')[0]
if content_type in config.JSON_REQUEST_CONTENT_TYPES:
return request.get_json(force=True)
elif content_type == 'application/x-www-form-urlencoded':
return multidict_to_dict(request.form) if len(request.form) else \
abort(400, description='No form-urlencoded data supplied')
elif content_type == 'multipart/form-data':
# as multipart is also used for file uploads, we let an empty
# request.form go through as long as there are also files in the
# request.
if len(request.form) or len(request.files):
# merge form fields and request files, so we get a single payload
# to be validated against the resource schema.
formItems = MultiDict(request.form)
if config.MULTIPART_FORM_FIELDS_AS_JSON:
for key, lst in formItems.lists():
new_lst = []
for value in lst:
try:
new_lst.append(json.loads(value))
except ValueError:
new_lst.append(json.loads('"{0}"'.format(value)))
formItems.setlist(key, new_lst)
payload = CombinedMultiDict([formItems, request.files])
return multidict_to_dict(payload)
else:
abort(400, description='No multipart/form-data supplied')
else:
abort(400, description='Unknown or no Content-Type header supplied')
示例10: test_multidict_pickle
def test_multidict_pickle():
"""MultiDict types are pickle-able"""
for protocol in xrange(pickle.HIGHEST_PROTOCOL + 1):
print 'pickling protocol', protocol
d = MultiDict()
d.setlist('foo', [1, 2, 3, 4])
d.setlist('bar', 'foo bar baz'.split())
s = pickle.dumps(d, protocol)
ud = pickle.loads(s)
assert type(ud) is type(d)
print ud.lists()
assert ud == d
ud['newkey'] = 'bla'
assert ud != d
im = ImmutableMultiDict(d)
assert im == d
s = pickle.dumps(im, protocol)
ud = pickle.loads(s)
assert ud == im
assert type(ud) is type(im)
c = CombinedMultiDict([ud, im])
cc = pickle.loads(pickle.dumps(c, protocol))
assert c == cc
assert type(c) is type(cc)
示例11: createMultiDict
def createMultiDict(file_name):
Mdict, uniqueTags = MD(), []
count = max(enumerate(open(file_name)))[0]
iterators = lineGenerator(file_name)
super_dictionary= ast.literal_eval(open("super_dictionary.json","r").readline())
bar = progressbar.ProgressBar(maxval= count, \
widgets=[progressbar.Bar(':', '[', ']'), ' ', progressbar.Percentage()])
#Variant #Context #Topic #Tag
try:
for i in xrange(count):
trans = string.maketrans('\n', '\t')# because there are \n characters on each line
line = string.translate(iterators.next(), trans).split('\t')[:-1]
lookup = super_dictionary[line[1]]
line_words = list(set(SM.getWords(line[1])).union(set(lookup[0])))
if line[0] not in uniqueTags:
uniqueTags = uniqueTags +[line[0]]
for c in xrange(len(line_words)):
Mdict.setlistdefault(line_words[c]).extend([[ line_words ,line, lookup[1], lookup[2] ]])
bar.update(i+1)
bar.finish()
except StopIteration:
pass
return Mdict, uniqueTags
示例12: inspire_search_factory
def inspire_search_factory(self, search):
"""Parse query using Inspire-Query-Parser.
:param self: REST view.
:param search: Elastic search DSL search instance.
:returns: Tuple with search instance and URL arguments.
"""
query_string = request.values.get('q', '')
urlkwargs = MultiDict()
try:
search = search.query_from_iq(query_string)
except SyntaxError:
current_app.logger.debug(
"Failed parsing query: {0}".format(
request.values.get('q', '')),
exc_info=True)
raise InvalidQueryRESTError()
search_index = search._index[0]
search, urlkwargs = inspire_filter_factory(search, urlkwargs, search_index)
search, sortkwargs = default_sorter_factory(search, search_index)
search = select_source(search)
urlkwargs.add('q', query_string)
current_app.logger.debug(json.dumps(search.to_dict(), indent=4))
return search, urlkwargs
示例13: tree2
def tree2():
global final_html
global df,origin_df
chi_key = list()
firstkey = ""
init_style_string = """<p style="position: absolute; font-size: 12px; top: <top>px; width: <width>px; height: <height>px; left:<left>px; text-align: center;">tree_text_here</p>"""
if request.method == 'POST':
Listkey1 = list(MultiDict(request.form).values())
Listkey2 = MultiDict(request.form)
DV_tree = Listkey2.get('DV')
df1 = df
for key1 in Listkey1:
if(key1 <> "Build Tree" and key1 <> DV_tree):
chi_key.append(key1)
df1 = df.loc[:,chi_key]
df2 = df1.values
temp_count = 0
Y = df[DV_tree]
clf = tree.DecisionTreeClassifier()
clf = clf.fit(df2,Y.values)
dot_data = StringIO()
tree.export_graphviz(clf, out_file=dot_data)
k = dot_data.getvalue()
k1 = k.split(";")
left_px = 600
width_px = 150
top_px = 50
height_px = 309
s = build_tree_html(k,init_style_string,left_px,width_px,top_px,height_px)
temp_df = df[0:15]
t = """</div><div style="float:right;"><br> Decision Tree result <br>"""
final_html = template.s1 + t + k + "</div><br><br><br>" + temp_df.to_html()
return final_html
return 'helloo'
示例14: treat
def treat():
global final_html
global df,origin_df
chi_key = list()
firstkey = False
secondkey = False
if request.method == 'POST':
Listkey1 = list(MultiDict(request.form).values())
Listkey2 = MultiDict(request.form)
df1 = df
for key1 in Listkey1:
if(key1 == "Replace nulls,NAs with zeros"):
firstkey = True
secondkey = False
elif(key1 == "Custom: Enter values to replace"):
secondkey = True
firstkey = False
if(secondkey):
replace_str = str(Listkey2.get('changeval'))
for key1 in Listkey1:
if(key1 <> "Replace nulls,NAs with zeros" and key1 <> replace_str and key1 <> "Custom: Enter values to replace"):
df[key1].fillna(replace_str)
elif(firstkey):
replace_str = str(Listkey2.get('changeval'))
for key1 in Listkey1:
if(key1 <> "Replace nulls,NAs with zeros" and key1 <> replace_str and key1 <> "Custom: Enter values to replace"):
df[key1].fillna(0)
temp_df = df[1:15]
final_html = template.s1 + "</div><br>Null values were removed<br><br>" + temp_df.to_html()
return final_html
return 'helloo'
示例15: from_params
def from_params(params: MultiDict, items: int) -> 'Page':
# page, page-size, limit (deprecated)
page = params.get('page', 1, int)
limit = params.get('limit', 0, int)
page_size = params.get('page-size', limit, int)
return Page(page, page_size, items)