How to use the werkzeug.datastructures.MultiDict function in Werkzeug

To help you get started, we’ve selected a few Werkzeug examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webcompat / webcompat.com / tests / unit / test_uploads.py View on Github external
def form(self):
                    d = MultiDict()
                    d['image'] = filedata
                    return d
github arXiv / arxiv-search / search / controllers / advanced / tests.py View on Github external
def test_order_is_invalid(self, mock_url_for):
        """The order parameter on the request is invalid."""
        request_data = MultiDict({
            'advanced': True,
            'terms-0-operator': 'AND',
            'terms-0-field': 'title',
            'terms-0-term': 'foo',
            'size': 50,     # Valid.
            'order': 'foo'  # Invalid
        })
        with self.assertRaises(BadRequest):
            advanced.search(request_data)
github kylewm / silo.pub / silopub / test_twitter.py View on Github external
def test_publish_reply(self, poster):
        with self.app.test_request_context():
            request.form = MultiDict({
                'in-reply-to': 'https://twitter.com/mashable/status/668134813325508609',
                'content': 'Speak, friend, and enter',
                'url': 'http://bar.co.uk/bat',
            })
            request.files = {}
            poster.return_value = FakeResponse(json.dumps({
                'user': {'screen_name': 'moriafan'},
                'id_str': '234567',
            }))
            resp = twitter.publish(self.site)
            self.assertEqual(201, resp.status_code)
            self.assertEqual('https://twitter.com/moriafan/status/234567',
                             resp.headers['location'])
            poster.assert_called_once_with(
                twitter.CREATE_STATUS_URL, data={
                    'status': '@mashable Speak, friend, and enter',
github ONSdigital / eq-survey-runner / tests / integration / household_composition / test_repeating_household_routing.py View on Github external
def test_repeating_group_skip_second(self):
        # Given I add some people
        form_data = MultiDict()
        form_data.add('household-0-first-name', 'Joe')
        form_data.add('household-0-middle-names', '')
        form_data.add('household-0-last-name', 'Bloggs')
        form_data.add('household-1-first-name', 'Jane')
        form_data.add('household-1-middle-names', '')
        form_data.add('household-1-last-name', 'Doe')
        self.post(form_data)
        self.assertInBody('Is that everyone?')
        self.post({'everyone-at-address-confirmation-answer': 'Yes'})

        # Then provide details for the first member
        joe_dob = {
            'date-of-birth-answer-day': '12',
            'date-of-birth-answer-month': '3',
            'date-of-birth-answer-year': '1990'
        }
github guaosi / flask-movie / app / admin / auth.py View on Github external
def auth_edit(id):
    id_dict=MultiDict([('id',id)])
    values=CombinedMultiDict([id_dict, request.form])
    auth=Auth.query.get_or_404(id)
    form=AuthEditForm(values)
    if request.method == 'POST' and form.validate():
        with db.auto_commit():
            auth.set_attr(form.data)
            db.session.add(auth)
            Oplog('修改权限:' + auth.name + ',id:' + str(auth.id))
            flash('修改权限成功~','ok')
            return redirect(url_for('admin.auth_edit',id=id))
    return render_template('admin/auth_edit.html',form=form,auth=auth)
github ziirish / burp-ui / burpui / api / prefs.py View on Github external
def _update_prefs(self):
        """update prefs"""
        args = self.parser.parse_args()
        sess = session._get_current_object()
        ret = {}
        req = MultiDict()
        for loc in ['values', 'json']:
            data = getattr(request, loc, None)
            if data:
                req.update(data)
        for key in args.keys():
            if key not in req:
                continue
            temp = args.get(key)
            if temp:
                if key == 'language':
                    self._user_language(temp)
                sess[key] = temp
            elif key in sess:  # pragma: no cover
                del sess[key]
            ret[key] = temp
            self._store_prefs(key, temp)
github czcorpus / kontext / lib / actions / concordance.py View on Github external
def _store_semi_persistent_attrs(self, attr_list):
        """
        Stores the state of all semi-persistent parameters (i.e. the ones
        with persistence flag Parameter.PERSISTENT) and also aligned
        corpora form elements (they must be treated in a different way because
        they cannot be hardcoded as Parameter instances due to their dynamic nature).

        arguments:
            explicit_list -- a list of attributes to store (the ones
                             without Parameter.SEMI_PERSISTENT flag will be ignored)
        """
        semi_persist_attrs = self._get_items_by_persistence(Parameter.SEMI_PERSISTENT)
        tmp = MultiDict(self._session.get('semi_persistent_attrs', {}))
        for attr_name in attr_list:
            if attr_name in semi_persist_attrs:
                v = getattr(self.args, attr_name)
                if type(v) in (list, tuple):
                    tmp.setlist(attr_name, v)
                else:
                    tmp[attr_name] = v
        # we have to ensure Werkzeug sets 'should_save' attribute
        self._session['semi_persistent_attrs'] = tmp.items(multi=True)

        # aligned corpora forms inputs require different approach due to their dynamic nature
        if self.args.sel_aligned:
            sess_key = 'aligned_forms:%s' % self.args.corpname
            tmp = self._session.get(sess_key, {})
            # TODO restore this
            for aligned_lang in self.args.sel_aligned:
github flectra-hq / flectra / flectra / http.py View on Github external
def load_request_data(self):
        data = self.pop('serialized_request_data', None)
        files = werkzeug.datastructures.MultiDict()
        try:
            if data:
                # regenerate files filenames with the current session store
                for name, (storename, filename, content_type) in data['files'].items():
                    path = os.path.join(root.session_store.path, storename)
                    files.add(name, (path, filename, content_type))
                yield werkzeug.datastructures.CombinedMultiDict([data['form'], files])
            else:
                yield None
        finally:
            # cleanup files
            for f, _, _ in files.values():
                try:
                    os.unlink(f)
                except IOError:
                    pass
github accelero-cloud / appkernel / appkernel / service.py View on Github external
def _get_request_args():
    request_args = {}
    # extract the query parameters and add to a generic parameter dictionary
    if isinstance(request.args, MultiDict):
        # Multidict is a werkzeug only type so we should check what happens in production
        for arg in request.args:
            query_item = {arg: request.args.get(arg)}
            request_args.update(query_item)
    else:
        request_args.update(request.args)
    return request_args
github plangrid / flask-rebar / flask_rebar / validation.py View on Github external
def _deserialize(self, value, attr, data):
        # data is a MultiDict of query params, so pull out all of the items
        # with getlist instead of just the first
        if not isinstance(data, MultiDict):
            raise ValueError(
                "{} only deserializes {} instances".format(
                    self.__class__.__name__, MultiDict
                )
            )
        items = data.getlist(attr)
        return super(QueryParamList, self)._deserialize(items, attr, data)