def _get_content_from_file(self, filename, encoding):
        f = open(filename, 'r')
        try:
            content = f.read()
            if chardet.detect(content)['encoding'].startswith(self.format_encoding):
                #f = f.decode(self.format_encoding)
                encoding = self.format_encoding
            else:
                #f = f.decode(self.default_encoding)
                encoding = 'utf-8'
            f.close()
            f = codecs.open(filename, 'r', encoding=encoding)
            return f.read()
        except IOError, e:
            logger.warning(
                "Error opening file %s with encoding %s: %s" %\
                    (filename, self.format_encoding, e.message),
                exc_info=True
            )
            raise FormatError(e.message)
        except Exception, e:
            logger.error("Unhandled exception: %s" % e.message, exc_info=True)
            raise
        finally:
            f.close()
dataset/ETHPy150Open rvanlaar/easy-transifex/src/transifex/transifex/resources/formats/strings.py/AppleStringsHandler._get_content_from_file/original