naeural-client 2.6.26__py3-none-any.whl → 2.6.28__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.
naeural_client/_ver.py CHANGED
@@ -1,4 +1,4 @@
1
- __VER__ = "2.6.26"
1
+ __VER__ = "2.6.28"
2
2
 
3
3
  if __name__ == "__main__":
4
4
  with open("pyproject.toml", "rt") as fd:
naeural_client/bc/base.py CHANGED
@@ -542,10 +542,63 @@ class BaseBlockEngine:
542
542
  except:
543
543
  result = False
544
544
  return result
545
-
546
545
 
547
- def _load_and_maybe_create_allowed(self):
546
+
547
+ def add_address_to_allowed(self, address : any):
548
+ """
549
+ Adds a new address or a list of addresses to the allowed list
550
+ """
551
+ changed = False
552
+ if isinstance(address, str):
553
+ address = [address]
554
+ #endif
555
+ if isinstance(address, list) and len(address) > 0:
556
+ # self.P(f"Adding addresses to the allowed list:\n{address}", verbosity=1)
557
+ # now check addresses
558
+ lst_addresses = []
559
+ lst_names = []
560
+ for addr in address:
561
+ addr = addr.strip()
562
+ parts = addr.split()
563
+ if len(parts) == 0:
564
+ continue
565
+ addr = parts[0]
566
+ name = parts[1] if len(parts) > 1 else ""
567
+ if not self.address_is_valid(addr):
568
+ self.P("WARNING: address <{}> is not valid. Ignoring.".format(addr), color='r')
569
+ else:
570
+ lst_addresses.append(self.maybe_add_prefix(addr))
571
+ lst_names.append(name)
572
+ #endif
573
+ #endfor
574
+ if len(lst_addresses) > 0:
575
+ existing_addrs, existing_names = self._load_and_maybe_create_allowed(return_names=True)
576
+ existing_addrs = [self.maybe_add_prefix(x) for x in existing_addrs]
577
+ for addr, name in zip(lst_addresses, lst_names):
578
+ if addr not in existing_addrs:
579
+ changed = True
580
+ existing_addrs.append(addr)
581
+ existing_names.append(name)
582
+ self.P("Address <{}{}> added to the allowed list.".format(addr, name), color='g')
583
+ #endif new address
584
+ #endfor
585
+ if changed:
586
+ with self._whitelist_lock:
587
+ fn = self._get_allowed_file()
588
+ with open(fn, 'wt') as fh:
589
+ for addr, name in zip(existing_addrs, existing_names):
590
+ fh.write("{}{}\n".format(addr, (" " + name) if len(name)>0 else ""))
591
+ #endfor each address in modified whitelist
592
+ #endwith open file
593
+ #endwith lock
594
+ #endif changed
595
+ #endif addresses received ok
596
+ return changed
597
+
598
+
599
+ def _load_and_maybe_create_allowed(self, return_names=False, return_prefix=False):
548
600
  lst_final = []
601
+ lst_names = []
549
602
  with self._whitelist_lock:
550
603
  try:
551
604
  fn = self._get_allowed_file()
@@ -563,16 +616,21 @@ class BaseBlockEngine:
563
616
  lst_lines = []
564
617
  errors = False
565
618
  for allowed_tuple in lst_allowed:
566
- allowed = allowed_tuple.split()[0]
619
+ parts = allowed_tuple.split()
620
+ if len(parts) == 0:
621
+ continue
622
+ allowed = parts[0]
567
623
  allowed = self._remove_prefix(allowed)
624
+ name = parts[1] if len(parts) > 1 else ""
568
625
  if not self.address_is_valid(allowed):
569
626
  self.P("WARNING: address <{}> is not valid. Removing {} from allowed list.".format(
570
627
  allowed, allowed_tuple), color='r'
571
628
  )
572
629
  errors = True
573
630
  else:
574
- lst_final.append(allowed)
631
+ lst_final.append(self.maybe_add_prefix(allowed))
575
632
  lst_lines.append(allowed_tuple)
633
+ lst_names.append(name)
576
634
  if errors:
577
635
  with open(fn, 'wt') as fh:
578
636
  for line in lst_lines:
@@ -581,6 +639,8 @@ class BaseBlockEngine:
581
639
  self.P(f"ERROR: failed to load the allowed list of addresses: {exc}", color='r')
582
640
  #endtry
583
641
  #endwith
642
+ if return_names:
643
+ return lst_final, lst_names
584
644
  return lst_final
585
645
 
586
646
 
@@ -754,12 +814,18 @@ class BaseBlockEngine:
754
814
  dct_safe_data = dct_data
