Skip to content

Commit

Permalink
Updates _get_txt_record_key_value
Browse files Browse the repository at this point in the history
  • Loading branch information
raul-marquez-csa committed Jan 29, 2024
1 parent 76f85da commit 601d100
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/python_testing/operational_mdns_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.
#

import logging
import time
from typing import Dict, Union

Expand Down Expand Up @@ -89,12 +90,18 @@ def _get_service_name(self):
def _get_txt_record_key_value(self, key: str):
# Convert the key from string to bytes, as the dictionary uses bytes
byte_key = key.encode('utf-8')


if self._service_info is None:
logging.info("Service info not found")
return None

# Check if the key exists in the dictionary
asserts.assert_in(byte_key, self._service_info.properties, f"Property '{key}' not found")
if byte_key not in self._service_info.properties:
logging.info("Key '{key}' not found")
return None

value = self._service_info.properties[byte_key]

# Convert the value from bytes to string
return None if value is None else value.decode('utf-8')

async def getTxtRecord(self, key: str = None, refresh=False) -> Union[Dict[str, str], str, None]:
Expand Down

0 comments on commit 601d100

Please sign in to comment.