ratio1 3.4.45__py3-none-any.whl → 3.4.47__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.
ratio1/_ver.py CHANGED
@@ -1,4 +1,4 @@
1
- __VER__ = "3.4.45"
1
+ __VER__ = "3.4.47"
2
2
 
3
3
  if __name__ == "__main__":
4
4
  with open("pyproject.toml", "rt") as fd:
@@ -23,7 +23,7 @@ class WebappPipeline(Pipeline):
23
23
  ) -> None:
24
24
  """
25
25
  This is a special type of pipeline that is used to deploy webapps.
26
- It will override the deploy method to return the ngrok URL as well as the on_data method to extract the ngrok URL.
26
+ It will override the deploy method to return the app URL as well as the on_data method to extract the app URL.
27
27
  """
28
28
  self.app_url = None
29
29
  self.__extra_debug = extra_debug
@@ -47,7 +47,7 @@ class WebappPipeline(Pipeline):
47
47
 
48
48
  def __check_payloads(self, session, plugin_signature, plugin_instance, data):
49
49
  """
50
- Check if the payload if from ngrok and extract the ngrok URL.
50
+ Check if the payload is from webapp and extract the app URL.
51
51
 
52
52
  Parameters
53
53
  ----------
@@ -127,13 +127,13 @@ class WebappPipeline(Pipeline):
127
127
  The URL of the webapp.
128
128
  """
129
129
  res = super().deploy(verbose=verbose, timeout=timeout, **kwargs)
130
- # now we wait for the ngrok url to be available
130
+ # now we wait for the app url to be available
131
131
  start = time.time()
132
132
  while self.app_url is None:
133
133
  elapsed = time.time() - start
134
134
  if elapsed > timeout:
135
- msg = "Timeout waiting for ngrok url"
135
+ msg = "Timeout waiting for app url"
136
136
  self.P(msg, color="red")
137
137
  raise Exception(msg)
138
- # return the ngrok url
138
+ # return the app url
139
139
  return self.app_url
ratio1/ipfs/r1fs.py CHANGED
@@ -300,6 +300,7 @@ class R1FSEngine:
300
300
  return
301
301
 
302
302
  def _hash_secret(self, secret: str) -> bytes:
303
+ secret = str(secret) # to be sure that the passed secret is of string type.
303
304
  # Convert text to bytes, then hash with SHA-256 => 32-byte key
304
305
  return hashlib.sha256(secret.encode("utf-8")).digest()
305
306
 
@@ -510,6 +511,25 @@ class R1FSEngine:
510
511
  )
511
512
  return result
512
513
 
514
+ # PUBLIC COMMAND
515
+ def get_ipfs_id_data(self) -> dict:
516
+ """
517
+ Get the IPFS peer ID via 'ipfs id' (JSON output).
518
+ Returns the ipfs ID object.
519
+ """
520
+ data = {}
521
+ output = self.__run_command(["ipfs", "id"]) # this will raise an exception if the command fails
522
+ try:
523
+ data = json.loads(output)
524
+ except json.JSONDecodeError:
525
+ raise Exception("Failed to parse JSON from 'ipfs id' output.")
526
+ except Exception as e:
527
+ msg = f"Error getting IPFS ID: {e}. `ipfs id`:\n{data}"
528
+ self.P(msg, color='r')
529
+ raise Exception(f"Error getting IPFS ID: {e}") from e
530
+ return data
531
+
532
+ # END PUBLIC COMMANS
513
533
 
