Skip to content

Commit

Permalink
Order is important for longest-match... Also, typing.Self not in 3.9.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikael Kullberg committed Nov 19, 2024
1 parent 469d766 commit 120b6e1
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions dnstapir/dns/mozpsl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import io
from typing import Self

import httpx


Expand All @@ -10,7 +8,7 @@ class TrieNode:
def __init__(self) -> None:
self.count = 0
self.icann: bool | None = None
self.children: dict[str, Self] = {}
self.children = {}


class Trie:
Expand Down Expand Up @@ -47,17 +45,21 @@ def search(self, key: list[str]) -> tuple[int, int]:
pcore = 0
current = self.root
for label in key:
if current.icann is True:
core = current.count
elif current.icann is False:
pcore = current.count
# # If current.icann is None, do not update core or pcore
if label not in current.children:
#if '*' in current.children:
# current = current.children['*']
if current.count != 0:
break
else:
raise KeyError
current = current.children[label]
else:
current = current.children[label]

# If current.icann is None, do not update core or pcore
if current.icann is True:
core = current.count
elif current.icann is False:
pcore = current.count
if pcore == core:
pcore = 0
return (core, pcore)
Expand Down Expand Up @@ -133,7 +135,7 @@ def coredomain(self, domain: str) -> tuple[str, str]:
core.reverse()
pcore = lbls[0:p]
pcore.reverse()
return (".".join(core), ".".join(pcore))
return (".".join(core)+".", ".".join(pcore)+".")

def rdomain(self, rdomain: str) -> tuple[str, str]:
"""Find ICANN and private name cut-off for domain, reverse order process"""
Expand Down

0 comments on commit 120b6e1

Please sign in to comment.