in mysqlx-connector-python/lib/mysqlx/connection.py [0:0]
def _init_attributes(self) -> None:
"""Setup default and user defined connection-attributes."""
if os.name == "nt":
if "64" in platform.architecture()[0]:
platform_arch: Union[str, Tuple[str, str]] = "x86_64"
elif "32" in platform.architecture()[0]:
platform_arch = "i386"
else:
platform_arch = platform.architecture()
os_ver = f"Windows-{platform.win32_ver()[1]}"
else:
platform_arch = platform.machine()
if platform.system() == "Darwin":
os_ver = f"macOS-{platform.mac_ver()[0]}"
else:
os_ver = "-".join(linux_distribution()[0:2])
license_chunks = LICENSE.split(" ")
if license_chunks[0] == "GPLv2":
client_license = "GPL-2.0"
else:
client_license = "Commercial"
default_attributes = {
# Process id
"_pid": str(os.getpid()),
# Platform architecture
"_platform": platform_arch,
# OS version
"_os": os_ver,
# Hostname of the local machine
"_source_host": socket.gethostname(),
# Client's name
"_client_name": "mysql-connector-python",
# Client's version
"_client_version": ".".join([str(x) for x in VERSION[0:3]]),
# Client's License identifier
"_client_license": client_license,
}
self._settings["attributes"].update(default_attributes)
if "connection-attributes" in self._settings:
for attr_name in self._settings["connection-attributes"]:
attr_value = self._settings["connection-attributes"][attr_name]
# Validate name type
if not isinstance(attr_name, str):
raise InterfaceError(
f"Attribute name '{attr_name}' must be a string type"
)
# Validate attribute name limit 32 characters
if len(attr_name) > 32:
raise InterfaceError(
f"Attribute name '{attr_name}' exceeds 32 characters "
"limit size"
)
# Validate names in connection-attributes cannot start with "_"
if attr_name.startswith("_"):
raise InterfaceError(
"Key names in 'session-connect-attributes' cannot "
f"start with '_', found: {attr_name}"
)
# Validate value type
if not isinstance(attr_value, str):
raise InterfaceError(
f"Attribute name '{attr_name}' value '{attr_value}' "
" must be a string type"
)
# Validate attribute value limit 1024 characters
if len(attr_value) > 1024:
raise InterfaceError(
f"Attribute name '{attr_name}' value: '{attr_value}' "
"exceeds 1024 characters limit size"
)
self._settings["attributes"][attr_name] = attr_value