1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-19 00:17:51 +02:00

make _safe_print and _asciify private

This commit is contained in:
Kelly Brazil
2022-04-27 07:37:31 -07:00
parent 78d2b239c8
commit d9c0b8f8ad
2 changed files with 11 additions and 13 deletions

View File

@ -84,9 +84,6 @@ if PYGMENTS_INSTALLED:
} }
def set_env_colors(env_colors=None): def set_env_colors(env_colors=None):
""" """
Return a dictionary to be used in Pygments custom style class. Return a dictionary to be used in Pygments custom style class.
@ -442,11 +439,11 @@ def main():
sys.exit(0) sys.exit(0)
if help_me: if help_me:
utils.safe_print(help_doc(sys.argv)) utils._safe_print(help_doc(sys.argv))
sys.exit(0) sys.exit(0)
if version_info: if version_info:
utils.safe_print(versiontext()) utils._safe_print(versiontext())
sys.exit(0) sys.exit(0)
# if magic syntax used, try to run the command and error if it's not found, etc. # if magic syntax used, try to run the command and error if it's not found, etc.
@ -461,7 +458,7 @@ def main():
try: try:
magic_stdout, magic_stderr, magic_exit_code = run_user_command(run_command) magic_stdout, magic_stderr, magic_exit_code = run_user_command(run_command)
if magic_stderr: if magic_stderr:
utils.safe_print(magic_stderr[:-1], file=sys.stderr) utils._safe_print(magic_stderr[:-1], file=sys.stderr)
except OSError as e: except OSError as e:
if debug: if debug:

View File

@ -9,7 +9,7 @@ from functools import lru_cache
from typing import List, Iterable, Union, Optional from typing import List, Iterable, Union, Optional
def asciify(string: str) -> str: def _asciify(string: str) -> str:
""" """
Return a string downgraded from Unicode to ASCII with some simple Return a string downgraded from Unicode to ASCII with some simple
conversions. conversions.
@ -21,11 +21,12 @@ def asciify(string: str) -> str:
return string return string
def safe_print(string: str, sep=' ', end='\n', file=sys.stdout, flush=False) -> None: def _safe_print(string: str, sep=' ', end='\n', file=sys.stdout, flush=False) -> None:
"""Output for both UTF-8 and ASCII encoding systems"""
try: try:
print(string, sep=sep, end=end, file=file, flush=flush) print(string, sep=sep, end=end, file=file, flush=flush)
except UnicodeEncodeError: except UnicodeEncodeError:
print(asciify(string), sep=sep, end=end, file=file, flush=flush) print(_asciify(string), sep=sep, end=end, file=file, flush=flush)
def warning_message(message_lines: List[str]) -> None: def warning_message(message_lines: List[str]) -> None:
@ -55,13 +56,13 @@ def warning_message(message_lines: List[str]) -> None:
first_line = message_lines.pop(0) first_line = message_lines.pop(0)
first_str = f'jc: Warning - {first_line}' first_str = f'jc: Warning - {first_line}'
first_str = first_wrapper.fill(first_str) first_str = first_wrapper.fill(first_str)
safe_print(first_str, file=sys.stderr) _safe_print(first_str, file=sys.stderr)
for line in message_lines: for line in message_lines:
if line == '': if line == '':
continue continue
message = next_wrapper.fill(line) message = next_wrapper.fill(line)
safe_print(message, file=sys.stderr) _safe_print(message, file=sys.stderr)
def error_message(message_lines: List[str]) -> None: def error_message(message_lines: List[str]) -> None:
@ -87,13 +88,13 @@ def error_message(message_lines: List[str]) -> None:
first_line = message_lines.pop(0) first_line = message_lines.pop(0)
first_str = f'jc: Error - {first_line}' first_str = f'jc: Error - {first_line}'
first_str = first_wrapper.fill(first_str) first_str = first_wrapper.fill(first_str)
safe_print(first_str, file=sys.stderr) _safe_print(first_str, file=sys.stderr)
for line in message_lines: for line in message_lines:
if line == '': if line == '':
continue continue
message = next_wrapper.fill(line) message = next_wrapper.fill(line)
safe_print(message, file=sys.stderr) _safe_print(message, file=sys.stderr)
def compatibility(mod_name: str, compatible: List, quiet: bool = False) -> None: def compatibility(mod_name: str, compatible: List, quiet: bool = False) -> None: