Skip to content

Commit

Permalink
Added proper typing to errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
ccie18643 committed Sep 16, 2024
1 parent f2a7f7b commit 9224970
Show file tree
Hide file tree
Showing 21 changed files with 44 additions and 44 deletions.
6 changes: 3 additions & 3 deletions pytcp/protocols/arp/arp__errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@

from __future__ import annotations

from pytcp.lib.errors import PacketIntegrityError, PacketSanityError
from pytcp.protocols.errors import PacketIntegrityError, PacketSanityError


class ArpIntegrityError(PacketIntegrityError):
"""
Exception raised when ARP packet integrity check fails.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[ARP] " + message)


Expand All @@ -52,5 +52,5 @@ class ArpSanityError(PacketSanityError):
Exception raised when ARP packet sanity check fails.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[ARP] " + message)
6 changes: 3 additions & 3 deletions pytcp/protocols/dhcp4/dhcp4__errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@

from __future__ import annotations

from pytcp.lib.errors import PacketIntegrityError, PacketSanityError
from pytcp.protocols.errors import PacketIntegrityError, PacketSanityError


class Dhcp4IntegrityError(PacketIntegrityError):
"""
Exception raised when DHCPv4 packet integrity check fails.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[DHCPv4] " + message)


Expand All @@ -52,5 +52,5 @@ class Dhcp4SanityError(PacketSanityError):
Exception raised when DHCPv4 packet sanity check fails.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[DHCPv4] " + message)
4 changes: 2 additions & 2 deletions pytcp/lib/errors.py → pytcp/protocols/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class PacketIntegrityError(PacketValidationError):
Exception raised when integrity check fails.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[INTEGRITY ERROR]" + message)


Expand All @@ -62,5 +62,5 @@ class PacketSanityError(PacketValidationError):
Exception raised when sanity check fails.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[SANITY ERROR]" + message)
6 changes: 3 additions & 3 deletions pytcp/protocols/ethernet/ethernet__errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@

from __future__ import annotations

from pytcp.lib.errors import PacketIntegrityError, PacketSanityError
from pytcp.protocols.errors import PacketIntegrityError, PacketSanityError


class EthernetIntegrityError(PacketIntegrityError):
"""
Exception raised when Ethernet packet integrity check fails.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[Ethernet] " + message)


Expand All @@ -52,5 +52,5 @@ class EthernetSanityError(PacketSanityError):
Exception raised when Ethernet packet sanity check fails.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[Ethernet] " + message)
6 changes: 3 additions & 3 deletions pytcp/protocols/ethernet_802_3/ethernet_802_3__errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@

from __future__ import annotations

from pytcp.lib.errors import PacketIntegrityError, PacketSanityError
from pytcp.protocols.errors import PacketIntegrityError, PacketSanityError


class Ethernet8023IntegrityError(PacketIntegrityError):
"""
Exception raised when Ethernet 802.3 packet integrity check fails.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[Ethernet 802.3] " + message)


Expand All @@ -52,5 +52,5 @@ class Ethernet8023SanityError(PacketSanityError):
Exception raised when Ethernet 802.3 packet sanity check fails.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[Ethernet 802.3] " + message)
6 changes: 3 additions & 3 deletions pytcp/protocols/icmp4/icmp4__errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@

from __future__ import annotations

from pytcp.lib.errors import PacketIntegrityError, PacketSanityError
from pytcp.protocols.errors import PacketIntegrityError, PacketSanityError


class Icmp4IntegrityError(PacketIntegrityError):
"""
The ICMPv4 packet integrity check failure.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[ICMPv4] " + message)


Expand All @@ -52,5 +52,5 @@ class Icmp4SanityError(PacketSanityError):
The ICMPv4 packet sanity check failure.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[ICMPv4] " + message)
6 changes: 3 additions & 3 deletions pytcp/protocols/icmp6/icmp6__errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@

from __future__ import annotations

from pytcp.lib.errors import PacketIntegrityError, PacketSanityError
from pytcp.protocols.errors import PacketIntegrityError, PacketSanityError


class Icmp6IntegrityError(PacketIntegrityError):
"""
Exception raised when ICMPv6 packet integrity check fails.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[ICMPv6] " + message)


