dhcpkit.utils module

Utility functions

dhcpkit.utils.camelcase_to_dash(camelcase: str) → str[source]

Convert a name in CamelCase to non-camel-case

Parameters:camelcase – CamelCased string
Returns:non-camel-cased string
dhcpkit.utils.camelcase_to_underscore(camelcase: str) → str[source]

Convert a name in CamelCase to non_camel_case

Parameters:camelcase – CamelCased string
Returns:non_camel_cased string
dhcpkit.utils.encode_domain(domain_name: str, allow_relative: bool = False) → bytearray[source]

Encode a single domain name as a sequence of bytes

Parameters:
  • domain_name – The domain name
  • allow_relative – Assume that domain names that don’t end with a period are relative and encode them as such
Returns:

The encoded domain name as bytes

dhcpkit.utils.encode_domain_list(domain_names: Iterable) → bytearray[source]

Encode a list of domain names to a sequence of bytes

Parameters:domain_names – The list of domain names
Returns:The encoded domain names as bytes
dhcpkit.utils.normalise_hex(hex_data: Union, include_colons: bool = False) → str[source]

Normalise a string containing hexadecimal data

Parameters:
  • hex_data – Hexadecimal data, either with or without colon separators per byte
  • include_colons – Whether to include colon separators per byte in the output
Returns:

Hexadecimal data in lowercase without colon separators

dhcpkit.utils.parse_domain_bytes(buffer: bytes, offset: int = 0, length: int = None, allow_relative: bool = False) → Tuple[source]

Extract a single domain name.

Parameters:
  • buffer – The buffer to read data from
  • offset – The offset in the buffer where to start reading
  • length – The amount of data we are allowed to read from the buffer
  • allow_relative – Allow domain names that do not end with a zero-length label
Returns:

The number of bytes used from the buffer and the extracted domain name

dhcpkit.utils.parse_domain_list_bytes(buffer: bytes, offset: int = 0, length: int = None) → Tuple[source]

Extract a list of domain names.

Parameters:
  • buffer – The buffer to read data from
  • offset – The offset in the buffer where to start reading
  • length – The amount of data we are allowed to read from the buffer
Returns:

The number of bytes used from the buffer and the extracted domain names

dhcpkit.utils.validate_domain_label(label: str)[source]

Check if a given string is a valid domain label

Parameters:label – The domain label