514
534
  def __run_command(
515
535
  self,
@@ -575,24 +595,15 @@ class R1FSEngine:
575
595
  Get the IPFS peer ID via 'ipfs id' (JSON output).
576
596
  Returns the 'ID' field as a string.
577
597
  """
578
- self.__ipfs_address = None
579
- output = self.__run_command(["ipfs", "id"]) # this will raise an exception if the command fails
580
- try:
581
- data = json.loads(output)
582
- self.__ipfs_id_result = data
583
- self.__ipfs_id = data.get("ID", ERROR_TAG)
584
- self.__ipfs_agent = data.get("AgentVersion", ERROR_TAG)
585
- addrs = data.get("Addresses", [])
586
- if not addrs:
587
- self.__ipfs_address = None
588
- else:
589
- self.__ipfs_address = addrs[1] if len(addrs) > 1 else addrs[0] if len(addrs) else ERROR_TAG
590
- except json.JSONDecodeError:
591
- raise Exception("Failed to parse JSON from 'ipfs id' output.")
592
- except Exception as e:
593
- msg = f"Error getting IPFS ID: {e}. `ipfs id`:\n{data}"
594
- self.P(msg, color='r')
595
- raise Exception(f"Error getting IPFS ID: {e}") from e
598
+ data = self.get_ipfs_id_data()
599
+ self.__ipfs_id_result = data
600
+ self.__ipfs_id = data.get("ID", ERROR_TAG)
601
+ self.__ipfs_agent = data.get("AgentVersion", ERROR_TAG)
602
+ addrs = data.get("Addresses", [])
603
+ if not addrs:
604
+ self.__ipfs_address = None
605
+ else:
606
+ self.__ipfs_address = addrs[1] if len(addrs) > 1 else addrs[0] if len(addrs) else ERROR_TAG
596
607
  return self.__ipfs_id
597
608
 
598
609
 
@@ -657,7 +668,7 @@ class R1FSEngine:
657
668
  tempfile=False,
658
669
  show_logs=True,
659
670
  raise_on_error=False,
660
- ) -> bool:
671
+ ) -> str:
661
672
  """
662
673
  Add a YAML object to IPFS.
663
674
  """
@@ -884,7 +895,8 @@ class R1FSEngine:
884
895
  timeout: int = None,
885
896
  pin: bool = True,
886
897
  raise_on_error: bool = False,
887
- show_logs: bool = True
898
+ show_logs: bool = True,
899
+ return_absolute_path: bool = True,
888
900
  ) -> str:
889
901
  """
890
902
  Retrieve an encrypted file from R1FS by CID, decrypt with AES-GCM in streaming mode.
@@ -916,6 +928,9 @@ class R1FSEngine:
916
928
  show_logs : bool, optional
917
929
  If True, logs steps via self.P / self.Pd. Default True.
918
930
 
931
+ return_absolute_path : bool, optional
932
+ If True, return the absolute path to the restored plaintext file.
933
+
919
934
  Returns
920
935
  -------
921
936
  str
@@ -1041,6 +1056,8 @@ class R1FSEngine:
1041
1056
  fin.seek(data_start, os.SEEK_SET)
1042
1057
 
1043
1058
  out_path = os.path.join(local_folder, original_filename)
1059
+ if return_absolute_path:
1060
+ out_path = os.path.abspath(out_path)
1044
1061
  chunk_size = 1024 * 1024
1045
1062
 
1046
1063
  with open(out_path, "wb") as fout:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ratio1
3
- Version: 3.4.45
3
+ Version: 3.4.47
4
4
  Summary: `ratio1` or Ration1 SDK is the Python SDK required for client app development for the Ratio1 ecosystem
5
5
  Project-URL: Homepage, https://github.com/Ratio1/ratio1_sdk
6
6
  Project-URL: Bug Tracker, https://github.com/Ratio1/ratio1_sdk/issues
@@ -1,5 +1,5 @@
1
1
  ratio1/__init__.py,sha256=YimqgDbjLuywsf8zCWE0EaUXH4MBUrqLxt0TDV558hQ,632
2
- ratio1/_ver.py,sha256=DyYAVKy3hLVQtMWbQSTyJLGNsx7pQ8Majk60ovEC-iU,331
2
+ ratio1/_ver.py,sha256=HoUSVwQY9A6o3Hp0Q1yUiWkM4nWr5iqZdpQu0pv2f-o,331
3
3
  ratio1/base_decentra_object.py,sha256=iXvAAf6wPnGWzeeiRfwLojVoan-m1e_VsyPzjUQuENo,4492
4
4
  ratio1/plugins_manager_mixin.py,sha256=X1JdGLDz0gN1rPnTN_5mJXR8JmqoBFQISJXmPR9yvCo,11106
5
5
  ratio1/base/__init__.py,sha256=hACh83_cIv7-PwYMM3bQm2IBmNqiHw-3PAfDfAEKz9A,259
@@ -10,7 +10,7 @@ ratio1/base/pipeline.py,sha256=szoHrk1qBdY6NKPUk3tUTsJx3XzYp5C2GTOlzRiQi48,62489
10
10
  ratio1/base/plugin_template.py,sha256=Gs438cSkhvxPujE4CRH_32pcuZaVwI9kia8E4VDRpSU,138794
11
11
  ratio1/base/responses.py,sha256=ZKBZmRhYDv8M8mQ5C_ahGsQvtWH4b9ImRcuerQdZmNw,6937
12
12
  ratio1/base/transaction.py,sha256=l2JCzTgH3-irFwCEBGrS3z8VOisA8GdC3zEfqgJOTG4,5138
13
- ratio1/base/webapp_pipeline.py,sha256=cH31-kuAIryUedObeW7qgxfU0ebK6qJKRxuHbbUHYVA,3706
13
+ ratio1/base/webapp_pipeline.py,sha256=H83EjkmyljetdHZ18V5R8OU3wXoWi_EpV0AAhQ4AM64,3695
14
14
  ratio1/base/payload/__init__.py,sha256=y8fBI8tG2ObNfaXFWjyWZXwu878FRYj_I8GIbHT4GKE,29
15
15
  ratio1/base/payload/payload.py,sha256=MoCeL6iZzl1an-4eqRpLW0iz6Yk3OvlBrymcmhWeecM,2689
16
16
  ratio1/bc/__init__.py,sha256=BI5pcqHdhwnMdbWTYDLW1cVP_844VtLra-lz7xprgsk,171
@@ -68,7 +68,7 @@ ratio1/io_formatter/default/aixp1.py,sha256=MX0TeUR4APA-qN3vUC6uzcz8Pssz5lgrQWo7
68
68
  ratio1/io_formatter/default/default.py,sha256=gEy78cP2D5s0y8vQh4aHuxqz7D10gGfuiKF311QhrpE,494
69
69
  ratio1/ipfs/__init__.py,sha256=vXEDLUNUO6lOTMGa8iQ9Zf7ajIQq9GZuvYraAHt3meE,38
70
70
  ratio1/ipfs/ifps_keygen,sha256=PcoYuo4c89_C9FWrKq9K_28ruhKqnxNn1s3nLHiF1tc,879
71
- ratio1/ipfs/r1fs.py,sha256=7Cs7IW1ksG7PnLoiEbf1R1zS6WiUCr7ajFqpmCCzabA,48781
71
+ ratio1/ipfs/r1fs.py,sha256=vpX2b_FdgWgC_ArY8JgW-D_9TbhIPIsNN2YFLB39mJs,49327
72
72
  ratio1/ipfs/ipfs_setup/ipfs.service,sha256=isTJQsktPy4i1yaDA9AC1OKdlTYvsCCRRAVX-EmGqAs,248
73
73
  ratio1/ipfs/ipfs_setup/launch_service.sh,sha256=GWhZyNqtohLxJg8Q_c8YnNZduu1ddXDU-IFRRMaEyiY,141
74
74
  ratio1/ipfs/ipfs_setup/restart.sh,sha256=9xHMgkUoAMI25jeaoDVFbCa_LjojYm3ubljW58RatKE,22
@@ -103,8 +103,8 @@ ratio1/utils/comm_utils.py,sha256=4cS9llRr_pK_3rNgDcRMCQwYPO0kcNU7AdWy_LtMyCY,10
103
103
  ratio1/utils/config.py,sha256=IMXAN9bpHePKEuTFGRRqFJXz_vBa-wi7s9gLhFEheRY,9953
104
104
  ratio1/utils/dotenv.py,sha256=_AgSo35n7EnQv5yDyu7C7i0kHragLJoCGydHjvOkrYY,2008
105
105
  ratio1/utils/oracle_sync/oracle_tester.py,sha256=aJOPcZhtbw1XPqsFG4qYpfv2Taj5-qRXbwJzrPyeXDE,27465
106
- ratio1-3.4.45.dist-info/METADATA,sha256=LHCIYIkIvXNehd-sURLHvre207r1Gb2pbi6rhROFlQQ,12248
107
- ratio1-3.4.45.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
108
- ratio1-3.4.45.dist-info/entry_points.txt,sha256=DR_olREzU1egwmgek3s4GfQslBi-KR7lXsd4ap0TFxE,46
109
- ratio1-3.4.45.dist-info/licenses/LICENSE,sha256=cvOsJVslde4oIaTCadabXnPqZmzcBO2f2zwXZRmJEbE,11311
110
- ratio1-3.4.45.dist-info/RECORD,,
106
+ ratio1-3.4.47.dist-info/METADATA,sha256=w88qtWACI2j8i-bAED7CopvILogVkE_aHJeMeWa5i6A,12248
107
+ ratio1-3.4.47.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
108
+ ratio1-3.4.47.dist-info/entry_points.txt,sha256=DR_olREzU1egwmgek3s4GfQslBi-KR7lXsd4ap0TFxE,46
109
+ ratio1-3.4.47.dist-info/licenses/LICENSE,sha256=cvOsJVslde4oIaTCadabXnPqZmzcBO2f2zwXZRmJEbE,11311
110
+ ratio1-3.4.47.dist-info/RECORD,,