我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用werkzeug.datastructures.ImmutableMultiDict()。
def process(self, formdata=None, obj=None, data=None, **kwargs): if not self.select_field or not getattr(self, self.select_field, False): return selected_value = kwargs.pop(self.select_field, None) selected_args = kwargs wrapped_formdata = self.meta.wrap_formdata(self, formdata) if wrapped_formdata and isinstance(wrapped_formdata, ImmutableMultiDict): selected_value = wrapped_formdata.get(self._prefix + self.select_field, '') key_prefix = self._prefix + selected_value + '-' selected_args = {k[len(key_prefix):]: v for k, v in wrapped_formdata.items() if key_prefix in k} if selected_value: kwargs = {self.select_field: selected_value, selected_value: selected_args} if not getattr(self, selected_value, False): self._create_dynamic_destination_form(kwargs) super(BaseDestinationForm, self).process(formdata, obj, data, **kwargs)
def manual_parse(self, view, req, **mainkwargs): ''' Manually parse the args ''' # args = parser.parse(user_args, request) self._get_release_endpoint(view) url = self._get_url() self._check_mainkwargs(**mainkwargs) self.create_args() self._pop_kwargs(**mainkwargs) newargs = parser.parse(self.final_args, req, force_all=True, **self._main_kwargs) # see if we make it a multidict makemulti = mainkwargs.get('makemulti', None) if makemulti: from werkzeug.datastructures import ImmutableMultiDict newargs = ImmutableMultiDict(newargs.copy()) return newargs
def test_basic(self, mock_request, mock_url_for): mock_request.form = ImmutableMultiDict([ ("foo.txt", "foocontent"), ("bar/baz/bah.txt", "bahcontent") ]) job_id = "job-id-xxxx" expected_response = { "archive_path": {"function": "fileserver.get_submission_archive", "id": job_id, "ext": "zip"}, "result_path": {"function": "fileserver.store_result", "id": job_id, "ext": "zip"} } dirs = DirectoryStructure() actual_response = json.loads(store_submission(job_id, dirs)) self.assertEqual(expected_response, actual_response) job_dir = os.path.join(dirs.submission_dir, job_id) self.assertTrue(os.path.isdir(job_dir)) self.assertTrue(os.path.exists(os.path.join(dirs.archive_dir, job_id + ".zip")))
def make_fake_dashboard(name='Random chart', max_charts=10): """Generate fake dashboard data with a specific number of random charts. Args: name (str): The name of the new dashboard (default: {'Random chart'}) max_charts (int): Max number of charts to make (default: {10}) Returns: dict: The chart configuration. """ charts = ImmutableMultiDict([ make_fake_chart_data() for _ in range(max_charts)] ) return dict( name=name, created_by='global', date=dt.now(), category=choice(settings.CHARTS_CONFIG.keys()), modules=db.format_charts(charts), id=str(uuid1()), layout='freeform', )
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
def add_year_restriction(self, function): """Resource method decorator which applies a restriction only allowing results related to a syllabus of one year of age or older. This only works for HTTP GET methods on collection resources. Other methods will be unaffected entirely by this decorator. """ method = function.__name__ __, resource_type = self.resource_method_info(function) if method == "get" and resource_type == ResourceType.collection: @wraps(function) def new_function_to_replace_old(*args, **kwargs): request_args = { 'useOldIndex': True } request_args.update(flask.request.args) flask.request.args = ImmutableMultiDict(request_args) return function(*args, **kwargs) return new_function_to_replace_old else: return function # TODO, FIXME: bad, remove this ASAP # (this is here as filler because we haven't gotten # to the elasticsearch bit yet)