aas-http-client 0.3.4__py3-none-any.whl → 0.3.5__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.

Potentially problematic release.


This version of aas-http-client might be problematic. Click here for more details.

aas_http_client/client.py CHANGED
@@ -80,6 +80,7 @@ class AasHttpClient(BaseModel):
80
80
  time_out: int = 200
81
81
  connection_time_out: int = 100
82
82
  ssl_verify: bool = True
83
+ trust_env: bool = False
83
84
  _session: Session = PrivateAttr(default=None)
84
85
 
85
86
  def initialize(self, password: str):
@@ -93,6 +94,7 @@ class AasHttpClient(BaseModel):
93
94
  self._session = requests.Session()
94
95
  self._session.auth = HTTPBasicAuth(self.username, password)
95
96
  self._session.verify = self.ssl_verify
97
+ self._session.trust_env = self.trust_env
96
98
 
97
99
  if self.https_proxy:
98
100
  self._session.proxies.update({"https": self.https_proxy})
@@ -31,8 +31,8 @@ def start() -> None:
31
31
  # add submodel to AAS
32
32
  model_builder.add_submodel_to_aas(aas, submodel)
33
33
 
34
- wrapper = _create_sdk_wrapper(Path("./aas_http_client/demo/python_server_config.json"))
35
- # dotnet_sdk_wrapper = _create_sdk_wrapper(Path("./aas_http_client/demo/dotnet_server_config.json"))
34
+ wrapper = _create_sdk_wrapper(Path("./aas_http_client/demo/python_server_config.yml"))
35
+ # dotnet_sdk_wrapper = _create_sdk_wrapper(Path("./aas_http_client/demo/dotnet_server_config.yml"))
36
36
 
37
37
  for existing_shell in wrapper.get_all_asset_administration_shells():
38
38
  logger.warning(f"Delete shell '{existing_shell.id}'")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aas-http-client
3
- Version: 0.3.4
3
+ Version: 0.3.5
4
4
  Summary: Generic python HTTP client for communication with various types of AAS servers
5
5
  Author-email: Daniel Klein <daniel.klein@em.ag>
6
6
  License: # :em engineering methods AG Software License
@@ -1,14 +1,13 @@
1
1
  aas_http_client/__init__.py,sha256=cAr1mQzWp0G0LKtkAOYzc9t95OY3jM3Aj4bKnxx0Dso,901
2
- aas_http_client/client.py,sha256=DFflDiU7oyDQ98-X4KQlkFDKQFN3_hqBd723n_h-NkE,26954
2
+ aas_http_client/client.py,sha256=OJc5gm2AziSABhDU0exxUt_pTcGXXmD-4jJ0-aq0_rQ,27031
3
3
  aas_http_client/core/encoder.py,sha256=FS7P0FPakzFsGz70eRFDHQZFA_2nlKLlWIxavtnFrPg,660
4
4
  aas_http_client/core/version_check.py,sha256=721Zs3xSRrJTYZtAxkaUWg9LLKtpU7oFM62DzQHZdE4,705
5
- aas_http_client/demo/demo_process.py,sha256=6sN_N3QbA4iLUmzeg1Y_XOwVAuDNtwkR4grAg7EkjWM,3301
6
- aas_http_client/demo/logging_handler.py,sha256=VJtZ4u3x_LhYZQtfNck7FuXhGFZm7gid0uDhvf9GjJ8,5596
5
+ aas_http_client/demo/demo_process.py,sha256=J-f5CEvCQYfqDoMzM2EgQhHFfTXdZDgbmIus8dB8iiQ,3299
7
6
  aas_http_client/utilities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
7
  aas_http_client/utilities/model_builder.py,sha256=EUqVvKgXiyJNtyUeFrL6ronfF4hiF1KCipxSaLj6EiE,4465
9
8
  aas_http_client/wrapper/sdk_wrapper.py,sha256=dSckMIbFJ_9wFvYKVjWNPIofcl5aINk43nIY3Un0ht4,15197
