def sanitize_file_name(x): from calibre.ebooks.oeb.polish.check.parsing import make_filename_safe x = sanitize_file_name_base(x) while '..' in x: x = x.replace('..', '.') return make_filename_safe(x)