Skip to content

Commit

Permalink
is_ens_normalizable
Browse files Browse the repository at this point in the history
  • Loading branch information
Carbon225 authored and djstrong committed Sep 4, 2023
1 parent 80174a0 commit d58162b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ ens_normalize('Nick.ETH')
# note: ens_normalize does not enforce any constraints that might be applied by a particular registrar. For example, the registrar for names that are a subname of '.eth' enforces a 3-character minimum and this constraint is not enforced by ens_normalize.
```

Check if a name is *normalizable* (see Glossary):

```python
from ens_normalize import is_ens_normalizable
# str -> bool
is_ens_normalizable('Nick.ETH')
# True
```

Inspect issues with disallowed names:

```python
Expand Down
1 change: 1 addition & 0 deletions ens_normalize/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
ens_tokenize,
ens_normalizations,
is_ens_normalized,
is_ens_normalizable,
DisallowedSequence,
DisallowedSequenceType,
CurableSequence,
Expand Down
8 changes: 8 additions & 0 deletions ens_normalize/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -1159,3 +1159,11 @@ def is_ens_normalized(name: str) -> bool:
(i.e. `ens_normalize(name) == name`).
"""
return ens_process(name, do_normalize=True).normalized == name


def is_ens_normalizable(name: str) -> bool:
"""
Checks if the input string is ENS normalizable
(i.e. `ens_normalize(name)` will not raise `DisallowedSequence`).
"""
return ens_process(name).error is None
7 changes: 7 additions & 0 deletions tests/test_normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
ens_tokenize,
ens_normalizations,
is_ens_normalized,
is_ens_normalizable,
DisallowedSequence,
DisallowedSequenceType,
CurableSequence,
Expand Down Expand Up @@ -416,3 +417,9 @@ def test_ignorable_name():
assert e.type == CurableSequenceType.EMPTY_LABEL
assert e.index == 0
assert e.sequence == '\ufe0f\ufe0f'


def test_is_normalizable():
assert is_ens_normalizable('nick.eth')
assert not is_ens_normalizable('ni_ck.eth')
assert is_ens_normalizable('')

0 comments on commit d58162b

Please sign in to comment.