Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/allow nested attributes #206

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/auth_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_auth1():
else:
reply = future.result()

if reply.code == AccessAccept:
if reply.number == AccessAccept:
print("Access accepted")
else:
print("Access denied")
Expand Down
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.
92 changes: 92 additions & 0 deletions pyrad/datatypes/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
"""
base.py

Contains base datatype
"""
from abc import ABC, abstractmethod

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

:param name: str representation of datatype
:type name: str
"""
self.name = name

@abstractmethod
def encode(self, attribute: 'Attribute', decoded: any,
*args, **kwargs) -> bytes:
"""
python data structure into bytestring
:param attribute: dictionary attribute
:type attribute: pyrad.dictionary.Attribute class
:param decoded: decoded value
:type decoded: any
:param args:
:param kwargs:
:return: bytestring encoding
:rtype: bytes
"""

@abstractmethod
def print(self, attribute: 'Attribute', decoded: any,
*args, **kwargs) -> str:
"""
python data structure into string
:param attribute: dictionary attribute
:type attribute: pyrad.dictionary.Attribute class
:param decoded: decoded value
:type decoded: any
:param args:
:param kwargs:
:return: string representation
:rtype: str
"""

@abstractmethod
def parse(self, dictionary: 'Dictionary', string: str,
*args, **kwargs) -> any:
"""
python data structure from string
:param dictionary: RADIUS dictionary
:type dictionary: pyrad.dictionary.Dictionary class
:param string: string representation of object
:type string: str
:param args:
:param kwargs:
:return: python datat structure
:rtype: any
"""

@abstractmethod
def get_value(self, attribute: 'Attribute', packet: bytes, offset: int) -> (tuple[((int, ...), bytes | dict), ...], int):
"""
gets encapsulated value

returns a tuple of encapsulated value and an int of number of bytes
read. the tuple contains one or more (key, value) pairs, with each key
being a full OID (tuple of ints) and the value being a bytestring (for
leaf attributes), or a dict (for TLVs).

future work will involve the removal of the dictionary and code
arguments. they are currently needed for VSA's get_value() where both
values are needed to fetch vendor attributes since vendor attributes
are not stored as a sub-attribute of the Vendor-Specific attribute.

future work will also change the return value. in place of returning a
tuple of (key, value) pairs, a single bytestring or dict will be
returned.

:param attribute: dictionary attribute
:type attribute: pyrad.dictionary.Attribute class
:param packet: entire packet bytestring
:type packet: bytes
:param offset: position in packet where current attribute begins
:type offset: int
:return: encapsulated value, bytes read
:rtype: any, int
"""
Loading