def strip_extra_slashes(path):
    """ Strip extra slashes from a filename. Examples:
    '//'  -> '/'
    '/'   -> '/'
    ''    -> ''
    'a//' -> 'a' """

    l = []
    slash = False
    for c in path:
        isslash = (c == '/')
        if not isslash or not slash:
            l.append(c)
        slash = isslash
    if slash and len(l) > 1 and l[-1] == '/':
        l.pop()
    return ''.join(l)