diff --git a/wordfence/cli/banner/banner.py b/wordfence/cli/banner/banner.py index 9fc90f52..366d688c 100644 --- a/wordfence/cli/banner/banner.py +++ b/wordfence/cli/banner/banner.py @@ -106,7 +106,9 @@ def show_welcome_banner(): def should_show_welcome_banner(banner_enabled): - return banner_enabled and sys.stdout.isatty() + return banner_enabled \ + and sys.stdout.isatty() \ + and sys.stdout.encoding == 'utf-8' def show_welcome_banner_if_enabled(config) -> None: diff --git a/wordfence/cli/cli.py b/wordfence/cli/cli.py index df8e1bbb..1cfedc44 100755 --- a/wordfence/cli/cli.py +++ b/wordfence/cli/cli.py @@ -102,6 +102,18 @@ def _get_cacheable_types(self) -> Set[str]: def display_help(self) -> None: self.helper.display_help(self.config.subcommand) + def configure_stdio(self) -> bool: + original_encoding = sys.stdout.encoding + sys.stdout.reconfigure(encoding='utf-8', errors='ignore') + if original_encoding != 'utf-8': + log.warning( + f'Encoding for stdout is {original_encoding} instead of ' + 'utf-8' + ) + return True + else: + return False + def invoke(self) -> int: with CliContext( self.config, @@ -110,11 +122,13 @@ def invoke(self) -> int: self.allows_color ) as context: context.initialize_logging() + stdio_changed = self.configure_stdio() if self.config.purge_cache: context.cache.purge() - show_welcome_banner_if_enabled(self.config) + if not stdio_changed: + show_welcome_banner_if_enabled(self.config) if self.config.help: self.display_help() diff --git a/wordfence/util/io.py b/wordfence/util/io.py index c2f4d65f..a3cb4bf8 100644 --- a/wordfence/util/io.py +++ b/wordfence/util/io.py @@ -35,7 +35,10 @@ def read_entry(self) -> Optional[str]: self._buffer = self._buffer[index + 1:] return entry elif not self._end_of_stream: - read = self.stream.read(self.chunk_size) + read = os.read( + self.stream.fileno(), + self.chunk_size + ).decode(self.stream.encoding) if read == '': self._end_of_stream = True self._buffer += read diff --git a/wordfence/version.py b/wordfence/version.py index 38913a4e..a072e793 100644 --- a/wordfence/version.py +++ b/wordfence/version.py @@ -1,2 +1,2 @@ -__version__ = '3.0.1' +__version__ = '3.0.2' __version_name__ = 'Ghost Rider' diff --git a/wordfence/wordpress/identifier.py b/wordfence/wordpress/identifier.py index e5df1e12..9055e829 100644 --- a/wordfence/wordpress/identifier.py +++ b/wordfence/wordpress/identifier.py @@ -71,7 +71,7 @@ def __str__(self) -> str: else: software = self.extension.get_name() version = self.extension.version - return f'{self.local_path} of {self.type} {software} ({version})' + return f'{self.local_path} of {self.type.value} {software} ({version})' class KnownPath: