Beispiel #1
0
def update(existing, add=False, **kwargs):
    """Update an existing header dictionary with the values in kwargs, adding
    new values only if add is true.

    :return: Updated dictionary of header entries
    :rtype: dict of strings
    """
    headerargs = OrderedDict()
    fixedargs = cidict()
    for key, value in kwargs.items():
        key = key.replace("_", "-")
        if key.islower():
            key = key.title()
        fixedargs[key] = value
    removed = []
    for key in poheader.header_order:
        if key in existing:
            if key in fixedargs:
                headerargs[key] = fixedargs.pop(key)
            else:
                headerargs[key] = existing[key]
            removed.append(key)
        elif add and key in fixedargs:
            headerargs[key] = fixedargs.pop(key)
    for key, value in existing.items():
        if key not in removed:
            headerargs[key] = value
    if add:
        for key in fixedargs:
            headerargs[key] = fixedargs[key]
    return headerargs
Beispiel #2
0
def test_cidict_has_key():
    cid = dictutils.cidict()
    cid['lower'] = 'lowercase'
    assert 'lower' in cid
    assert 'Lower' in cid
    assert 'LOWER' in cid
    assert 'upper' not in cid
Beispiel #3
0
def update(existing, add=False, **kwargs):
    """Update an existing header dictionary with the values in kwargs, adding new values
    only if add is true.

    :return: Updated dictionary of header entries
    :rtype: dict of strings
    """
    headerargs = OrderedDict()
    fixedargs = cidict()
    for key, value in kwargs.items():
        key = key.replace("_", "-")
        if key.islower():
            key = key.title()
        fixedargs[key] = value
    removed = []
    for key in poheader.header_order:
        if key in existing:
            if key in fixedargs:
                headerargs[key] = fixedargs.pop(key)
            else:
                headerargs[key] = existing[key]
            removed.append(key)
        elif add and key in fixedargs:
            headerargs[key] = fixedargs.pop(key)
    for key, value in six.iteritems(existing):
        if not key in removed:
            headerargs[key] = value
    if add:
        for key in fixedargs:
            headerargs[key] = fixedargs[key]
    return headerargs
Beispiel #4
0
def test_cidict_has_key():
    cid = dictutils.cidict()
    cid["lower"] = "lowercase"
    assert "lower" in cid
    assert "Lower" in cid
    assert "LOWER" in cid
    assert "upper" not in cid