Skip to content

Commit

Permalink
restructuring to use data driven approach
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat-pGuo committed Dec 5, 2024
1 parent f42a57c commit 03e85ad
Show file tree
Hide file tree
Showing 14 changed files with 1,126 additions and 452 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.
61 changes: 61 additions & 0 deletions pyrad/datatypes/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""
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, attribute, packet, offset, *args, **kwargs):
"""
retrieves the encapsulated value
: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 03e85ad

Please sign in to comment.