aas-standard-parser 0.3.3__py3-none-any.whl → 0.3.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.
@@ -0,0 +1,12 @@
1
+ """Helper classes for descriptor JSON parsing."""
2
+
3
+
4
+ class EndPointHrefData:
5
+ """Class to represent an endpoint href data structure."""
6
+
7
+ def __init__(self, href: str):
8
+ """Initialize the EndPointHrefData with the given href."""
9
+ self.href: str = href
10
+ self.base_url: str = ""
11
+ self.identifier: str = ""
12
+ self.identifier_encoded: str = ""
@@ -2,6 +2,9 @@
2
2
 
3
3
  import logging
4
4
 
5
+ from aas_standard_parser.classes.descriptor_json_helper_classes import EndPointHrefData
6
+ from aas_standard_parser.utils import decode_base_64, encode_base_64
7
+
5
8
  logger = logging.getLogger(__name__)
6
9
 
7
10
 
@@ -32,3 +35,30 @@ def get_endpoint_hrefs(descriptor_data: dict) -> list[str]:
32
35
  :return: A list of href strings extracted from the endpoints.
33
36
  """
34
37
  return [endpoint.get("protocolInformation", {}).get("href", "") for endpoint in descriptor_data.get("endpoints", [])]
38
+
39
+
40
+ def parse_endpoint_href(href: str) -> EndPointHrefData | None:
41
+ """Parse the endpoint href into its components.
42
+
43
+ :param href: The href string to parse.
44
+ :return: An EndPointHrefData object containing parsed components.
45
+ """
46
+ if "shells/" not in href and "submodels/" not in href:
47
+ logger.warning(f"Invalid href format: {href}")
48
+ return None
49
+
50
+ split_str = ""
51
+ if "/shells/" in href:
52
+ split_str = "/shells/"
53
+ elif "/submodels/" in href:
54
+ split_str = "/submodels/"
55
+
56
+ base_url: str = href.split(split_str, maxsplit=1)[0]
57
+ identifier: str = href.split(split_str)[1]
58
+
59
+ href_data = EndPointHrefData(href)
60
+ href_data.base_url = base_url
61
+ href_data.identifier = identifier
62
+ href_data.identifier_encoded = encode_base_64(identifier)
63
+
64
+ return href_data
@@ -1,5 +1,6 @@
1
1
  """Utility functions for AAS standard parser."""
2
2
 
3
+ import base64
3
4
  import json
4
5
  import logging
5
6
  from pathlib import Path
@@ -48,3 +49,25 @@ def _convert_to_object(content: dict) -> Any | None:
48
49
  logger.error(f"Decoding error: {e}")
49
50
  logger.error(f"In JSON: {content}")
50
51
  return None
52
+
53
+
54
+ def decode_base_64(text: str) -> str:
55
+ """Decode a Base64 encoded string.
56
+
57
+ :param text: Base64 encoded string to decode
58
+ :return: Decoded string
59
+ """
60
+ text_bytes = text.encode("utf-8")
61
+ base64_bytes = base64.b64encode(text_bytes)
62
+ return base64_bytes.decode("utf-8")
63
+
64
+
65
+ def encode_base_64(text: str) -> str:
66
+ """Encode a string to Base64.
67
+
68
+ :param text: String to encode
69
+ :return: Base64 encoded string
70
+ """
71
+ text_bytes = text.encode("utf-8")
72
+ base64_bytes = base64.b64decode(text_bytes)
73
+ return base64_bytes.decode("utf-8")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aas-standard-parser
3
- Version: 0.3.3
3
+ Version: 0.3.4
4
4
  Summary: Some auxiliary functions for parsing standard submodels
5
5
  Author-email: Daniel Klein <daniel.klein@em.ag>
6
6
  License: MIT License
@@ -3,17 +3,18 @@ aas_standard_parser/aas_parser.py,sha256=aKeiq6YFVpYyntfwdqTaMgzab_5Eo_4wV1BWBP5
3
3
  aas_standard_parser/aid_parser.py,sha256=RkQaaAIcPmKJ4cLxXfQoK4wBet1GdwH04FyNYacQgDE,14990
4
4
  aas_standard_parser/aimc_parser.py,sha256=izu967d6wH5BpxOQ6JAyo8VzKsHBrLdhZe3wkPYVFxY,9978
5
5
  aas_standard_parser/collection_helpers.py,sha256=STb6ygpVIixLguj0EJ53ZXSwnPD3mhTGlgJcIPxL9q4,4274
6
- aas_standard_parser/descriptor_json_helper.py,sha256=TqA6FEtGppNwSd-Yj9OQuTpbb4lRkbkvP4u9U_OUdP0,1243
6
+ aas_standard_parser/descriptor_json_helper.py,sha256=sSEdw7R4bJlw4dJ5hzlQAX6irqJPHUd7tByEgQqSJxI,2219
7
7
  aas_standard_parser/reference_helpers.py,sha256=HJMK1FjoEkPipw9kcT7k75EYioHz_SwcLLqXdFo9Eew,1339
8
8
  aas_standard_parser/submodel_json_helper.py,sha256=SeRJ-Oelrx1ZXW0W5rKVBLM_ade48yssBelVIZrGJLA,1240
9
9
  aas_standard_parser/submodel_parser.py,sha256=cKDKUBoKMJb1q6ISalJhLlE1VRqqFHTDWsv6BdeSmXU,2653
10
- aas_standard_parser/utils.py,sha256=aupcb_VfgLy8kGRReMXpEk_LS67rNwCVCW7BMFdgnv8,1608
10
+ aas_standard_parser/utils.py,sha256=4bZmTrOMhPsHEY3_SAwWnPpAwqU854mLOK5arugIGPg,2192
11
11
  aas_standard_parser/version_check.py,sha256=P1nb2WvVVU5RaQ4mWViFLnF9QkUv61Zc2EApYPGiiC8,1058
12
12
  aas_standard_parser/classes/aimc_parser_classes.py,sha256=PwKpuyB36urFc8YqQ6KtrG8H5WLd-3R2c3yST8Yyc_w,2581
13
+ aas_standard_parser/classes/descriptor_json_helper_classes.py,sha256=XKN-jzSYNiJTaHIhIoifheqIFTZFwONKUj3l74-mLJw,379
13
14
  aas_standard_parser/demo/demo_process.py,sha256=Xn9uD0xLoNx0ZvB3Lk0oYkGBRHaEfUbfqv5_SpPWYck,530
14
15
  aas_standard_parser/demo/logging_handler.py,sha256=x-eX4XDU3sZTJE22rzJSiaWQ8wRMbtaFpFBAeAcbIzI,5752
15
- aas_standard_parser-0.3.3.dist-info/licenses/LICENSE,sha256=simqYMD2P9Ikm0Kh9n7VGNpaVcm2TMVVQmECYZ_xVZ8,1065
16
- aas_standard_parser-0.3.3.dist-info/METADATA,sha256=77bUg2T43ICYMtwCP9yW3Cs_5UlELllBy-qPsFT63hs,4576
17
- aas_standard_parser-0.3.3.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
18
- aas_standard_parser-0.3.3.dist-info/top_level.txt,sha256=OQaK6cwYttR1-eKTz5u4M0jbwSfp4HqJ56chaf0nHnw,20
19
- aas_standard_parser-0.3.3.dist-info/RECORD,,
16
+ aas_standard_parser-0.3.4.dist-info/licenses/LICENSE,sha256=simqYMD2P9Ikm0Kh9n7VGNpaVcm2TMVVQmECYZ_xVZ8,1065
17
+ aas_standard_parser-0.3.4.dist-info/METADATA,sha256=iX7scHH8_BCzmJiBgzmbQNwPtSH2PGicVMrNsi8qkXc,4576
18
+ aas_standard_parser-0.3.4.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
19
+ aas_standard_parser-0.3.4.dist-info/top_level.txt,sha256=OQaK6cwYttR1-eKTz5u4M0jbwSfp4HqJ56chaf0nHnw,20
20
+ aas_standard_parser-0.3.4.dist-info/RECORD,,