Skip to content

Commit

Permalink
Merge pull request #28 from miaowware/valid-calls
Browse files Browse the repository at this point in the history
all sources: ensure valid callsigns are ASCII, allow /s
  • Loading branch information
0x5c authored Jan 29, 2023
2 parents a97f954 + e00d57c commit 7a16761
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Issue where trustee or image from QRZ could be empty (#22).
- Improve handling of malformed dates in received data (#24).
- Issue where callsigns containing '/' were marked invalid (#20).


## [1.0.1] - 2021-09-27
Expand Down
3 changes: 2 additions & 1 deletion callsignlookuptools/callook/callookasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import aiohttp

from ..common import mixins, dataclasses, exceptions
from ..common.functions import is_callsign
from .callook import CallookClientAbc


Expand All @@ -35,7 +36,7 @@ async def new(cls, session: Optional[aiohttp.ClientSession] = None) -> 'CallookA
return obj

async def search(self, callsign: str) -> dataclasses.CallsignData: # type: ignore[override]
if not callsign.isalnum():
if not is_callsign(callsign):
raise exceptions.CallsignLookupError("Invalid Callsign")

return self._process_search(
Expand Down
3 changes: 2 additions & 1 deletion callsignlookuptools/callook/callooksync.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import requests

from ..common import mixins, dataclasses, exceptions
from ..common.functions import is_callsign
from .callook import CallookClientAbc


Expand All @@ -27,7 +28,7 @@ def __init__(self, session: Optional[requests.Session] = None):
super().__init__()

def search(self, callsign: str) -> dataclasses.CallsignData:
if not callsign.isalnum():
if not is_callsign(callsign):
raise exceptions.CallsignLookupError("Invalid Callsign")

return self._process_search(
Expand Down
5 changes: 5 additions & 0 deletions callsignlookuptools/common/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ def xml2dict(xml: Union[bytes, etree._Element], to_lower: bool = True) -> Dict:
else:
result[key] = value
return result


def is_callsign(callsign: str) -> bool:
"""Check if a callsign is valid"""
return callsign.isascii() and callsign.replace("/", "").isalnum()
3 changes: 2 additions & 1 deletion callsignlookuptools/hamqth/hamqthasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from ..common import mixins, dataclasses, exceptions
from ..common.constants import DEFAULT_USERAGENT
from ..common.functions import is_callsign
from .hamqth import HamQthClientAbc


Expand Down Expand Up @@ -49,7 +50,7 @@ async def new(cls, username: str, password: str, session_key: str = "",
return obj

async def search(self, callsign: str) -> dataclasses.CallsignData: # type: ignore[override]
if not callsign.isalnum():
if not is_callsign(callsign):
raise exceptions.CallsignLookupError("Invalid Callsign")
try:
await self._check_session(
Expand Down
3 changes: 2 additions & 1 deletion callsignlookuptools/hamqth/hamqthsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from ..common import mixins, dataclasses, exceptions
from ..common.constants import DEFAULT_USERAGENT
from ..common.functions import is_callsign
from .hamqth import HamQthClientAbc


Expand All @@ -35,7 +36,7 @@ def __init__(self, username: str, password: str, session_key: str = "",
super().__init__(username, password, session_key=session_key, useragent=useragent)

def search(self, callsign: str) -> dataclasses.CallsignData:
if not callsign.isalnum():
if not is_callsign(callsign):
raise exceptions.CallsignLookupError("Invalid Callsign")
try:
self._check_session(
Expand Down
3 changes: 2 additions & 1 deletion callsignlookuptools/qrz/qrzasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from ..common import mixins, dataclasses, exceptions
from ..common.constants import DEFAULT_USERAGENT
from ..common.functions import is_callsign
from .qrz import QrzClientAbc


Expand Down Expand Up @@ -49,7 +50,7 @@ async def new(cls, username: str, password: str, session_key: str = "",
return obj

async def search(self, callsign: str) -> dataclasses.CallsignData: # type: ignore[override]
if not callsign.isalnum():
if not is_callsign(callsign):
raise exceptions.CallsignLookupError("Invalid Callsign")
try:
await self._check_session(
Expand Down
3 changes: 2 additions & 1 deletion callsignlookuptools/qrz/qrzsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from ..common import mixins, dataclasses, exceptions
from ..common.constants import DEFAULT_USERAGENT
from ..common.functions import is_callsign
from .qrz import QrzClientAbc


Expand All @@ -35,7 +36,7 @@ def __init__(self, username: str, password: str, session_key: str = "",
super().__init__(username, password, session_key=session_key, useragent=useragent)

def search(self, callsign: str) -> dataclasses.CallsignData:
if not callsign.isalnum():
if not is_callsign(callsign):
raise exceptions.CallsignLookupError("Invalid Callsign")
try:
self._check_session(
Expand Down
3 changes: 2 additions & 1 deletion callsignlookuptools/qrzcq/qrzcqasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from ..common import mixins, dataclasses, exceptions
from ..common.constants import DEFAULT_USERAGENT
from ..common.functions import is_callsign
from .qrzcq import QrzCqClientAbc


Expand Down Expand Up @@ -49,7 +50,7 @@ async def new(cls, username: str, password: str, session_key: str = "",
return obj

async def search(self, callsign: str) -> dataclasses.CallsignData: # type: ignore[override]
if not callsign.isalnum():
if not is_callsign(callsign):
raise exceptions.CallsignLookupError("Invalid Callsign")
try:
await self._check_session(
Expand Down
3 changes: 2 additions & 1 deletion callsignlookuptools/qrzcq/qrzcqsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from ..common import mixins, dataclasses, exceptions
from ..common.constants import DEFAULT_USERAGENT
from ..common.functions import is_callsign
from .qrzcq import QrzCqClientAbc


Expand All @@ -35,7 +36,7 @@ def __init__(self, username: str, password: str, session_key: str = "",
super().__init__(username, password, session_key=session_key, useragent=useragent)

def search(self, callsign: str) -> dataclasses.CallsignData:
if not callsign.isalnum():
if not is_callsign(callsign):
raise exceptions.CallsignLookupError("Invalid Callsign")
try:
self._check_session(
Expand Down

0 comments on commit 7a16761

Please sign in to comment.