funcnodes-basic 0.1.2__py3-none-any.whl → 0.1.4__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.
@@ -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.2"
8
+ __version__ = "0.1.4"
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,
@@ -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="Logic",
65
- description="Control flow and decision making nodes.",
64
+ name="Lists",
65
+ description="List operations",
66
66
  )
funcnodes_basic/logic.py CHANGED
@@ -32,8 +32,10 @@ class WhileNode(Node):
32
32
  done = NodeOutput(id="done", type=Any)
33
33
 
34
34
  async def func(self, condition: bool, input: Any) -> None:
35
- if condition:
35
+ if self.inputs["condition"].value:
36
36
  self.outputs["do"].value = input
37
+ triggerstack = TriggerStack()
38
+ await self.outputs["do"].trigger(triggerstack)
37
39
  self.request_trigger()
38
40
  else:
39
41
  self.outputs["done"].value = input
@@ -69,14 +71,11 @@ class ForNode(Node):
69
71
 
70
72
  async def func(self, input: list, collector: Optional[Any] = None) -> None:
71
73
  results = []
74
+ self.outputs["done"].value = NoValue
72
75
  for i in input:
73
76
  self.outputs["do"].set_value(i, does_trigger=False)
74
77
  triggerstack = TriggerStack()
75
- try:
76
- await self.outputs["do"].trigger(triggerstack)
77
- await triggerstack
78
- except Exception as e:
79
- pass
78
+ await self.outputs["do"].trigger(triggerstack)
80
79
  v = self.inputs["collector"].value
81
80
  if v is not NoValue:
82
81
  results.append(v)
@@ -574,7 +574,7 @@ def string_encode(
574
574
  )
575
575
  def string_decode(
576
576
  b: bytes,
577
- encoding: POSSIBLE_DECODINGS_TYPE = "utf-8",
577
+ encoding: POSSIBLE_DECODINGS_TYPE = "utf_8",
578
578
  errors: Literal[
579
579
  "strict",
580
580
  "replace",
@@ -718,6 +718,19 @@ regex_shelf = fn.Shelf(
718
718
  description="Basic regular expression operations.",
719
719
  )
720
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
+
721
734
  NODE_SHELF = fn.Shelf(
722
735
  nodes=[
723
736
  string_length,
@@ -758,6 +771,7 @@ NODE_SHELF = fn.Shelf(
758
771
  string_isdecimal,
759
772
  string_isnumeric,
760
773
  string_isascii,
774
+ string_input,
761
775
  ],
762
776
  subshelves=[regex_shelf],
763
777
  name="Strings",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: funcnodes-basic
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: Basic functionalities for funcnodes
5
5
  Author: Julian Kimmig
6
6
  Author-email: julian.kimmig@gmx.net
@@ -0,0 +1,9 @@
1
+ funcnodes_basic/__init__.py,sha256=zsbdWOv6CgaIcOLBH3YtUMnRtYtU6VNw1zrfaNvOrv8,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=zxkFdqgDtWKxnQPPqpguqT0-Dw2MGq4tJEa2roqVUnw,3631
5
+ funcnodes_basic/math.py,sha256=9kYKXCH1f8lXvuxiUJnTORUp29rYrjmi24Di71toiDE,11280
6
+ funcnodes_basic/strings.py,sha256=BbLuq6m96Sia02UEmi-aUi5L5bebGbcgwvpTnGFVD2E,16429
7
+ funcnodes_basic-0.1.4.dist-info/METADATA,sha256=VmPcsdcr4uqmAw-XrTaD94r1zNhS2FJgi37iOJtxiSc,432
8
+ funcnodes_basic-0.1.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
9
+ funcnodes_basic-0.1.4.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- funcnodes_basic/__init__.py,sha256=tNR7s8n_tDNUPe41kUK4F0bZ1XSyN7T1CU2GHPt8C8c,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=t89-YUgptDb06DZq9UiOcfCWpOWbfWVbYNwXlalD_y4,16203
6
- funcnodes_basic-0.1.2.dist-info/METADATA,sha256=WxUte40KpVbJPi4h7pUT8jPRqZu4LO8nHtJeW2ZdbSg,432
7
- funcnodes_basic-0.1.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
8
- funcnodes_basic-0.1.2.dist-info/RECORD,,