def sanitize_open(filename, open_mode):
 try:
  if (filename == u'-'):
   if (sys.platform == u'win32'):
    import msvcrt
    msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
   return ((sys.stdout.buffer if hasattr(sys.stdout, u'buffer') else sys.stdout), filename)
  stream = open(encodeFilename(filename), open_mode)
  return (stream, filename)
 except (IOError, OSError) as err:
  if (err.errno in (errno.EACCES,)):
   raise
  alt_filename = sanitize_path(filename)
  if (alt_filename == filename):
   raise
  else:
   stream = open(encodeFilename(alt_filename), open_mode)
   return (stream, alt_filename)

def sanitize_open ( filename , open_mode ) : try : if ( filename == u'-' ) : if ( sys . platform == u'win32' ) : import msvcrt msvcrt . setmode ( sys . stdout . fileno ( ) , os . O_BINARY ) return ( ( sys . stdout . buffer if hasattr ( sys . stdout , u'buffer' ) else sys . stdout ) , filename ) stream = open ( encodeFilename ( filename ) , open_mode ) return ( stream , filename ) except ( IOError , OSError ) as err : if ( err . errno in ( errno . EACCES , ) ) : raise alt_filename = sanitize_path ( filename ) if ( alt_filename == filename ) : raise else : stream = open ( encodeFilename ( alt_filename ) , open_mode ) return ( stream , alt_filename )
try to open the given filename .