Skip to content

Commit

Permalink
restructuring to use data driven approach with datatypes
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat-pGuo committed Dec 6, 2024
1 parent f42a57c commit 60349c0
Show file tree
Hide file tree
Showing 13 changed files with 973 additions and 442 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.
63 changes: 63 additions & 0 deletions pyrad/datatypes/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""
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, *args, **kwargs):
"""
turns python data structure into bytes
:param *args:
:param **kwargs:
:param attribute:
:param decoded: python data structure to encode
:return: encoded bytes
"""

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

@abstractmethod
def parse(self, dictionary, string, *args, **kwargs):
"""
returns python structure from ASCII string
:param *args:
:param **kwargs:
:param dictionary:
:param string: ASCII string of attribute
:return: python structure for attribute
"""

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

0 comments on commit 60349c0

Please sign in to comment.