Skip to content

Commit 9d44892

Browse files
Add auth_key_is_free_account()
1 parent 0e3ce67 commit 9d44892

4 files changed

Lines changed: 9 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
returned by `get_usage()`.
1515
* Add `Translator.translate_document_wait_until_done()` to poll translation
1616
status until translation is complete or fails.
17+
* Add `auth_key_is_free_account()` utility function.
1718
### Changed
1819
### Deprecated
1920
* Deprecate `limit_exceeded` and `any_limit_exceeded` properties of `Usage`

deepl/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
)
3333

3434
from .util import ( # noqa
35+
auth_key_is_free_account,
3536
convert_tsv_to_dict,
3637
convert_dict_to_tsv,
3738
validate_glossary_term,

deepl/translator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def __init__(
467467
if server_url is None:
468468
server_url = (
469469
self._DEEPL_SERVER_URL_FREE
470-
if auth_key.endswith(":fx")
470+
if util.auth_key_is_free_account(auth_key)
471471
else self._DEEPL_SERVER_URL
472472
)
473473

deepl/util.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ def get_int_safe(d: dict, key: str) -> Optional[int]:
3434
return None
3535

3636

37+
def auth_key_is_free_account(auth_key: str) -> bool:
38+
"""Returns True if the given authentication key belongs to a DeepL API Free
39+
account, otherwise False."""
40+
return auth_key.endswith(":fx")
41+
42+
3743
def validate_glossary_term(term: str) -> None:
3844
"""Checks if the given glossary term contains any disallowed characters.
3945

0 commit comments

Comments
 (0)