Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Milestone/3.0.2 #240

Merged
merged 10 commits into from
Feb 12, 2024
4 changes: 3 additions & 1 deletion wordfence/cli/banner/banner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 15 additions & 1 deletion wordfence/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion wordfence/util/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion wordfence/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '3.0.1'
__version__ = '3.0.2'
__version_name__ = 'Ghost Rider'
2 changes: 1 addition & 1 deletion wordfence/wordpress/identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading