Skip to content

Commit

Permalink
move tools.py code into polymorphic class methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat-pGuo committed Nov 29, 2024
1 parent f42a57c commit 9eafd73
Show file tree
Hide file tree
Showing 12 changed files with 665 additions and 429 deletions.
2 changes: 1 addition & 1 deletion pyrad/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
__copyright__ = 'Copyright 2002-2023 Wichert Akkerman, Istvan Ruzman and Christian Giese. All rights reserved.'
__version__ = '2.4'

__all__ = ['client', 'dictionary', 'packet', 'server', 'tools', 'dictfile']
__all__ = ['client', 'dictionary', 'packet', 'server', 'datatypes', 'dictfile']
Empty file added pyrad/datatypes/__init__.py
Empty file.
42 changes: 42 additions & 0 deletions pyrad/datatypes/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
base.py
Contains base datatype
"""
from abc import ABC, abstractmethod

class AbstractDatatype(ABC):
"""
Root of entire datatype class hierarchy
"""
def __init__(self, name):
self.name = name

@abstractmethod
def encode(self, attribute, decoded):
"""
turns python data structure into bytes
:param attribute:
:param decoded: python data structure to encode
:return: encoded bytes
"""

@abstractmethod
def print(self, decoded):
"""
returns string representation of decoding
:param decoded: value pair
:return: string
"""

@abstractmethod
def get_value(self, attribute, packet, offset):
"""
retrieves the encapsulated value
:param attribute: attribute value
:param packet: packet
:param offset: attribute starting position
:return: encapsulated value, and bytes read
"""
Loading

0 comments on commit 9eafd73

Please sign in to comment.