From 2f726a26371b79d96ebff7ec13b8902dc0f981ad Mon Sep 17 00:00:00 2001 From: agiovannini Date: Fri, 21 Jul 2017 13:35:58 +0200 Subject: [PATCH 01/10] Disabled ASCII conversion in order to improve console output encoding/printing. --- fire/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fire/core.py b/fire/core.py index 37af3493..dc07ac8c 100644 --- a/fire/core.py +++ b/fire/core.py @@ -255,7 +255,7 @@ def _OneLineResult(result): return str(result).replace('\n', ' ') try: - return json.dumps(result) + return json.dumps(result, ensure_ascii=False) except (TypeError, ValueError): return str(result).replace('\n', ' ') From b5df39ad489ee8124d111d1f825ea39e7436f40f Mon Sep 17 00:00:00 2001 From: agiovannini Date: Fri, 21 Jul 2017 15:07:46 +0200 Subject: [PATCH 02/10] Shaddy's verbose filtering. --- fire/helputils.py | 321 ++++++++++++++++++++++++---------------------- 1 file changed, 165 insertions(+), 156 deletions(-) diff --git a/fire/helputils.py b/fire/helputils.py index 5c23de3a..72efdd6f 100644 --- a/fire/helputils.py +++ b/fire/helputils.py @@ -23,178 +23,187 @@ from __future__ import print_function import inspect - from fire import completion from fire import inspectutils def _NormalizeField(field): - """Takes a field name and turns it into a human readable name for display. + """Takes a field name and turns it into a human readable name for display. - Args: - field: The field name, used to index into the inspection dict. - Returns: - The human readable name, suitable for display in a help string. - """ - if field == 'type_name': - field = 'type' - return (field[0].upper() + field[1:]).replace('_', ' ') + Args: + field: The field name, used to index into the inspection dict. + Returns: + The human readable name, suitable for display in a help string. + """ + if field == 'type_name': + field = 'type' + return (field[0].upper() + field[1:]).replace('_', ' ') def _DisplayValue(info, field, padding): - """Gets the value of field from the dict info for display. - - Args: - info: The dict with information about the component. - field: The field to access for display. - padding: Number of spaces to indent text to line up with first-line text. - Returns: - The value of the field for display, or None if no value should be displayed. - """ - value = info.get(field) - - if value is None: - return - - skip_doc_types = ('dict', 'list', 'unicode', 'int', 'float', 'bool') - - if field == 'docstring': - if info.get('type_name') in skip_doc_types: - # Don't show the boring default docstrings for these types. - return None - elif value == '': - return None - - elif field == 'usage': - lines = [] - for index, line in enumerate(value.split('\n')): - if index > 0: - line = ' ' * padding + line - lines.append(line) - return '\n'.join(lines) + """Gets the value of field from the dict info for display. + + Args: + info: The dict with information about the component. + field: The field to access for display. + padding: Number of spaces to indent text to line up with first-line text. + Returns: + The value of the field for display, or None if no value should be displayed. + """ + value = info.get(field) + + if value is None: + return + + skip_doc_types = ('dict', 'list', 'unicode', 'int', 'float', 'bool') - return value + if field == 'docstring': + if info.get('type_name') in skip_doc_types: + # Don't show the boring default docstrings for these types. + return None + elif value == '': + return None + + elif field == 'usage': + lines = [] + for index, line in enumerate(value.split('\n')): + if index > 0: + line = ' ' * padding + line + lines.append(line) + return '\n'.join(lines) + + return value def HelpString(component, trace=None, verbose=False): - """Returns a help string for a supplied component. - - The component can be any Python class, object, function, module, etc. - - Args: - component: The component to determine the help string for. - trace: The Fire trace leading to this component. - verbose: Whether to include private members in the help string. - Returns: - String suitable for display giving information about the component. - """ - info = inspectutils.Info(component) - info['usage'] = UsageString(component, trace, verbose) - - fields = [ - 'type_name', - 'string_form', - 'file', - 'line', - - 'docstring', - 'init_docstring', - 'class_docstring', - 'call_docstring', - 'length', - - 'usage', - ] - - max_size = max( - len(_NormalizeField(field)) + 1 - for field in fields - if field in info and info[field]) - format_string = '{{field:{max_size}s}} {{value}}'.format(max_size=max_size) - - lines = [] - for field in fields: - value = _DisplayValue(info, field, padding=max_size + 1) - if value: - if lines and field == 'usage': - lines.append('') # Ensure a blank line before usage. - - lines.append(format_string.format( - field=_NormalizeField(field) + ':', - value=value, - )) - return '\n'.join(lines) + """Returns a help string for a supplied component. + + The component can be any Python class, object, function, module, etc. + + Args: + component: The component to determine the help string for. + trace: The Fire trace leading to this component. + verbose: Whether to include private members in the help string. + Returns: + String suitable for display giving information about the component. + """ + info = inspectutils.Info(component) + info['usage'] = UsageString(component, trace, verbose) + + debug_fields = [ + 'type_name', + 'string_form', + 'file', + 'line', + + 'docstring', + 'init_docstring', + 'class_docstring', + 'call_docstring', + 'length', + + 'usage', + ] + + default_fields = [ + 'docstring', + 'init_docstring', + 'class_docstring', + 'call_docstring', + 'length', + 'usage' + ] + # level.debug, level.verbose + fields = debug_fields if verbose else default_fields + max_size = max( + len(_NormalizeField(field)) + 1 + for field in fields + if field in info and info[field]) + format_string = '{{field:{max_size}s}} {{value}}'.format(max_size=max_size) + + lines = [] + for field in fields: + value = _DisplayValue(info, field, padding=max_size + 1) + if value: + if lines and field == 'usage': + lines.append('') # Ensure a blank line before usage. + + lines.append(format_string.format( + field=_NormalizeField(field) + ':', + value=value, + )) + return '\n'.join(lines) def _UsageStringFromFullArgSpec(command, spec): - """Get a usage string from the FullArgSpec for the given command. - - The strings look like: - command --arg ARG [--opt OPT] [VAR ...] [--KWARGS ...] - - Args: - command: The command leading up to the function. - spec: a FullArgSpec object describing the function. - Returns: - The usage string for the function. - """ - num_required_args = len(spec.args) - len(spec.defaults) - - help_flags = [] - help_positional = [] - for index, arg in enumerate(spec.args): - flag = arg.replace('_', '-') - if index < num_required_args: - help_flags.append('--{flag} {value}'.format(flag=flag, value=arg.upper())) - help_positional.append('{value}'.format(value=arg.upper())) - else: - help_flags.append('[--{flag} {value}]'.format( - flag=flag, value=arg.upper())) - help_positional.append('[{value}]'.format(value=arg.upper())) - - if spec.varargs: - help_flags.append('[{var} ...]'.format(var=spec.varargs.upper())) - help_positional.append('[{var} ...]'.format(var=spec.varargs.upper())) - - for arg in spec.kwonlyargs: - if arg in spec.kwonlydefaults: - arg_str = '[--{flag} {value}]'.format(flag=arg, value=arg.upper()) - else: - arg_str = '--{flag} {value}'.format(flag=arg, value=arg.upper()) - help_flags.append(arg_str) - help_positional.append(arg_str) - - if spec.varkw: - help_flags.append('[--{kwarg} ...]'.format(kwarg=spec.varkw.upper())) - help_positional.append('[--{kwarg} ...]'.format(kwarg=spec.varkw.upper())) - - commands_flags = command + ' '.join(help_flags) - commands_positional = command + ' '.join(help_positional) - commands = [commands_positional] - - if commands_flags != commands_positional: - commands.append(commands_flags) - - return '\n'.join(commands) + """Get a usage string from the FullArgSpec for the given command. + + The strings look like: + command --arg ARG [--opt OPT] [VAR ...] [--KWARGS ...] + + Args: + command: The command leading up to the function. + spec: a FullArgSpec object describing the function. + Returns: + The usage string for the function. + """ + num_required_args = len(spec.args) - len(spec.defaults) + + help_flags = [] + help_positional = [] + for index, arg in enumerate(spec.args): + flag = arg.replace('_', '-') + if index < num_required_args: + help_flags.append('--{flag} {value}'.format(flag=flag, value=arg.upper())) + help_positional.append('{value}'.format(value=arg.upper())) + else: + help_flags.append('[--{flag} {value}]'.format( + flag=flag, value=arg.upper())) + help_positional.append('[{value}]'.format(value=arg.upper())) + + if spec.varargs: + help_flags.append('[{var} ...]'.format(var=spec.varargs.upper())) + help_positional.append('[{var} ...]'.format(var=spec.varargs.upper())) + + for arg in spec.kwonlyargs: + if arg in spec.kwonlydefaults: + arg_str = '[--{flag} {value}]'.format(flag=arg, value=arg.upper()) + else: + arg_str = '--{flag} {value}'.format(flag=arg, value=arg.upper()) + help_flags.append(arg_str) + help_positional.append(arg_str) + + if spec.varkw: + help_flags.append('[--{kwarg} ...]'.format(kwarg=spec.varkw.upper())) + help_positional.append('[--{kwarg} ...]'.format(kwarg=spec.varkw.upper())) + + commands_flags = command + ' '.join(help_flags) + commands_positional = command + ' '.join(help_positional) + commands = [commands_positional] + + if commands_flags != commands_positional: + commands.append(commands_flags) + + return '\n'.join(commands) def UsageString(component, trace=None, verbose=False): - """Returns a string showing how to use the component as a Fire command.""" - command = trace.GetCommand() + ' ' if trace else '' - - if inspect.isroutine(component) or inspect.isclass(component): - spec = inspectutils.GetFullArgSpec(component) - return _UsageStringFromFullArgSpec(command, spec) - - if isinstance(component, (list, tuple)): - length = len(component) - if length == 0: - return command - if length == 1: - return command + '[0]' - return command + '[0..{cap}]'.format(cap=length - 1) - - completions = completion.Completions(component, verbose) - if command: - completions = [''] + completions - return '\n'.join(command + end for end in completions) + """Returns a string showing how to use the component as a Fire command.""" + command = trace.GetCommand() + ' ' if trace else '' + + if inspect.isroutine(component) or inspect.isclass(component): + spec = inspectutils.GetFullArgSpec(component) + return _UsageStringFromFullArgSpec(command, spec) + + if isinstance(component, (list, tuple)): + length = len(component) + if length == 0: + return command + if length == 1: + return command + '[0]' + return command + '[0..{cap}]'.format(cap=length - 1) + + completions = completion.Completions(component, verbose) + if command: + completions = [''] + completions + return '\n'.join(command + end for end in completions) From bde2eb7f222aa5b4fc69ded228f5f32bc84c7871 Mon Sep 17 00:00:00 2001 From: agiovannini Date: Fri, 21 Jul 2017 16:24:02 +0200 Subject: [PATCH 03/10] Enable docstring (magic for __str__) --- fire/helputils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fire/helputils.py b/fire/helputils.py index 72efdd6f..1e3ff94e 100644 --- a/fire/helputils.py +++ b/fire/helputils.py @@ -111,7 +111,8 @@ def HelpString(component, trace=None, verbose=False): 'class_docstring', 'call_docstring', 'length', - 'usage' + 'usage', + 'string_form', ] # level.debug, level.verbose fields = debug_fields if verbose else default_fields From 11b5ff648f1b2a14c7258bb1d8b9d72e60dd4093 Mon Sep 17 00:00:00 2001 From: agiovannini Date: Fri, 21 Jul 2017 16:29:18 +0200 Subject: [PATCH 04/10] Move to top String From... --- fire/helputils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fire/helputils.py b/fire/helputils.py index 1e3ff94e..55473056 100644 --- a/fire/helputils.py +++ b/fire/helputils.py @@ -23,6 +23,7 @@ from __future__ import print_function import inspect + from fire import completion from fire import inspectutils @@ -106,13 +107,13 @@ def HelpString(component, trace=None, verbose=False): ] default_fields = [ + 'string_form', 'docstring', 'init_docstring', 'class_docstring', 'call_docstring', 'length', 'usage', - 'string_form', ] # level.debug, level.verbose fields = debug_fields if verbose else default_fields From 6d44c4234c6d6b2206434448c2c8e1efe5639a0e Mon Sep 17 00:00:00 2001 From: agiovannini Date: Fri, 21 Jul 2017 16:46:51 +0200 Subject: [PATCH 05/10] Revert to pull-request, and move new changes to separated branch Revert "Disabled ASCII conversion in order to improve console output encoding/printing." This reverts commit 2f726a26371b79d96ebff7ec13b8902dc0f981ad. --- fire/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fire/core.py b/fire/core.py index dc07ac8c..37af3493 100644 --- a/fire/core.py +++ b/fire/core.py @@ -255,7 +255,7 @@ def _OneLineResult(result): return str(result).replace('\n', ' ') try: - return json.dumps(result, ensure_ascii=False) + return json.dumps(result) except (TypeError, ValueError): return str(result).replace('\n', ' ') From a0d11cb0d2fe64462c22203ce5653a948088e9d8 Mon Sep 17 00:00:00 2001 From: atgiovannini Date: Fri, 21 Jul 2017 16:46:51 +0200 Subject: [PATCH 06/10] Update with my github username Revert to pull-request, and move new changes to separated branch Revert "Disabled ASCII conversion in order to improve console output encoding/printing." This reverts commit 2f726a26371b79d96ebff7ec13b8902dc0f981ad. --- fire/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fire/core.py b/fire/core.py index dc07ac8c..37af3493 100644 --- a/fire/core.py +++ b/fire/core.py @@ -255,7 +255,7 @@ def _OneLineResult(result): return str(result).replace('\n', ' ') try: - return json.dumps(result, ensure_ascii=False) + return json.dumps(result) except (TypeError, ValueError): return str(result).replace('\n', ' ') From 9c5ecbf37e7c2dd6065ea14962a5db3cb101d1a1 Mon Sep 17 00:00:00 2001 From: atgiovannini Date: Fri, 21 Jul 2017 17:30:34 +0200 Subject: [PATCH 07/10] fix indentations --- fire/helputils.py | 321 ++++++++++++++++++++++------------------------ 1 file changed, 155 insertions(+), 166 deletions(-) diff --git a/fire/helputils.py b/fire/helputils.py index 55473056..3a5804c7 100644 --- a/fire/helputils.py +++ b/fire/helputils.py @@ -29,183 +29,172 @@ def _NormalizeField(field): - """Takes a field name and turns it into a human readable name for display. + """Takes a field name and turns it into a human readable name for display. - Args: - field: The field name, used to index into the inspection dict. - Returns: - The human readable name, suitable for display in a help string. - """ - if field == 'type_name': - field = 'type' - return (field[0].upper() + field[1:]).replace('_', ' ') + Args: + field: The field name, used to index into the inspection dict. + Returns: + The human readable name, suitable for display in a help string. + """ + if field == 'type_name': + field = 'type' + return (field[0].upper() + field[1:]).replace('_', ' ') def _DisplayValue(info, field, padding): - """Gets the value of field from the dict info for display. - - Args: - info: The dict with information about the component. - field: The field to access for display. - padding: Number of spaces to indent text to line up with first-line text. - Returns: - The value of the field for display, or None if no value should be displayed. - """ - value = info.get(field) - - if value is None: - return - - skip_doc_types = ('dict', 'list', 'unicode', 'int', 'float', 'bool') - - if field == 'docstring': - if info.get('type_name') in skip_doc_types: - # Don't show the boring default docstrings for these types. - return None - elif value == '': - return None - - elif field == 'usage': - lines = [] - for index, line in enumerate(value.split('\n')): - if index > 0: - line = ' ' * padding + line - lines.append(line) - return '\n'.join(lines) + """Gets the value of field from the dict info for display. + + Args: + info: The dict with information about the component. + field: The field to access for display. + padding: Number of spaces to indent text to line up with first-line text. + Returns: + The value of the field for display, or None if no value should be displayed. + """ + value = info.get(field) + + if value is None: + return + + skip_doc_types = ('dict', 'list', 'unicode', 'int', 'float', 'bool') + + if field == 'docstring': + if info.get('type_name') in skip_doc_types: + # Don't show the boring default docstrings for these types. + return None + elif value == '': + return None + + elif field == 'usage': + lines = [] + for index, line in enumerate(value.split('\n')): + if index > 0: + line = ' ' * padding + line + lines.append(line) + return '\n'.join(lines) - return value + return value def HelpString(component, trace=None, verbose=False): - """Returns a help string for a supplied component. - - The component can be any Python class, object, function, module, etc. - - Args: - component: The component to determine the help string for. - trace: The Fire trace leading to this component. - verbose: Whether to include private members in the help string. - Returns: - String suitable for display giving information about the component. - """ - info = inspectutils.Info(component) - info['usage'] = UsageString(component, trace, verbose) - - debug_fields = [ - 'type_name', - 'string_form', - 'file', - 'line', - - 'docstring', - 'init_docstring', - 'class_docstring', - 'call_docstring', - 'length', - - 'usage', - ] - - default_fields = [ - 'string_form', - 'docstring', - 'init_docstring', - 'class_docstring', - 'call_docstring', - 'length', - 'usage', - ] - # level.debug, level.verbose - fields = debug_fields if verbose else default_fields - max_size = max( - len(_NormalizeField(field)) + 1 - for field in fields - if field in info and info[field]) - format_string = '{{field:{max_size}s}} {{value}}'.format(max_size=max_size) - - lines = [] - for field in fields: - value = _DisplayValue(info, field, padding=max_size + 1) - if value: - if lines and field == 'usage': - lines.append('') # Ensure a blank line before usage. - - lines.append(format_string.format( - field=_NormalizeField(field) + ':', - value=value, - )) - return '\n'.join(lines) + """Returns a help string for a supplied component. + + The component can be any Python class, object, function, module, etc. + + Args: + component: The component to determine the help string for. + trace: The Fire trace leading to this component. + verbose: Whether to include private members in the help string. + Returns: + String suitable for display giving information about the component. + """ + info = inspectutils.Info(component) + info['usage'] = UsageString(component, trace, verbose) + + fields = [ + 'type_name', + 'string_form', + 'file', + 'line', + + 'docstring', + 'init_docstring', + 'class_docstring', + 'call_docstring', + 'length', + + 'usage', + ] + + max_size = max( + len(_NormalizeField(field)) + 1 + for field in fields + if field in info and info[field]) + format_string = '{{field:{max_size}s}} {{value}}'.format(max_size=max_size) + + lines = [] + for field in fields: + value = _DisplayValue(info, field, padding=max_size + 1) + if value: + if lines and field == 'usage': + lines.append('') # Ensure a blank line before usage. + + lines.append(format_string.format( + field=_NormalizeField(field) + ':', + value=value, + )) + return '\n'.join(lines) def _UsageStringFromFullArgSpec(command, spec): - """Get a usage string from the FullArgSpec for the given command. - - The strings look like: - command --arg ARG [--opt OPT] [VAR ...] [--KWARGS ...] - - Args: - command: The command leading up to the function. - spec: a FullArgSpec object describing the function. - Returns: - The usage string for the function. - """ - num_required_args = len(spec.args) - len(spec.defaults) - - help_flags = [] - help_positional = [] - for index, arg in enumerate(spec.args): - flag = arg.replace('_', '-') - if index < num_required_args: - help_flags.append('--{flag} {value}'.format(flag=flag, value=arg.upper())) - help_positional.append('{value}'.format(value=arg.upper())) - else: - help_flags.append('[--{flag} {value}]'.format( - flag=flag, value=arg.upper())) - help_positional.append('[{value}]'.format(value=arg.upper())) - - if spec.varargs: - help_flags.append('[{var} ...]'.format(var=spec.varargs.upper())) - help_positional.append('[{var} ...]'.format(var=spec.varargs.upper())) - - for arg in spec.kwonlyargs: - if arg in spec.kwonlydefaults: - arg_str = '[--{flag} {value}]'.format(flag=arg, value=arg.upper()) - else: - arg_str = '--{flag} {value}'.format(flag=arg, value=arg.upper()) - help_flags.append(arg_str) - help_positional.append(arg_str) - - if spec.varkw: - help_flags.append('[--{kwarg} ...]'.format(kwarg=spec.varkw.upper())) - help_positional.append('[--{kwarg} ...]'.format(kwarg=spec.varkw.upper())) - - commands_flags = command + ' '.join(help_flags) - commands_positional = command + ' '.join(help_positional) - commands = [commands_positional] - - if commands_flags != commands_positional: - commands.append(commands_flags) - - return '\n'.join(commands) + """Get a usage string from the FullArgSpec for the given command. + + The strings look like: + command --arg ARG [--opt OPT] [VAR ...] [--KWARGS ...] + + Args: + command: The command leading up to the function. + spec: a FullArgSpec object describing the function. + Returns: + The usage string for the function. + """ + num_required_args = len(spec.args) - len(spec.defaults) + + help_flags = [] + help_positional = [] + for index, arg in enumerate(spec.args): + flag = arg.replace('_', '-') + if index < num_required_args: + help_flags.append('--{flag} {value}'.format(flag=flag, value=arg.upper())) + help_positional.append('{value}'.format(value=arg.upper())) + else: + help_flags.append('[--{flag} {value}]'.format( + flag=flag, value=arg.upper())) + help_positional.append('[{value}]'.format(value=arg.upper())) + + if spec.varargs: + help_flags.append('[{var} ...]'.format(var=spec.varargs.upper())) + help_positional.append('[{var} ...]'.format(var=spec.varargs.upper())) + + for arg in spec.kwonlyargs: + if arg in spec.kwonlydefaults: + arg_str = '[--{flag} {value}]'.format(flag=arg, value=arg.upper()) + else: + arg_str = '--{flag} {value}'.format(flag=arg, value=arg.upper()) + help_flags.append(arg_str) + help_positional.append(arg_str) + + if spec.varkw: + help_flags.append('[--{kwarg} ...]'.format(kwarg=spec.varkw.upper())) + help_positional.append('[--{kwarg} ...]'.format(kwarg=spec.varkw.upper())) + + commands_flags = command + ' '.join(help_flags) + commands_positional = command + ' '.join(help_positional) + commands = [commands_positional] + + if commands_flags != commands_positional: + commands.append(commands_flags) + + return '\n'.join(commands) def UsageString(component, trace=None, verbose=False): - """Returns a string showing how to use the component as a Fire command.""" - command = trace.GetCommand() + ' ' if trace else '' - - if inspect.isroutine(component) or inspect.isclass(component): - spec = inspectutils.GetFullArgSpec(component) - return _UsageStringFromFullArgSpec(command, spec) - - if isinstance(component, (list, tuple)): - length = len(component) - if length == 0: - return command - if length == 1: - return command + '[0]' - return command + '[0..{cap}]'.format(cap=length - 1) - - completions = completion.Completions(component, verbose) - if command: - completions = [''] + completions - return '\n'.join(command + end for end in completions) + """Returns a string showing how to use the component as a Fire command.""" + command = trace.GetCommand() + ' ' if trace else '' + + if inspect.isroutine(component) or inspect.isclass(component): + spec = inspectutils.GetFullArgSpec(component) + return _UsageStringFromFullArgSpec(command, spec) + + if isinstance(component, (list, tuple)): + length = len(component) + if length == 0: + return command + if length == 1: + return command + '[0]' + return command + '[0..{cap}]'.format(cap=length - 1) + + completions = completion.Completions(component, verbose) + if command: + completions = [''] + completions + return '\n'.join(command + end for end in completions) \ No newline at end of file From a701b6789c2888f232ecaf63b1bb883ace5c10d4 Mon Sep 17 00:00:00 2001 From: atgiovannini Date: Fri, 21 Jul 2017 17:42:06 +0200 Subject: [PATCH 08/10] add newline at EOF --- fire/helputils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fire/helputils.py b/fire/helputils.py index 3a5804c7..5c23de3a 100644 --- a/fire/helputils.py +++ b/fire/helputils.py @@ -197,4 +197,4 @@ def UsageString(component, trace=None, verbose=False): completions = completion.Completions(component, verbose) if command: completions = [''] + completions - return '\n'.join(command + end for end in completions) \ No newline at end of file + return '\n'.join(command + end for end in completions) From 58ebf1871ec0e2a2686b176be4ce14215d8928d0 Mon Sep 17 00:00:00 2001 From: atgiovannini Date: Fri, 28 Jul 2017 10:33:00 +0200 Subject: [PATCH 09/10] Comment on the requested change --- fire/core.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fire/core.py b/fire/core.py index dc07ac8c..e67c7a8b 100644 --- a/fire/core.py +++ b/fire/core.py @@ -254,6 +254,7 @@ def _OneLineResult(result): if isinstance(result, six.string_types): return str(result).replace('\n', ' ') + try: return json.dumps(result, ensure_ascii=False) except (TypeError, ValueError): From 8198c79e1f8d039a7a54fe7286164d75a4ded9e2 Mon Sep 17 00:00:00 2001 From: atgiovannini Date: Fri, 28 Jul 2017 10:34:38 +0200 Subject: [PATCH 10/10] Disable ascii conversion from json.dumps --- fire/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fire/core.py b/fire/core.py index 27dada64..28dd4cb5 100644 --- a/fire/core.py +++ b/fire/core.py @@ -254,9 +254,9 @@ def _OneLineResult(result): if isinstance(result, six.string_types): return str(result).replace('\n', ' ') - try: - return json.dumps(result) + # non-forced to ascii convert + return json.dumps(result, ensure_ascii=False) except (TypeError, ValueError): return str(result).replace('\n', ' ')