Skip to content
This repository was archived by the owner on Apr 22, 2024. It is now read-only.

Commit dfca6c9

Browse files
authored
Merge pull request #636 from hdiogenes/add-repr-to-group-mod
Add __repr__ to `GroupMod` (+4 other classes)
2 parents 2595075 + 0b75866 commit dfca6c9

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed

pyof/foundation/base.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __deepcopy__(self, memo):
6363
return type(self)(value=self._value, enum_ref=self.enum_ref)
6464

6565
def __repr__(self):
66-
return "{}({})".format(type(self).__name__, self._value)
66+
return "{}({})".format(type(self).__name__, repr(self._value))
6767

6868
def __str__(self):
6969
return '{}'.format(str(self._value))
@@ -517,6 +517,19 @@ def __eq__(self, other):
517517
"""
518518
return self.pack() == other.pack()
519519

520+
# def __repr__(self):
521+
# """Generic fallback for __repr__ using the built-in introspection.
522+
#
523+
# For debugging purposes. Disabled to avoid infinite recursion in
524+
# the case that objects reference each other.
525+
#
526+
# """
527+
# # from pprint import pformat
528+
# # attributes = pformat(dict(self._get_instance_attributes()))
529+
# attributes = ', '.join(f'{k}={v!r}' for (k, v)
530+
# in self._get_instance_attributes())
531+
# return f'{type(self).__name__}({attributes})'
532+
520533
@staticmethod
521534
def _attr_fits_into_class(attr, cls):
522535
if not isinstance(attr, cls):

pyof/v0x04/common/action.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ def __init__(self, port=None,
328328
self.port = port
329329
self.max_length = max_length
330330

331+
def __repr__(self):
332+
return f"{type(self).__name__}(port={self.port})"
333+
331334

332335
class ActionPopMPLS(ActionHeader):
333336
"""Action structure for OFPAT_POP_MPLS."""
@@ -388,6 +391,10 @@ def __init__(self, field=None):
388391
super().__init__(action_type=ActionType.OFPAT_SET_FIELD)
389392
self.field = OxmTLV() if field is None else field
390393

394+
def __repr__(self):
395+
return (f"{type(self).__name__}({self.field.oxm_field!s}, "
396+
f"{self.field.oxm_value})")
397+
391398
def pack(self, value=None):
392399
"""Pack this structure updating the length and padding it."""
393400
self._update_length()

pyof/v0x04/common/header.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,7 @@ def __init__(self, message_type=None, length=None, xid=None):
102102
self.message_type = message_type
103103
self.length = length
104104
self.xid = xid
105+
106+
def __repr__(self):
107+
return (f"{type(self).__name__}(version={self.version}, "
108+
f"xid={self.xid}, {self.message_type!s})")

pyof/v0x04/controller2switch/common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ def __init__(self, length=None, weight=None, watch_port=None,
224224
self.watch_group = watch_group
225225
self.actions = actions
226226

227+
def __repr__(self):
228+
return f"{type(self).__name__}(actions={self.actions!r})"
229+
227230
def unpack(self, buff, offset=0):
228231
"""Unpack bucket.
229232

pyof/v0x04/controller2switch/group_mod.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,8 @@ def __init__(self, xid=None, command=None, group_type=None, group_id=None,
9191
self.group_type = group_type
9292
self.group_id = group_id
9393
self.buckets = buckets
94+
95+
def __repr__(self):
96+
return (f"{type(self).__name__}(xid={self.header.xid}, {self.command},"
97+
f" group_type={self.group_type}, group_id={self.group_id},"
98+
f" buckets={self.buckets!r})")

0 commit comments

Comments
 (0)