'Retrieve the given key from the given dictionary, removing it if found.
@param d: a dictionary.
@param name: a key in I{d}.
@param proto: an instance of an AMP.
@raise KeyError: if I am not optional and no value was found.
@return: d[name].'

def retrieve(self, d, name, proto):

    if self.optional:
        value = d.get(name)
        if (value is not None):
            del d[name]
    else:
        value = d.pop(name)
    return value