755
815
 
756
816
  dumps_config = dict(
757
- sort_keys=True,
758
817
  cls=_ComplexJsonEncoder,
759
818
  separators=(',',':'),
760
819
  ensure_ascii=self.__ensure_ascii_payloads,
761
820
  )
821
+ # we dump the data to a string then we reload and sort as there might
822
+ # be some issues with the sorting if we have int keys that will be sorted
823
+ # then recovered as string keys
762
824
  str_data = json.dumps(dct_safe_data, **dumps_config)
825
+ # we reload the data to ensure
826
+ dct_reload = json.loads(str_data)
827
+ # in order to ensure the data is sorted
828
+ str_data = json.dumps(dct_reload, sort_keys=True)
763
829
  return str_data
764
830
 
765
831
  def _create_new_sk(self):
@@ -900,6 +966,13 @@ class BaseBlockEngine:
900
966
  """Returns the allowed command senders for the current node"""
901
967
  return self.allowed_list
902
968
 
969
+ @property
970
+ def whitelist_with_names(self):
971
+ """
972
+ Returns a tuple with the allowed list (prefixed) and a list with names
973
+ """
974
+ return self._load_and_maybe_create_allowed(return_names=True, return_prefix=True)
975
+
903
976
 
904
977
  def maybe_remove_prefix(self, address):
