Skip to content

Commit 60349c0

Browse files
committed
restructuring to use data driven approach with datatypes
1 parent f42a57c commit 60349c0

13 files changed

+973
-442
lines changed

Diff for: pyrad/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@
4343
__copyright__ = 'Copyright 2002-2023 Wichert Akkerman, Istvan Ruzman and Christian Giese. All rights reserved.'
4444
__version__ = '2.4'
4545

46-
__all__ = ['client', 'dictionary', 'packet', 'server', 'tools', 'dictfile']
46+
__all__ = ['client', 'dictionary', 'packet', 'server', 'datatypes', 'dictfile']

Diff for: pyrad/datatypes/__init__.py

Whitespace-only changes.

Diff for: pyrad/datatypes/base.py

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""
2+
base.py
3+
4+
Contains base datatype
5+
"""
6+
from abc import ABC, abstractmethod
7+
8+
class AbstractDatatype(ABC):
9+
"""
10+
Root of entire datatype class hierarchy
11+
"""
12+
def __init__(self, name):
13+
self.name = name
14+
15+
@abstractmethod
16+
def encode(self, attribute, decoded, *args, **kwargs):
17+
"""
18+
turns python data structure into bytes
19+
20+
:param *args:
21+
:param **kwargs:
22+
:param attribute:
23+
:param decoded: python data structure to encode
24+
:return: encoded bytes
25+
"""
26+
27+
@abstractmethod
28+
def print(self, attribute, decoded, *args, **kwargs):
29+
"""
30+
returns string representation of decoding
31+
32+
:param *args:
33+
:param **kwargs:
34+
:param attribute: attribute object
35+
:param decoded: value pair
36+
:return: string
37+
"""
38+
39+
@abstractmethod
40+
def parse(self, dictionary, string, *args, **kwargs):
41+
"""
42+
returns python structure from ASCII string
43+
44+
:param *args:
45+
:param **kwargs:
46+
:param dictionary:
47+
:param string: ASCII string of attribute
48+
:return: python structure for attribute
49+
"""
50+
51+
@abstractmethod
52+
def get_value(self, dictionary, code, attribute, packet, offset):
53+
"""
54+
retrieves the encapsulated value
55+
:param dictionary:
56+
:param code:
57+
:param *args:
58+
:param **kwargs:
59+
:param attribute: attribute value
60+
:param packet: packet
61+
:param offset: attribute starting position
62+
:return: encapsulated value, and bytes read
63+
"""

0 commit comments

Comments
 (0)