funcnodes-basic 0.1.1__py3-none-any.whl → 0.1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- funcnodes_basic/__init__.py +3 -1
- funcnodes_basic/dicts.py +104 -0
- funcnodes_basic/lists.py +4 -4
- funcnodes_basic/strings.py +42 -4
- {funcnodes_basic-0.1.1.dist-info → funcnodes_basic-0.1.3.dist-info}/METADATA +1 -1
- funcnodes_basic-0.1.3.dist-info/RECORD +9 -0
- funcnodes_basic-0.1.1.dist-info/RECORD +0 -8
- {funcnodes_basic-0.1.1.dist-info → funcnodes_basic-0.1.3.dist-info}/WHEEL +0 -0
funcnodes_basic/__init__.py
CHANGED
@@ -3,13 +3,15 @@ from .logic import NODE_SHELF as logic_shelf
|
|
3
3
|
from .math import NODE_SHELF as math_shelf
|
4
4
|
from .lists import NODE_SHELF as lists_shelf
|
5
5
|
from .strings import NODE_SHELF as strings_shelf
|
6
|
+
from .dicts import NODE_SHELF as dicts_shelf
|
6
7
|
|
7
|
-
__version__ = "0.1.
|
8
|
+
__version__ = "0.1.3"
|
8
9
|
|
9
10
|
NODE_SHELF = Shelf(
|
10
11
|
nodes=[],
|
11
12
|
subshelves=[
|
12
13
|
lists_shelf,
|
14
|
+
dicts_shelf,
|
13
15
|
strings_shelf,
|
14
16
|
math_shelf,
|
15
17
|
logic_shelf,
|
funcnodes_basic/dicts.py
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
"""
|
2
|
+
work with python dictionaries
|
3
|
+
"""
|
4
|
+
import funcnodes as fn
|
5
|
+
from typing import Any, List, Tuple
|
6
|
+
|
7
|
+
|
8
|
+
class DictGetNode(fn.Node):
|
9
|
+
node_id = "dict_get"
|
10
|
+
node_name = "Dict Get"
|
11
|
+
dictionary = fn.NodeInput(id="dictionary", type=dict)
|
12
|
+
key = fn.NodeInput(id="key", type=str)
|
13
|
+
value = fn.NodeOutput(id="value", type=Any)
|
14
|
+
|
15
|
+
def __init__(self, *args, **kwargs):
|
16
|
+
super().__init__(*args, **kwargs)
|
17
|
+
self._keymap = {}
|
18
|
+
self.get_input("dictionary").on("after_set_value", self._update_keys)
|
19
|
+
|
20
|
+
def _update_keys(self, **kwargs):
|
21
|
+
try:
|
22
|
+
d = self.get_input("dictionary").value
|
23
|
+
keys = list(d.keys())
|
24
|
+
except KeyError:
|
25
|
+
return
|
26
|
+
keymap = dict({str(i): k for i, k in enumerate(keys)})
|
27
|
+
reversed_keymap = {v: k for k, v in keymap.items()}
|
28
|
+
self.get_input("key").update_value_options(options=reversed_keymap)
|
29
|
+
self._keymap = keymap
|
30
|
+
|
31
|
+
async def func(self, dictionary: dict, key: str) -> None:
|
32
|
+
v = dictionary.get(self._keymap[key], fn.NoValue)
|
33
|
+
self.outputs["value"].value = v
|
34
|
+
return v
|
35
|
+
|
36
|
+
|
37
|
+
@fn.NodeDecorator(
|
38
|
+
id="dict_keys",
|
39
|
+
name="Dict Keys",
|
40
|
+
)
|
41
|
+
def dict_keys(dictionary: dict) -> List[Any]:
|
42
|
+
return list(dictionary.keys())
|
43
|
+
|
44
|
+
|
45
|
+
@fn.NodeDecorator(
|
46
|
+
id="dict_values",
|
47
|
+
name="Dict Values",
|
48
|
+
)
|
49
|
+
def dict_values(dictionary: dict) -> List[Any]:
|
50
|
+
return list(dictionary.values())
|
51
|
+
|
52
|
+
|
53
|
+
@fn.NodeDecorator(
|
54
|
+
id="dict_items",
|
55
|
+
name="Dict Items",
|
56
|
+
)
|
57
|
+
def dict_items(dictionary: dict) -> List[tuple]:
|
58
|
+
return list(dictionary.items())
|
59
|
+
|
60
|
+
|
61
|
+
@fn.NodeDecorator(
|
62
|
+
id="dict_from_items",
|
63
|
+
name="Dict From Items",
|
64
|
+
)
|
65
|
+
def dict_from_items(items: List[tuple]) -> dict:
|
66
|
+
return dict(items)
|
67
|
+
|
68
|
+
|
69
|
+
@fn.NodeDecorator(
|
70
|
+
id="dict_from_keys_values",
|
71
|
+
name="Dict From Keys Values",
|
72
|
+
)
|
73
|
+
def dict_from_keys_values(keys: List[Any], values: List[Any]) -> dict:
|
74
|
+
return dict(zip(keys, values))
|
75
|
+
|
76
|
+
|
77
|
+
@fn.NodeDecorator(
|
78
|
+
id="dict_to_lists",
|
79
|
+
name="Dict to List",
|
80
|
+
outputs=[
|
81
|
+
{"name": "keys"},
|
82
|
+
{
|
83
|
+
"name": "values",
|
84
|
+
},
|
85
|
+
],
|
86
|
+
)
|
87
|
+
def dict_to_list(dictionary: dict) -> Tuple[List[Any], List[Any]]:
|
88
|
+
return list(dictionary.items())
|
89
|
+
|
90
|
+
|
91
|
+
NODE_SHELF = fn.Shelf(
|
92
|
+
nodes=[
|
93
|
+
DictGetNode,
|
94
|
+
dict_keys,
|
95
|
+
dict_values,
|
96
|
+
dict_items,
|
97
|
+
dict_from_items,
|
98
|
+
dict_from_keys_values,
|
99
|
+
dict_to_list,
|
100
|
+
],
|
101
|
+
name="Dicts",
|
102
|
+
description="Work with dictionaries",
|
103
|
+
subshelves=[],
|
104
|
+
)
|
funcnodes_basic/lists.py
CHANGED
@@ -32,8 +32,8 @@ class GetIndexNode(fn.Node):
|
|
32
32
|
uuid="element",
|
33
33
|
)
|
34
34
|
|
35
|
-
def __init__(self):
|
36
|
-
super().__init__()
|
35
|
+
def __init__(self, *args, **kwargs):
|
36
|
+
super().__init__(*args, **kwargs)
|
37
37
|
self.get_input("inputlist").on("after_set_value", self._update_indices)
|
38
38
|
|
39
39
|
def _update_indices(self, **kwargs):
|
@@ -61,6 +61,6 @@ class GetIndexNode(fn.Node):
|
|
61
61
|
NODE_SHELF = fn.Shelf(
|
62
62
|
nodes=[contains, GetIndexNode],
|
63
63
|
subshelves=[],
|
64
|
-
name="
|
65
|
-
description="
|
64
|
+
name="Lists",
|
65
|
+
description="List operations",
|
66
66
|
)
|
funcnodes_basic/strings.py
CHANGED
@@ -549,8 +549,19 @@ def string_isascii(s: str) -> bool:
|
|
549
549
|
{"name": "encoded"},
|
550
550
|
],
|
551
551
|
)
|
552
|
-
def string_encode(
|
553
|
-
|
552
|
+
def string_encode(
|
553
|
+
s: str,
|
554
|
+
encoding: POSSIBLE_DECODINGS_TYPE = "utf-8",
|
555
|
+
errors: Literal[
|
556
|
+
"strict",
|
557
|
+
"replace",
|
558
|
+
"ignore",
|
559
|
+
"xmlcharrefreplace",
|
560
|
+
"backslashreplace",
|
561
|
+
"namereplace",
|
562
|
+
] = "replace",
|
563
|
+
) -> bytes:
|
564
|
+
return s.encode(encoding, errors)
|
554
565
|
|
555
566
|
|
556
567
|
@fn.NodeDecorator(
|
@@ -561,8 +572,19 @@ def string_encode(s: str, encoding: POSSIBLE_DECODINGS_TYPE = "utf-8") -> bytes:
|
|
561
572
|
{"name": "decoded"},
|
562
573
|
],
|
563
574
|
)
|
564
|
-
def string_decode(
|
565
|
-
|
575
|
+
def string_decode(
|
576
|
+
b: bytes,
|
577
|
+
encoding: POSSIBLE_DECODINGS_TYPE = "utf_8",
|
578
|
+
errors: Literal[
|
579
|
+
"strict",
|
580
|
+
"replace",
|
581
|
+
"ignore",
|
582
|
+
"xmlcharrefreplace",
|
583
|
+
"backslashreplace",
|
584
|
+
"namereplace",
|
585
|
+
] = "replace",
|
586
|
+
) -> str:
|
587
|
+
return b.decode(encoding, errors)
|
566
588
|
|
567
589
|
|
568
590
|
@fn.NodeDecorator(
|
@@ -696,12 +718,27 @@ regex_shelf = fn.Shelf(
|
|
696
718
|
description="Basic regular expression operations.",
|
697
719
|
)
|
698
720
|
|
721
|
+
|
722
|
+
@fn.NodeDecorator(
|
723
|
+
node_id="string.input",
|
724
|
+
node_name="Input",
|
725
|
+
description="Input a string",
|
726
|
+
outputs=[
|
727
|
+
{"name": "string"},
|
728
|
+
],
|
729
|
+
)
|
730
|
+
def string_input(s: str) -> str:
|
731
|
+
return s
|
732
|
+
|
733
|
+
|
699
734
|
NODE_SHELF = fn.Shelf(
|
700
735
|
nodes=[
|
701
736
|
string_length,
|
702
737
|
string_concat,
|
703
738
|
string_split,
|
704
739
|
string_join,
|
740
|
+
string_encode,
|
741
|
+
string_decode,
|
705
742
|
string_upper,
|
706
743
|
string_lower,
|
707
744
|
string_replace,
|
@@ -734,6 +771,7 @@ NODE_SHELF = fn.Shelf(
|
|
734
771
|
string_isdecimal,
|
735
772
|
string_isnumeric,
|
736
773
|
string_isascii,
|
774
|
+
string_input,
|
737
775
|
],
|
738
776
|
subshelves=[regex_shelf],
|
739
777
|
name="Strings",
|
@@ -0,0 +1,9 @@
|
|
1
|
+
funcnodes_basic/__init__.py,sha256=1xIYBA0_AUVoTwmatlvpKqFvaNxz9LUQskpim310_gc,505
|
2
|
+
funcnodes_basic/dicts.py,sha256=7wHKDH6Mr1nfWrX3Bd9oP6V20Tl1dHOx_ze5FKiSymA,2457
|
3
|
+
funcnodes_basic/lists.py,sha256=cDBaXY_I2D1-CHbIA4_7OV2Dn2zk47c20hCAQHhPoO4,1561
|
4
|
+
funcnodes_basic/logic.py,sha256=X1gHjQzhGYYFJwV0Y-L0Cty3CD-w6UWbcax72JWmGoM,3577
|
5
|
+
funcnodes_basic/math.py,sha256=9kYKXCH1f8lXvuxiUJnTORUp29rYrjmi24Di71toiDE,11280
|
6
|
+
funcnodes_basic/strings.py,sha256=BbLuq6m96Sia02UEmi-aUi5L5bebGbcgwvpTnGFVD2E,16429
|
7
|
+
funcnodes_basic-0.1.3.dist-info/METADATA,sha256=yqZaUnqYInVWQI18u87NQnWkisT2SlObvJZmC_eMjv0,432
|
8
|
+
funcnodes_basic-0.1.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
9
|
+
funcnodes_basic-0.1.3.dist-info/RECORD,,
|
@@ -1,8 +0,0 @@
|
|
1
|
-
funcnodes_basic/__init__.py,sha256=XWfNAxnVXLrY1GF3L7CbQsbBCZ8CU5Re_FhMJmAIUkY,439
|
2
|
-
funcnodes_basic/lists.py,sha256=e0ym5OVZAPRm05gMKxullRspql0oIaHEh4RxXCUsVbE,1553
|
3
|
-
funcnodes_basic/logic.py,sha256=X1gHjQzhGYYFJwV0Y-L0Cty3CD-w6UWbcax72JWmGoM,3577
|
4
|
-
funcnodes_basic/math.py,sha256=9kYKXCH1f8lXvuxiUJnTORUp29rYrjmi24Di71toiDE,11280
|
5
|
-
funcnodes_basic/strings.py,sha256=q-4eP1FU7gtp2bploDB4vo9VBtfu67MZ6-KJDS8myB0,15769
|
6
|
-
funcnodes_basic-0.1.1.dist-info/METADATA,sha256=WcniYk0CFeT3gg8KWK1ByXB94BNmhTem9cC-6toSogQ,432
|
7
|
-
funcnodes_basic-0.1.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
8
|
-
funcnodes_basic-0.1.1.dist-info/RECORD,,
|
File without changes
|