def undouble_unicode_escape(value):
    """ The mother of all hacks.
    This tries to work around unicode/string confusion between
    python2 and python3 while opening files in text mode that contain
    bytes, or strings, that represent UTF-8 encoded unicode, or various
    levels of escaped UTF-8 representing unicode, or whatever...

    All of this is end-of-pipe window dressing to work around the confusion
    in the i18ndude code base about filehandles, unicode, printing to stdout
    and then redirecting stdout to filehandles again and then ... etc.
    """
    try:
        value = value.decode('raw_unicode_escape')
    except UnicodeEncodeError:
        pass
    except AttributeError:
        pass
    try:
        value = value.encode('raw_unicode_escape').decode('utf-8')
    except UnicodeDecodeError:
        pass
    except UnicodeEncodeError:
        pass
    except AttributeError:
        return value
    try:
        value = value.encode('raw_unicode_escape').decode('utf-8')
    except UnicodeDecodeError:
        pass
    value = value.encode('raw_unicode_escape').decode('raw_unicode_escape')
    try:
        value = value.decode('raw_unicode_escape')
    except UnicodeEncodeError:
        pass
    except AttributeError:
        pass
    return value
