Add STRING escape and unescape nodes.
Fix test cases for containers and add those for the new string nodes
This commit is contained in:
@@ -811,7 +811,6 @@ class DataListSlice(ComfyNodeABC):
|
||||
start = kwargs.get('start', [0])[0]
|
||||
stop = kwargs.get('stop', [INT_MAX])[0]
|
||||
step = kwargs.get('step', [1])[0]
|
||||
print(f"start: {start}, stop: {stop}, step: {step}; input_list: {input_list}")
|
||||
|
||||
return (input_list[start:stop:step],)
|
||||
|
||||
|
||||
@@ -91,8 +91,8 @@ class ListCreateFromFloat(ComfyNodeABC):
|
||||
FUNCTION = "create_list"
|
||||
|
||||
def create_list(self, **kwargs: list[Any]) -> tuple[list[Any]]:
|
||||
values = [float(value) for value in kwargs.values()]
|
||||
return (values[:-1],)
|
||||
values = [float(value) for value in list(kwargs.values())[:-1]]
|
||||
return (values,)
|
||||
|
||||
|
||||
class ListCreateFromInt(ComfyNodeABC):
|
||||
@@ -117,8 +117,8 @@ class ListCreateFromInt(ComfyNodeABC):
|
||||
FUNCTION = "create_list"
|
||||
|
||||
def create_list(self, **kwargs: list[Any]) -> tuple[list[Any]]:
|
||||
values = [int(value) for value in kwargs.values()]
|
||||
return (values[:-1],)
|
||||
values = [int(value) for value in list(kwargs.values())[:-1]]
|
||||
return (values,)
|
||||
|
||||
|
||||
class ListCreateFromString(ComfyNodeABC):
|
||||
@@ -143,8 +143,8 @@ class ListCreateFromString(ComfyNodeABC):
|
||||
FUNCTION = "create_list"
|
||||
|
||||
def create_list(self, **kwargs: list[Any]) -> tuple[list[Any]]:
|
||||
values = [str(value) for value in kwargs.values()]
|
||||
return (values[:-1],)
|
||||
values = [str(value) for value in list(kwargs.values())[:-1]]
|
||||
return (values,)
|
||||
|
||||
|
||||
class ListAppend(ComfyNodeABC):
|
||||
|
||||
@@ -37,8 +37,8 @@ class SetCreate(ComfyNodeABC):
|
||||
FUNCTION = "create_set"
|
||||
|
||||
def create_set(self, **kwargs: list[Any]) -> tuple[set[Any]]:
|
||||
values = kwargs.values()
|
||||
return (set(values[:-1]),)
|
||||
values = list(kwargs.values())[:-1]
|
||||
return (set(values),)
|
||||
|
||||
|
||||
class SetCreateFromBoolean(ComfyNodeABC):
|
||||
@@ -63,8 +63,8 @@ class SetCreateFromBoolean(ComfyNodeABC):
|
||||
FUNCTION = "create_set"
|
||||
|
||||
def create_set(self, **kwargs: list[Any]) -> tuple[set[Any]]:
|
||||
values = [bool(value) for value in kwargs.values()]
|
||||
return (set(values[:-1]),)
|
||||
values = [bool(value) for value in list(kwargs.values())[:-1]]
|
||||
return (set(values),)
|
||||
|
||||
|
||||
class SetCreateFromFloat(ComfyNodeABC):
|
||||
@@ -89,8 +89,8 @@ class SetCreateFromFloat(ComfyNodeABC):
|
||||
FUNCTION = "create_set"
|
||||
|
||||
def create_set(self, **kwargs: list[Any]) -> tuple[set[Any]]:
|
||||
values = [float(value) for value in kwargs.values()]
|
||||
return (set(values[:-1]),)
|
||||
values = [float(value) for value in list(kwargs.values())[:-1]]
|
||||
return (set(values),)
|
||||
|
||||
|
||||
class SetCreateFromInt(ComfyNodeABC):
|
||||
@@ -115,8 +115,8 @@ class SetCreateFromInt(ComfyNodeABC):
|
||||
FUNCTION = "create_set"
|
||||
|
||||
def create_set(self, **kwargs: list[Any]) -> tuple[set[Any]]:
|
||||
values = [int(value) for value in kwargs.values()]
|
||||
return (set(values[:-1]),)
|
||||
values = [int(value) for value in list(kwargs.values())[:-1]]
|
||||
return (set(values),)
|
||||
|
||||
|
||||
class SetCreateFromString(ComfyNodeABC):
|
||||
@@ -141,8 +141,8 @@ class SetCreateFromString(ComfyNodeABC):
|
||||
FUNCTION = "create_set"
|
||||
|
||||
def create_set(self, **kwargs: list[Any]) -> tuple[set[Any]]:
|
||||
values = [str(value) for value in kwargs.values()]
|
||||
return (set(values[:-1]),)
|
||||
values = [str(value) for value in list(kwargs.values())[:-1]]
|
||||
return (set(values),)
|
||||
|
||||
|
||||
class SetAdd(ComfyNodeABC):
|
||||
|
||||
@@ -890,6 +890,74 @@ class StringRemovesuffix(ComfyNodeABC):
|
||||
return (string.removesuffix(suffix),)
|
||||
|
||||
|
||||
class StringUnescape(ComfyNodeABC):
|
||||
"""
|
||||
Unescapes a string by converting escape sequences to their actual characters.
|
||||
|
||||
This node converts escape sequences like '\n' (two characters) to actual newlines (one character),
|
||||
'\t' to tabs, '\\' to backslashes, etc. Useful for processing strings where escape sequences
|
||||
are represented literally rather than interpreted.
|
||||
"""
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"string": (IO.STRING, {"default": ""}),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = (IO.STRING,)
|
||||
CATEGORY = "Basic/STRING"
|
||||
DESCRIPTION = cleandoc(__doc__ or "")
|
||||
FUNCTION = "unescape"
|
||||
|
||||
def unescape(self, string):
|
||||
# Decode escaped sequences only for control characters
|
||||
result = (
|
||||
string
|
||||
.replace(r'\\', '\u0000')
|
||||
.replace(r'\n', '\n')
|
||||
.replace(r'\t', '\t')
|
||||
.replace(r'\"', '"')
|
||||
.replace(r'\'', "'")
|
||||
.replace('\u0000', '\\')
|
||||
)
|
||||
return (result,)
|
||||
|
||||
|
||||
class StringEscape(ComfyNodeABC):
|
||||
"""
|
||||
Escapes a string by converting special characters to escape sequences.
|
||||
|
||||
This node converts characters like newlines, tabs, quotes, and backslashes to their escaped
|
||||
representation (like '\n', '\t', '\"', '\\'). Useful when you need to prepare strings
|
||||
for formats that require escaped sequences instead of literal special characters.
|
||||
"""
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"string": (IO.STRING, {"default": ""}),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = (IO.STRING,)
|
||||
CATEGORY = "Basic/STRING"
|
||||
DESCRIPTION = cleandoc(__doc__ or "")
|
||||
FUNCTION = "escape"
|
||||
|
||||
def escape(self, string):
|
||||
result = (
|
||||
string
|
||||
.replace('\\', r'\\')
|
||||
.replace('\n', r'\n')
|
||||
.replace('\t', r'\t')
|
||||
.replace('"', r'\"')
|
||||
.replace("'", r"\'")
|
||||
)
|
||||
return (result,)
|
||||
|
||||
|
||||
class StringReplace(ComfyNodeABC):
|
||||
"""
|
||||
Replaces occurrences of a substring with another substring.
|
||||
@@ -1384,6 +1452,7 @@ NODE_CLASS_MAPPINGS = {
|
||||
"Basic data handling: StringDecode": StringDecode,
|
||||
"Basic data handling: StringEncode": StringEncode,
|
||||
"Basic data handling: StringEndswith": StringEndswith,
|
||||
"Basic data handling: StringEscape": StringEscape,
|
||||
"Basic data handling: StringExpandtabs": StringExpandtabs,
|
||||
"Basic data handling: StringFind": StringFind,
|
||||
"Basic data handling: StringFormatMap": StringFormatMap,
|
||||
@@ -1422,6 +1491,7 @@ NODE_CLASS_MAPPINGS = {
|
||||
"Basic data handling: StringStrip": StringStrip,
|
||||
"Basic data handling: StringSwapcase": StringSwapcase,
|
||||
"Basic data handling: StringTitle": StringTitle,
|
||||
"Basic data handling: StringUnescape": StringUnescape,
|
||||
"Basic data handling: StringUpper": StringUpper,
|
||||
"Basic data handling: StringZfill": StringZfill,
|
||||
}
|
||||
@@ -1435,6 +1505,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"Basic data handling: StringDecode": "decode",
|
||||
"Basic data handling: StringEncode": "encode",
|
||||
"Basic data handling: StringEndswith": "endswith",
|
||||
"Basic data handling: StringEscape": "escape",
|
||||
"Basic data handling: StringExpandtabs": "expandtabs",
|
||||
"Basic data handling: StringFind": "find",
|
||||
"Basic data handling: StringFormatMap": "format_map",
|
||||
@@ -1473,6 +1544,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"Basic data handling: StringStrip": "strip",
|
||||
"Basic data handling: StringSwapcase": "swapcase",
|
||||
"Basic data handling: StringTitle": "title",
|
||||
"Basic data handling: StringUnescape": "unescape",
|
||||
"Basic data handling: StringUpper": "upper",
|
||||
"Basic data handling: StringZfill": "zfill",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user