more native_str

This commit is contained in:
Matthias Urlichs committed 2019-02-04 13:38:31 +01:00
1 parent e8bee435af
commit 4ebb5cf42d
4 files changed
+24 -19

No files matched your search

+2 -1
View File
@@ -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("-")
+17 -17
View File
@@ -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'
"""
+3
View File
@@ -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")
+2 -1
View File
@@ -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))