@@ -861,7 +861,7 @@ def dataToOutFile(filename, data):
861861 retVal = os .path .join (conf .filePath , filePathToSafeString (filename ))
862862
863863 try :
864- with codecs . open (retVal , "wb" , UNICODE_ENCODING ) as f :
864+ with openFile (retVal , "wb" ) as f :
865865 f .write (data )
866866 except IOError , ex :
867867 errMsg = "something went wrong while trying to write "
@@ -1813,7 +1813,7 @@ def readCachedFileContent(filename, mode='rb'):
18131813 with kb .locks .cache :
18141814 if filename not in kb .cache .content :
18151815 checkFile (filename )
1816- with codecs . open (filename , mode , UNICODE_ENCODING ) as f :
1816+ with openFile (filename , mode ) as f :
18171817 kb .cache .content [filename ] = f .read ()
18181818
18191819 return kb .cache .content [filename ]
@@ -1878,7 +1878,7 @@ def initCommonOutputs():
18781878 kb .commonOutputs = {}
18791879 key = None
18801880
1881- with codecs . open (paths .COMMON_OUTPUTS , 'r' , UNICODE_ENCODING ) as f :
1881+ with openFile (paths .COMMON_OUTPUTS , 'r' ) as f :
18821882 for line in f .readlines (): # xreadlines doesn't return unicode strings when codec.open() is used
18831883 if line .find ('#' ) != - 1 :
18841884 line = line [:line .find ('#' )]
@@ -1905,7 +1905,7 @@ def getFileItems(filename, commentPrefix='#', unicode_=True, lowercase=False, un
19051905 checkFile (filename )
19061906
19071907 try :
1908- with codecs . open (filename , 'r' , UNICODE_ENCODING , errors = "ignore" ) if unicode_ else open (filename , 'r' ) as f :
1908+ with openFile (filename , 'r' , errors = "ignore" ) if unicode_ else open (filename , 'r' ) as f :
19091909 for line in (f .readlines () if unicode_ else f .xreadlines ()): # xreadlines doesn't return unicode strings when codec.open() is used
19101910 if commentPrefix :
19111911 if line .find (commentPrefix ) != - 1 :
@@ -2822,13 +2822,13 @@ def showHttpErrorCodes():
28222822 for code , count in kb .httpErrorCodes .items ())
28232823 logger .warn (warnMsg )
28242824
2825- def openFile (filename , mode = 'r' ):
2825+ def openFile (filename , mode = 'r' , encoding = UNICODE_ENCODING , errors = "replace" ):
28262826 """
28272827 Returns file handle of a given filename
28282828 """
28292829
28302830 try :
2831- return codecs .open (filename , mode , UNICODE_ENCODING , "replace" )
2831+ return codecs .open (filename , mode , encoding , errors )
28322832 except IOError :
28332833 errMsg = "there has been a file opening error for filename '%s'. " % filename
28342834 errMsg += "Please check %s permissions on a file " % ("write" if \
0 commit comments