MCPcopy Create free account
hub / github.com/rthalley/dnspython / _validate_labels

Function _validate_labels

dns/name.py:320–347  ·  view source on GitHub ↗

Check for empty labels in the middle of a label sequence, labels that are too long, and for too many labels. Raises ``dns.name.NameTooLong`` if the name as a whole is too long. Raises ``dns.name.EmptyLabel`` if a label is empty (i.e. the root label) and appears in a position other

(labels: Tuple[bytes, ...])

Source from the content-addressed store, hash-verified

318
319
320def _validate_labels(labels: Tuple[bytes, ...]) -> None:
321 """Check for empty labels in the middle of a label sequence,
322 labels that are too long, and for too many labels.
323
324 Raises ``dns.name.NameTooLong`` if the name as a whole is too long.
325
326 Raises ``dns.name.EmptyLabel`` if a label is empty (i.e. the root
327 label) and appears in a position other than the end of the label
328 sequence
329
330 """
331
332 l = len(labels)
333 total = 0
334 i = -1
335 j = 0
336 for label in labels:
337 ll = len(label)
338 total += ll + 1
339 if ll > 63:
340 raise LabelTooLong
341 if i < 0 and label == b"":
342 i = j
343 j += 1
344 if total > 255:
345 raise NameTooLong
346 if i >= 0 and i != l - 1:
347 raise EmptyLabel
348
349
350def _maybe_convert_to_binary(label: bytes | str) -> bytes:

Callers 2

__init__Method · 0.85
__setstate__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…