diff --git a/src/octoprint/timelapse.py b/src/octoprint/timelapse.py index 158ac9de2..da9be2ef7 100644 --- a/src/octoprint/timelapse.py +++ b/src/octoprint/timelapse.py @@ -97,9 +97,10 @@ def valid_timelapse(path): def _extract_prefix(filename): """ + >>> from octoprint.util import to_native_str >>> _extract_prefix("some_long_filename_without_hyphen.jpg") >>> _extract_prefix("-first_char_is_hyphen.jpg") - >>> _extract_prefix("some_long_filename_with-stuff.jpg") + >>> to_native_str(_extract_prefix("some_long_filename_with-stuff.jpg")) 'some_long_filename_with' """ pos = filename.rfind("-") diff --git a/src/octoprint/util/__init__.py b/src/octoprint/util/__init__.py index b70b410cb..50222c779 100644 --- a/src/octoprint/util/__init__.py +++ b/src/octoprint/util/__init__.py @@ -329,20 +329,20 @@ def get_dos_filename(input, existing_filenames=None, extension=None, whitelisted Examples: - >>> get_dos_filename("test1234.gco") + >>> to_native_str(get_dos_filename("test1234.gco")) 'test1234.gco' - >>> get_dos_filename("test1234.gcode") + >>> to_native_str(get_dos_filename("test1234.gcode")) 'test1234.gco' - >>> get_dos_filename("test12345.gco") + >>> to_native_str(get_dos_filename("test12345.gco")) 'test12~1.gco' - >>> get_dos_filename("test1234.fnord", extension="gco") + >>> to_native_str(get_dos_filename("test1234.fnord", extension="gco")) 'test1234.gco' - >>> get_dos_filename("auto0.g", extension="gco") + >>> to_native_str(get_dos_filename("auto0.g", extension="gco")) 'auto0.gco' - >>> get_dos_filename("auto0.g", extension="gco", whitelisted_extensions=["g"]) + >>> to_native_str(get_dos_filename("auto0.g", extension="gco", whitelisted_extensions=["g"])) 'auto0.g' >>> get_dos_filename(None) - >>> get_dos_filename("foo") + >>> to_native_str(get_dos_filename("foo")) 'foo' """ @@ -414,30 +414,30 @@ def find_collision_free_name(filename, extension, existing_filenames, max_power= Examples: - >>> find_collision_free_name("test1234", "gco", []) + >>> to_native_str(find_collision_free_name("test1234", "gco", [])) 'test1234.gco' - >>> find_collision_free_name("test1234", "gcode", []) + >>> to_native_str(find_collision_free_name("test1234", "gcode", [])) 'test1234.gco' - >>> find_collision_free_name("test12345", "gco", []) + >>> to_native_str(find_collision_free_name("test12345", "gco", [])) 'test12~1.gco' - >>> find_collision_free_name("test 123", "gco", []) + >>> to_native_str(find_collision_free_name("test 123", "gco", [])) 'test_123.gco' - >>> find_collision_free_name("test1234", "g o", []) + >>> to_native_str(find_collision_free_name("test1234", "g o", [])) 'test1234.g_o' - >>> find_collision_free_name("test12345", "gco", ["/test12~1.gco"]) + >>> to_native_str(find_collision_free_name("test12345", "gco", ["/test12~1.gco"])) 'test12~2.gco' >>> many_files = ["/test12~{}.gco".format(x) for x in range(10)[1:]] - >>> find_collision_free_name("test12345", "gco", many_files) + >>> to_native_str(find_collision_free_name("test12345", "gco", many_files)) 'test1~10.gco' >>> many_more_files = many_files + ["/test1~{}.gco".format(x) for x in range(10, 99)] - >>> find_collision_free_name("test12345", "gco", many_more_files) + >>> to_native_str(find_collision_free_name("test12345", "gco", many_more_files)) 'test1~99.gco' >>> many_more_files_plus_one = many_more_files + ["/test1~99.gco"] - >>> find_collision_free_name("test12345", "gco", many_more_files_plus_one) + >>> to_native_str(find_collision_free_name("test12345", "gco", many_more_files_plus_one)) Traceback (most recent call last): ... ValueError: Can't create a collision free filename - >>> find_collision_free_name("test12345", "gco", many_more_files_plus_one, max_power=3) + >>> to_native_str(find_collision_free_name("test12345", "gco", many_more_files_plus_one, max_power=3)) 'test~100.gco' """ diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 137fe8c87..05730d4ca 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -4584,6 +4584,9 @@ def _normalize_command_handler_result(command, command_type, gcode, subcode, tag be empty in which case the command is to be suppressed. Examples: + >>> from octoprint.util import to_native_str + >>> uu = lambda x: tuple(to_native_str(y) if y is not None else None for y in x) + >>> u = lambda x: list(uu(y) for y in x) >>> _normalize_command_handler_result("M105", None, "M105", None, None, None) [('M105', None, 'M105', None, None)] >>> _normalize_command_handler_result("M105", None, "M105", None, None, "M110") diff --git a/src/octoprint/util/pip.py b/src/octoprint/util/pip.py index 43e4f5d55..19af2fd85 100644 --- a/src/octoprint/util/pip.py +++ b/src/octoprint/util/pip.py @@ -426,8 +426,9 @@ class PipCaller(CommandlineCaller): Example:: + >>> from octoprint.util import to_native_str >>> text = b'some text with some\x1b[?25h ANSI codes for \x1b[31mred words\x1b[39m and\x1b[?25l also some cursor control codes' - >>> PipCaller._preprocess(text) + >>> to_native_str(PipCaller._preprocess(text)) 'some text with some ANSI codes for red words and also some cursor control codes' """ return to_unicode(clean_ansi(text))