Skip to content
  • Christian Boltz's avatar
    Prevent encoding errors when reading a file · 7ef2ae9b
    Christian Boltz authored
    
    
    This patch changes open_file_read() and open_file_write() to use 
    errors='surrogateescape' (with fallback to 'replace' for py2).
    
    This avoids a crash when reading a logfile with special characters that 
    are not utf8-encoded (for example a latin1 "ö"), and also avoids crashes 
    at several other places we don't know yet ;-)
    
    The patch also changes open_file_read() and open_file_write() to wrapper
    functions, and moves the "real" code to the new open_file_anymode() 
    function.
    
    Also, I removed the try/except - it's superfluous because it throws the 
    exception without any modifications.
    
    
    Acked-by: default avatarKshitij Gupta <kgupta8592@gmail.com>
    7ef2ae9b