当前位置: 首页>>代码示例>>Python>>正文


Python MultiDict.pop方法代码示例

本文整理汇总了Python中webob.multidict.MultiDict.pop方法的典型用法代码示例。如果您正苦于以下问题:Python MultiDict.pop方法的具体用法?Python MultiDict.pop怎么用?Python MultiDict.pop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在webob.multidict.MultiDict的用法示例。


在下文中一共展示了MultiDict.pop方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: whitenoise_tween

# 需要导入模块: from webob.multidict import MultiDict [as 别名]
# 或者: from webob.multidict.MultiDict import pop [as 别名]
    def whitenoise_tween(request):
        whn = request.registry.whitenoise

        if whn.autorefresh:
            static_file = whn.find_file(request.path_info)
        else:
            static_file = whn.files.get(request.path_info)

        # We could not find a static file, so we'll just continue processing
        # this as normal.
        if static_file is None:
            return handler(request)

        request_headers = dict(kv for kv in request.environ.items() if kv[0].startswith("HTTP_"))

        if request.method not in {"GET", "HEAD"}:
            return HTTPMethodNotAllowed()
        else:
            path, headers = static_file.get_path_and_headers(request_headers)
            headers = MultiDict(headers)

            resp = FileResponse(
                path,
                request=request,
                content_type=headers.pop("Content-Type", None),
                content_encoding=headers.pop("Content-Encoding", None),
            )
            resp.md5_etag()
            resp.headers.update(headers)

            return resp
开发者ID:pypa,项目名称:warehouse,代码行数:33,代码来源:static.py

示例2: test_multidict

# 需要导入模块: from webob.multidict import MultiDict [as 别名]
# 或者: from webob.multidict.MultiDict import pop [as 别名]
def test_multidict():
    d = MultiDict(a=1, b=2)
    eq(d['a'], 1)
    eq(d.getall('c'), [])

    d.add('a', 2)
    eq(d['a'], 2)
    eq(d.getall('a'), [1, 2])

    d['b'] = 4
    eq(d.getall('b'), [4])
    eq(list(d.keys()), ['a', 'a', 'b'])
    eq(list(d.items()), [('a', 1), ('a', 2), ('b', 4)])
    eq(d.mixed(), {'a': [1, 2], 'b': 4})

    # test getone

    # KeyError: "Multiple values match 'a': [1, 2]"
    assert_raises(KeyError, d.getone, 'a')
    eq(d.getone('b'), 4)
    # KeyError: "Key not found: 'g'"
    assert_raises(KeyError, d.getone, 'g')

    eq(d.dict_of_lists(), {'a': [1, 2], 'b': [4]})
    assert 'b' in d
    assert 'e' not in d
    d.clear()
    assert 'b' not in d
    d['a'] = 4
    d.add('a', 5)
    e = d.copy()
    assert 'a' in e
    e.clear()
    e['f'] = 42
    d.update(e)
    eq(d, MultiDict([('a', 4), ('a', 5), ('f', 42)]))
    f = d.pop('a')
    eq(f, 4)
    eq(d['a'], 5)


    eq(d.pop('g', 42), 42)
    assert_raises(KeyError, d.pop, 'n')
    # TypeError: pop expected at most 2 arguments, got 3
    assert_raises(TypeError, d.pop, 4, 2, 3)
    d.setdefault('g', []).append(4)
    eq(d, MultiDict([('a', 5), ('f', 42), ('g', [4])]))
开发者ID:B-Rich,项目名称:webob,代码行数:49,代码来源:test_misc.py

示例3: test_multidict

# 需要导入模块: from webob.multidict import MultiDict [as 别名]
# 或者: from webob.multidict.MultiDict import pop [as 别名]
def test_multidict():
    d = MultiDict(a=1, b=2)
    assert d['a'] == 1
    assert d.getall('c') == []

    d.add('a', 2)
    assert d['a'] == 2
    assert d.getall('a') == [1, 2]

    d['b'] = 4
    assert d.getall('b') == [4]
    assert list(d.keys()) == ['a', 'a', 'b']
    assert list(d.items()) == [('a', 1), ('a', 2), ('b', 4)]
    assert d.mixed() == {'a': [1, 2], 'b': 4}

    # test getone

    # KeyError: "Multiple values match 'a': [1, 2]"
    with pytest.raises(KeyError):
        d.getone('a')

    assert d.getone('b') == 4
    # KeyError: "Key not found: 'g'"
    with pytest.raises(KeyError):
        d.getone('g')

    assert d.dict_of_lists() == {'a': [1, 2], 'b': [4]}
    assert 'b' in d
    assert 'e' not in d
    d.clear()
    assert 'b' not in d
    d['a'] = 4
    d.add('a', 5)
    e = d.copy()
    assert 'a' in e
    e.clear()
    e['f'] = 42
    d.update(e)
    assert d == MultiDict([('a', 4), ('a', 5), ('f', 42)])
    f = d.pop('a')
    assert f == 4
    assert d['a'] == 5

    assert d.pop('g', 42) == 42
    with pytest.raises(KeyError):
        d.pop('n')
    # TypeError: pop expected at most 2 arguments, got 3
    with pytest.raises(TypeError):
        d.pop(4, 2, 3)
    d.setdefault('g', []).append(4)
    assert d == MultiDict([('a', 5), ('f', 42), ('g', [4])])
开发者ID:adamchainz,项目名称:webob,代码行数:53,代码来源:test_misc.py

示例4: params

# 需要导入模块: from webob.multidict import MultiDict [as 别名]
# 或者: from webob.multidict.MultiDict import pop [as 别名]
    def params(self, key=None):
        result = []
        if key is None:
            return self.request.params

        islist = False
        list_key = key + '[]'
        if list_key in self.request.params:
            islist = True

        if key in self.request.params or list_key in self.request.params:
            dict_copy = self.request.params.copy()
            dict_copy = MultiDict([(k.replace('[]', ''), value)
                                   for (k, value) in dict_copy.items()])
            while key in dict_copy:
                result.append(dict_copy.pop(key))

            len_result = len(result)
            if not islist and len_result == 1:
                return result[0]
            elif islist or len_result > 1:
                return result

        return None
开发者ID:ecreall,项目名称:pontus,代码行数:26,代码来源:view.py


注:本文中的webob.multidict.MultiDict.pop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。