Expand All @@ -52,5 +52,5 @@ class Icmp6SanityError(PacketSanityError):
Exception raised when ICMPv6 packet sanity check fails.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[ICMPv6] " + message)
6 changes: 3 additions & 3 deletions pytcp/protocols/ip4/ip4__errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@

from __future__ import annotations

from pytcp.lib.errors import PacketIntegrityError, PacketSanityError
from pytcp.protocols.errors import PacketIntegrityError, PacketSanityError


class Ip4IntegrityError(PacketIntegrityError):
"""
Exception raised when IPv4 packet integrity check fails.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[IPv4] " + message)


Expand All @@ -52,5 +52,5 @@ class Ip4SanityError(PacketSanityError):
Exception raised when IPv4 packet sanity check fails.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[IPv4] " + message)
6 changes: 3 additions & 3 deletions pytcp/protocols/ip6/ip6__errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@

from __future__ import annotations

from pytcp.lib.errors import PacketIntegrityError, PacketSanityError
from pytcp.protocols.errors import PacketIntegrityError, PacketSanityError


class Ip6IntegrityError(PacketIntegrityError):
"""
Exception raised when IPv6 packet integrity check fails.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[IPv6] " + message)


Expand All @@ -52,5 +52,5 @@ class Ip6SanityError(PacketSanityError):
Exception raised when IPv6 packet sanity check fails.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[IPv6] " + message)
6 changes: 3 additions & 3 deletions pytcp/protocols/ip6_frag/ip6_frag__errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@

from __future__ import annotations

from pytcp.lib.errors import PacketIntegrityError, PacketSanityError
from pytcp.protocols.errors import PacketIntegrityError, PacketSanityError


class Ip6FragIntegrityError(PacketIntegrityError):
"""
Exception raised when IPv6 Frag packet integrity check fails.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[IPv6 Frag] " + message)


Expand All @@ -52,5 +52,5 @@ class Ip6FragSanityError(PacketSanityError):
Exception raised when IPv6 Frag packet sanity check fails.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[IPv6 Frag] " + message)
6 changes: 3 additions & 3 deletions pytcp/protocols/tcp/tcp__errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@

from __future__ import annotations

from pytcp.lib.errors import PacketIntegrityError, PacketSanityError
from pytcp.protocols.errors import PacketIntegrityError, PacketSanityError


class TcpIntegrityError(PacketIntegrityError):
"""
Exception raised when TCP packet integrity check fails.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[TCP] " + message)


Expand All @@ -52,5 +52,5 @@ class TcpSanityError(PacketSanityError):
Exception raised when TCP packet sanity check fails.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[TCP] " + message)
6 changes: 3 additions & 3 deletions pytcp/protocols/udp/udp__errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@

from __future__ import annotations

from pytcp.lib.errors import PacketIntegrityError, PacketSanityError
from pytcp.protocols.errors import PacketIntegrityError, PacketSanityError


class UdpIntegrityError(PacketIntegrityError):
"""
Exception raised when UDP packet integrity check fails.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[UDP] " + message)


Expand All @@ -52,5 +52,5 @@ class UdpSanityError(PacketSanityError):
Exception raised when UDP packet sanity check fails.
"""

def __init__(self, message: str, /):
def __init__(self, message: str, /) -> None:
super().__init__("[UDP] " + message)
2 changes: 1 addition & 1 deletion pytcp/stack/packet_handler/packet_handler__arp__rx.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
from typing import TYPE_CHECKING

from pytcp import stack
from pytcp.lib.errors import PacketValidationError
from pytcp.lib.logger import log
from pytcp.protocols.arp.arp__header import ArpOperation
from pytcp.protocols.arp.arp__parser import ArpParser
from pytcp.protocols.errors import PacketValidationError


class PacketHandlerArpRx(ABC):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
from abc import ABC
from typing import TYPE_CHECKING

