Python werkzeug.datastructures 模块,ImmutableMultiDict() 实例源码

我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用werkzeug.datastructures.ImmutableMultiDict()

项目:wazo-admin-ui    作者:wazo-pbx    | 项目源码 | 文件源码
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)
项目:marvin    作者:sdss    | 项目源码 | 文件源码
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
项目:fileserver    作者:ReCodEx    | 项目源码 | 文件源码
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")))
项目:flask_jsondash    作者:christabor    | 项目源码 | 文件源码
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',
    )
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
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
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
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
项目:osp-api    作者:opensyllabus    | 项目源码 | 文件源码
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)
项目:FileStoreGAE    作者:liantian-cn    | 项目源码 | 文件源码
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
项目:python-group-proj    作者:Sharcee    | 项目源码 | 文件源码
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
项目:webapp    作者:superchilli    | 项目源码 | 文件源码
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
项目:gardenbot    作者:GoestaO    | 项目源码 | 文件源码
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
项目:flask-zhenai-mongo-echarts    作者:Fretice    | 项目源码 | 文件源码
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
项目:flask    作者:bobohope    | 项目源码 | 文件源码
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