human
Complete this python program:
def base64unpickle(value, unsafe=False):
assistant
#Here is the Python code you requested.

    """Decodes value from Base64 to plain format and deserializes (with pickle) its content
    >>> base64unpickle(\gAJVBmZvb2JhcnEBLg==\)
    \foobar\
    """
    retVal = None
    def _(self):
        if (len(self.stack) > 1):
            func = self.stack[(-2)]
            if (func not in PICKLE_REDUCE_WHITELIST):
                raise Exception, 'abusing    reduce()    is    bad,    Mkay!'
        self.load_reduce()
    def loads(str):
        f = StringIO.StringIO(str)
        if unsafe:
            unpickler = picklePy.Unpickler(f)
            unpickler.dispatch[picklePy.REDUCE] = _
        else:
            unpickler = pickle.Unpickler(f)
        return unpickler.load()
    try:
        retVal = loads(base64decode(value))
    except TypeError:
        retVal = loads(base64decode(bytes(value)))
    return retVal