from pytcp.lib.errors import PacketValidationError
from pytcp.lib.logger import log
from pytcp.protocols.errors import PacketValidationError
from pytcp.protocols.ethernet_802_3.ethernet_802_3__parser import (
Ethernet8023Parser,
)
Expand Down
2 changes: 1 addition & 1 deletion pytcp/stack/packet_handler/packet_handler__ethernet__rx.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
from abc import ABC
from typing import TYPE_CHECKING

from pytcp.lib.errors import PacketValidationError
from pytcp.lib.logger import log
from pytcp.protocols.errors import PacketValidationError
from pytcp.protocols.ethernet.ethernet__header import EtherType
from pytcp.protocols.ethernet.ethernet__parser import EthernetParser

Expand Down
2 changes: 1 addition & 1 deletion pytcp/stack/packet_handler/packet_handler__icmp4__rx.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@

from net_addr import Ip4Address
from pytcp import stack
from pytcp.lib.errors import PacketValidationError
from pytcp.lib.logger import log
from pytcp.protocols.enums import IpProto
from pytcp.protocols.errors import PacketValidationError
from pytcp.protocols.icmp4.icmp4__parser import Icmp4Parser
from pytcp.protocols.icmp4.message.icmp4_message import Icmp4Type
from pytcp.protocols.icmp4.message.icmp4_message__destination_unreachable import (
Expand Down
2 changes: 1 addition & 1 deletion pytcp/stack/packet_handler/packet_handler__icmp6__rx.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@

from net_addr import Ip6Address
from pytcp import stack
from pytcp.lib.errors import PacketValidationError
from pytcp.lib.logger import log
from pytcp.protocols.enums import IpProto
from pytcp.protocols.errors import PacketValidationError
from pytcp.protocols.icmp6.icmp6__parser import Icmp6Parser
from pytcp.protocols.icmp6.message.icmp6_message import Icmp6Type
from pytcp.protocols.icmp6.message.icmp6_message__destination_unreachable import (
Expand Down
2 changes: 1 addition & 1 deletion pytcp/stack/packet_handler/packet_handler__ip4__rx.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
from typing import TYPE_CHECKING

from pytcp import stack
from pytcp.lib.errors import PacketValidationError
from pytcp.lib.inet_cksum import inet_cksum
from pytcp.lib.logger import log
from pytcp.lib.packet import PacketRx
from pytcp.protocols.enums import IpProto
from pytcp.protocols.errors import PacketValidationError
from pytcp.protocols.ip4.ip4__header import IP4__HEADER__LEN
from pytcp.protocols.ip4.ip4__parser import Ip4Parser

Expand Down
2 changes: 1 addition & 1 deletion pytcp/stack/packet_handler/packet_handler__ip6__rx.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
from abc import ABC
from typing import TYPE_CHECKING

from pytcp.lib.errors import PacketValidationError
from pytcp.lib.logger import log
from pytcp.lib.packet import PacketRx
from pytcp.protocols.enums import IpProto
from pytcp.protocols.errors import PacketValidationError
from pytcp.protocols.ip6.ip6__parser import Ip6Parser


Expand Down
2 changes: 1 addition & 1 deletion pytcp/stack/packet_handler/packet_handler__tcp__rx.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
from typing import TYPE_CHECKING, cast

from pytcp import stack
from pytcp.lib.errors import PacketValidationError
from pytcp.lib.logger import log
from pytcp.lib.packet import PacketRx
from pytcp.protocols.errors import PacketValidationError
from pytcp.protocols.tcp.tcp__parser import TcpParser
from pytcp.socket.tcp__metadata import TcpMetadata
from pytcp.socket.tcp__socket import TcpSocket
Expand Down
2 changes: 1 addition & 1 deletion pytcp/stack/packet_handler/packet_handler__udp__rx.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@

from net_addr import Ip4Address
from pytcp import stack
from pytcp.lib.errors import PacketValidationError
from pytcp.lib.logger import log
from pytcp.lib.packet import PacketRx
from pytcp.protocols.errors import PacketValidationError
from pytcp.protocols.icmp4.icmp4__base import Icmp4Message
from pytcp.protocols.icmp4.message.icmp4_message__destination_unreachable import (
Icmp4DestinationUnreachableCode,
Expand Down

0 comments on commit 9224970

Please sign in to comment.