Code Duplication    Length = 27-31 lines in 2 locations

pyof/v0x04/controller2switch/multipart_request.py 1 location

@@ 74-104 (lines=31) @@
71
        self.flags = flags
72
        self.body = body
73
74
    def pack(self, value=None):
75
        """Pack a MultipartRequest using the object's attributes.
76
77
        This method will pack the attribute body and multipart_type before pack
78
        the MultipartRequest object, then will return this struct as a
79
        binary data.
80
81
        Args:
82
            value (:class:`~MultipartRequest`): Object to be packed.
83
84
        Returns:
85
            bytes: Binary data with MultipartRequest packed.
86
87
        """
88
        buff = self.body
89
        if not value:
90
            value = self.body
91
92
        if value:
93
            if isinstance(value, (list, FixedTypeList)):
94
                obj = self._get_body_instance()
95
                obj.extend(value)
96
            elif hasattr(value, 'pack'):
97
                obj = value
98
99
            self.body = obj.pack()
100
101
        multipart_packed = super().pack()
102
        self.body = buff
103
104
        return multipart_packed
105
106
    def unpack(self, buff, offset=0):
107
        """Unpack a binary message into this object's attributes.

pyof/v0x04/controller2switch/multipart_reply.py 1 location

@@ 87-113 (lines=27) @@
84
        self.flags = flags
85
        self.body = body
86
87
    def pack(self, value=None):
88
        """Pack a StatsReply using the object's attributes.
89
90
        This method will pack the attribute body and multipart_type before pack
91
        the StatsReply object, then will return this struct as a binary data.
92
93
        Returns:
94
            stats_reply_packed (bytes): Binary data with StatsReply packed.
95
96
        """
97
        buff = self.body
98
        if not value:
99
            value = self.body
100
101
        if value:
102
            if isinstance(value, (list, FixedTypeList)):
103
                obj = self._get_body_instance()
104
                obj.extend(value)
105
            elif hasattr(value, 'pack'):
106
                obj = value
107
108
            self.body = obj.pack()
109
110
        multipart_packed = super().pack()
111
        self.body = buff
112
113
        return multipart_packed
114
115
    def unpack(self, buff, offset=0):
116
        """Unpack a binary message into this object's attributes.