10
- aas_http_client-0.3.4.dist-info/licenses/LICENSE,sha256=ayt4HY-Tjoe1Uvj47j6UdNq8mEufKcKFangurChIHxQ,5990
11
- aas_http_client-0.3.4.dist-info/METADATA,sha256=Iel95Gsqa7EywECf0qFN1IuMCbK6hlwk_rNzm0_IqgE,10467
12
- aas_http_client-0.3.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
- aas_http_client-0.3.4.dist-info/top_level.txt,sha256=vzvoz2vjeTLwpuz-Y-eEfoQ7T3byoaKshVlFMFH5NaM,16
14
- aas_http_client-0.3.4.dist-info/RECORD,,
9
+ aas_http_client-0.3.5.dist-info/licenses/LICENSE,sha256=ayt4HY-Tjoe1Uvj47j6UdNq8mEufKcKFangurChIHxQ,5990
10
+ aas_http_client-0.3.5.dist-info/METADATA,sha256=D9g2hkwHjAbRyxMyp7c3Vd6JwHwWzFBXGs8jdF8RJcg,10467
11
+ aas_http_client-0.3.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
+ aas_http_client-0.3.5.dist-info/top_level.txt,sha256=vzvoz2vjeTLwpuz-Y-eEfoQ7T3byoaKshVlFMFH5NaM,16
13
+ aas_http_client-0.3.5.dist-info/RECORD,,
@@ -1,177 +0,0 @@
1
- """
2
- Logging handler.
3
-
4
- This module contains all methods and functions to handle the logging.
5
- """
6
-
7
- import json
8
- import logging
9
- import queue
10
- import sys
11
- import uuid
12
- from datetime import UTC, datetime
13
- from logging.handlers import QueueHandler
14
- from pathlib import Path
15
- from typing import ClassVar
16
-
17
- from pythonjsonlogger import jsonlogger
18
-
19
- LOG_FOLDER: str = "./_log"
20
- LOG_FILE_SUFFIX: str = "_log.json"
21
-
22
-
23
- class ColorCodes:
24
- """Define the color codes for the console output."""
25
-
26
- grey = "\x1b[38;21m"
27
- green = "\x1b[1;32m"
28
- yellow = "\x1b[33;21m"
29
- red = "\x1b[31;21m"
30
- bold_red = "\x1b[31;1m"
31
- blue = "\x1b[1;34m"
32
- light_blue = "\x1b[1;36m"
33
- purple = "\x1b[1;35m"
34
- reset = "\x1b[0m"
35
-
36
-
37
- class CustomConsoleFormatter(logging.Formatter):
38
- """Custom console formatter for logging with colored level.
39
-
40
- :param logging: formatter
41
- """
42
-
43
- FORMATS: ClassVar[dict] = {
44
- logging.DEBUG: ColorCodes.blue + "%(levelname)s" + ColorCodes.reset + ": %(message)s (%(filename)s:%(lineno)d)",
45
- logging.INFO: ColorCodes.green + "%(levelname)s" + ColorCodes.reset + ": %(message)s",
46
- logging.WARNING: ColorCodes.yellow + "%(levelname)s" + ColorCodes.reset + ": %(message)s",
47
- logging.ERROR: ColorCodes.red + "%(levelname)s" + ColorCodes.reset + ": %(message)s (%(filename)s:%(lineno)d)",
48
- logging.CRITICAL: ColorCodes.bold_red + "%(levelname)s: %(message)s (%(filename)s:%(lineno)d)" + ColorCodes.reset,
49
- }
50
-
51
- def format(self, record) -> str:
52
- """Format the log record.
53
-
54
- :param record: record to format
55
- :return: formatted record
56
- """
57
- log_fmt = self.FORMATS.get(record.levelno)
58
- formatter = logging.Formatter(log_fmt)
59
- return formatter.format(record)
60
-
61
-
62
- def _handle_file_rotation(log_file_path: Path, max_file_count: int = 5) -> None:
63
- log_folder: Path = log_file_path.resolve()
64
-
65
- if max_file_count < 1:
66
- return
67
-
68
- if not log_folder.exists():
69
- return
70
-
71
- existing_log_files: list[Path] = [file for file in log_folder.iterdir() if file.name.endswith(LOG_FILE_SUFFIX)]
72
-
73
- if len(existing_log_files) < max_file_count:
74
- return
75
-
76
- existing_log_files.sort(key=lambda x: x.stat().st_ctime)
77
-
78
- files_to_delete: int = len(existing_log_files) - (max_file_count - 1)
79
-
80
- for file in existing_log_files[:files_to_delete]:
81
- file.unlink()
82
-
83
- return
84
-
85
-
86
- def initialize_logging(console_level=logging.INFO) -> Path:
87
- """Initialize the standard logging.
88
-
89
- :param debug_mode_status: Status of the debug mode
90
- :param log_file_name: Name of the (path and extension)
91
- """
92
- log_path = Path(LOG_FOLDER).resolve()
93
- log_path.mkdir(parents=True, exist_ok=True)
94
-
95
- log_file_path = log_path / "api.log"
96
-
97
- log_file_format = "%(asctime)s %(levelname)s: %(message)s (%(filename)s:%(lineno)d)"
98
- logging.basicConfig(
99
- filename=log_file_path,
100
- level=logging.DEBUG,
101
- format=log_file_format,
102
- filemode="w",
103
- )
104
-
105
- # set console logging
106
- console_handler = logging.StreamHandler()
107
- console_handler.setLevel(console_level)
108
- console_handler.setFormatter(CustomConsoleFormatter())
109
- logging.getLogger("").addHandler(console_handler)
110
-
111
- # set queue logging
112
- log_queue: queue.Queue = queue.Queue(-1) # Use default max size
113
- queue_handler = QueueHandler(log_queue)
114
- logging.getLogger("").addHandler(queue_handler)
115
-
116
- logger = logging.getLogger(__name__)
117
- script_path = Path(sys.argv[0])
118
- python_version = sys.version.replace("\n", "")
119
-
120
- print("")
121
- logger.info(f"Run script '{script_path.name.replace('.py', '')}'")
122
- logger.info(f"Script executed by Python v{python_version}")
123
- logger.info("Logging initialized")
124
-
125
- return log_file_path.resolve()
126
-
127
-
128
- def read_log_file_as_list(log_file_path: Path) -> list[dict]:
129
- """Read the log file as a list of dictionaries (Json conform).
130
-
131
- :param log_file_path: Path to the log file
132
- :return: list of dictionaries (Json conform)
133
- """
134
- with Path.open(log_file_path, "r", encoding="utf-8") as f:
135
- return [json.loads(line) for line in f if line.strip()]
136
-
137
-
138
- def set_log_file(
139
- max_log_files: int = 10,
140
- ) -> Path:
141
- """Set the log file.
142
-
143
- :param max_log_files: max number of log files in folder, defaults to 5
144
- :return: log file path
145
- """
146
- logger = logging.getLogger() # Get the root logger
147
-
148
- # Remove all existing file handlers
149
- for handler in logger.handlers[:]:
150
- if isinstance(handler, logging.FileHandler):
151
- logger.removeHandler(handler)
152
- handler.close()
153
-
154
- now = datetime.now(tz=UTC)
155
- time_string = now.strftime("%Y-%m-%d_%H-%M-%S")
156
-
157
- # handle log file and folder
158
- log_path: Path = Path(LOG_FOLDER).resolve()
159
- log_path = Path(LOG_FOLDER, "runtime").resolve()
160
-
161
- log_path.mkdir(parents=True, exist_ok=True)
162
- log_file_name = f"{uuid.uuid4().hex}{LOG_FILE_SUFFIX}"
163
- log_file_path = log_path / f"{time_string}_{log_file_name}"
164
-
165
- _handle_file_rotation(log_path, max_log_files)
166
-
167
- # Add a new file handler with the new log file path
168
- json_formatter = jsonlogger.JsonFormatter("%(asctime)s %(levelname)s %(name)s %(message)s %(filename)s %(lineno)d")
169
- json_file_handler = logging.FileHandler(log_file_path, mode="w")
170
- json_file_handler.setFormatter(json_formatter)
171
- json_file_handler.setLevel(logging.DEBUG)
172
- logger.addHandler(json_file_handler)
173
-
174
- logging.info(f"Maximum log file number is: {max_log_files}") # noqa: LOG015
175
- logging.info(f"Write log file to: '{log_file_path}'") # noqa: LOG015
176
-
177
- return log_file_path.resolve()