905
978
  """
@@ -233,21 +233,31 @@ class _JSONSerializationMixin(object):
233
233
  # need to replace directly in the received dict if `inplace=True`
234
234
  if inplace:
235
235
  data = _JSONSerializationMixin.replace_nan(dct, inplace=inplace)
236
- return json.dumps(
236
+
237
+ temp = json.dumps(
237
238
  data,
238
239
  cls=NPJson,
239
- sort_keys=sort_keys,
240
+ sort_keys=False,
240
241
  separators=separators,
241
242
  **kwargs
242
243
  )
243
244
  else:
244
- return json.dumps(
245
+ temp = json.dumps(
245
246
  data,
246
247
  cls=SimpleNPJson,
247
- sort_keys=sort_keys,
248
+ sort_keys=False,
248
249
  separators=separators,
249
250
  **kwargs
250
251
  )
252
+ if sort_keys:
253
+ # we dump the data to a string then we reload and sort as there might
254
+ # be some issues with the sorting if we have int keys that will be sorted
255
+ # then recovered as string keys
256
+ return json.dumps(
257
+ json.loads(temp),
258
+ sort_keys=True, separators=separators, **kwargs
259
+ )
260
+ return temp
251
261
 
252
262
 
253
263
  @staticmethod
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: naeural_client
3
- Version: 2.6.26
3
+ Version: 2.6.28
4
4
  Summary: `naeural_client` is the Python SDK required for client app development for the Naeural Edge Protocol Edge Protocol framework
5
5
  Project-URL: Homepage, https://github.com/NaeuralEdgeProtocol/naeural_client
6
6
  Project-URL: Bug Tracker, https://github.com/NaeuralEdgeProtocol/naeural_client/issues
@@ -1,5 +1,5 @@
1
1
  naeural_client/__init__.py,sha256=YimqgDbjLuywsf8zCWE0EaUXH4MBUrqLxt0TDV558hQ,632
2
- naeural_client/_ver.py,sha256=v41SsIkuU8mwgkOit-MvKm8l1U2wH1sGEPmEk-6Qf6Q,331
2
+ naeural_client/_ver.py,sha256=Pe_mSANiKCh62K3Zslijzk6yhTY6gt-guyu3l-q8a9k,331
3
3
  naeural_client/base_decentra_object.py,sha256=C4iwZTkhKNBS4VHlJs5DfElRYLo4Q9l1V1DNVSk1fyQ,4412
4
4
  naeural_client/plugins_manager_mixin.py,sha256=X1JdGLDz0gN1rPnTN_5mJXR8JmqoBFQISJXmPR9yvCo,11106
5
5
  naeural_client/base/__init__.py,sha256=hACh83_cIv7-PwYMM3bQm2IBmNqiHw-3PAfDfAEKz9A,259
@@ -14,7 +14,7 @@ naeural_client/base/webapp_pipeline.py,sha256=QmPLVmhP0CPdi0YuvbZEH4APYz2Amtw3gy
14
14
  naeural_client/base/payload/__init__.py,sha256=y8fBI8tG2ObNfaXFWjyWZXwu878FRYj_I8GIbHT4GKE,29
15
15
  naeural_client/base/payload/payload.py,sha256=x-au7l67Z_vfn_4R2C_pjZCaFuUVXHngJiGOfIAYVdE,2690
16
16
  naeural_client/bc/__init__.py,sha256=FQj23D1PrY06NUOARiKQi4cdj0-VxnoYgYDEht8lpr8,158
17
- naeural_client/bc/base.py,sha256=NafeKetxDoG86-gNls3FPN1M09nzRUP9unCUzEcXlrk,37706
17
+ naeural_client/bc/base.py,sha256=s90pu8-_YJ4yADnQqbWwGoKouXztrHyH1voQCnFl1to,40507
18
18
  naeural_client/bc/chain.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  naeural_client/bc/ec.py,sha256=qI8l7YqiS4MNftlx-tF7IZUswrSeQc7KMn5OZ0fEaJs,23370
20
20
  naeural_client/certs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -66,7 +66,7 @@ naeural_client/logging/logger_mixins/computer_vision_mixin.py,sha256=TrtG7ayM2ab
66
66
  naeural_client/logging/logger_mixins/datetime_mixin.py,sha256=x0l2mhhmNZ6r_SmJ5or7dxAf2e4tQL0LiBsj3RDu6pU,11288
67
67
  naeural_client/logging/logger_mixins/download_mixin.py,sha256=8eu3w-H1LI6OmC_ZwzU3WrWMENQKdEZ2HjnQsAixwM0,13500
68
68
  naeural_client/logging/logger_mixins/general_serialization_mixin.py,sha256=3glOuN6Whi_GSxb1OiFitzypOqkf_x2RJGfGaO51_WE,7440
69
- naeural_client/logging/logger_mixins/json_serialization_mixin.py,sha256=7usTqigM221C2llVqr-JgtqMX_XYDgjbjAhXnUNXl8M,14594
69
+ naeural_client/logging/logger_mixins/json_serialization_mixin.py,sha256=8TAePgqYgwgpaAk6MRfCOqLqA2GIbO3MPOFYHJdaE0g,14937
70
70
  naeural_client/logging/logger_mixins/pickle_serialization_mixin.py,sha256=9BftwBe56e94FXjyf8c8m4GEvIvzNdK_jpQPtIIJbXY,9185
71
71
  naeural_client/logging/logger_mixins/process_mixin.py,sha256=ZO7S1mvKWwH_UIqv7JG-NxizcfWMJqngNNW_K-hESdU,1904
72
72
  naeural_client/logging/logger_mixins/resource_size_mixin.py,sha256=EdCeFM8Ol8q_OTOmsj5Q2uKPvkqkoNdcXSZjw4FgAh4,2297
@@ -83,8 +83,8 @@ naeural_client/utils/comm_utils.py,sha256=4cS9llRr_pK_3rNgDcRMCQwYPO0kcNU7AdWy_L
83
83
  naeural_client/utils/config.py,sha256=v7xHikr6Z5Sbvf3opYeMhYzGWD2pe0HlRwa-aGJzUh8,6323
84
84
  naeural_client/utils/dotenv.py,sha256=_AgSo35n7EnQv5yDyu7C7i0kHragLJoCGydHjvOkrYY,2008
85
85
  naeural_client/utils/oracle_sync/multiple_requests.py,sha256=GLzROGZ0gI4d1PVWgW_JBUYZjEL4LqZvHvwelxDiPW4,20892
86
- naeural_client-2.6.26.dist-info/METADATA,sha256=jvfB6kdLKoCkEHGyjhFJnTfmrH9Ya8J4fu4Z68ldclE,12354
87
- naeural_client-2.6.26.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
88
- naeural_client-2.6.26.dist-info/entry_points.txt,sha256=PNdyotDaQBAslZREx5luVyj0kqpQnwNACwkFNTPIHU4,55
89
- naeural_client-2.6.26.dist-info/licenses/LICENSE,sha256=cvOsJVslde4oIaTCadabXnPqZmzcBO2f2zwXZRmJEbE,11311
90
- naeural_client-2.6.26.dist-info/RECORD,,
86
+ naeural_client-2.6.28.dist-info/METADATA,sha256=dPMoifaDaW4iB1xJNRItGFCzafNnZ1jUtcOedmgqbfA,12354
87
+ naeural_client-2.6.28.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
88
+ naeural_client-2.6.28.dist-info/entry_points.txt,sha256=PNdyotDaQBAslZREx5luVyj0kqpQnwNACwkFNTPIHU4,55
89
+ naeural_client-2.6.28.dist-info/licenses/LICENSE,sha256=cvOsJVslde4oIaTCadabXnPqZmzcBO2f2zwXZRmJEbE,11311
90
+ naeural_client-2.6.28.dist-info/RECORD,,