Code Duplication    Length = 26-28 lines in 2 locations

pyof/v0x04/controller2switch/multipart_request.py 1 location

@@ 68-95 (lines=28) @@
65
        self.flags = flags
66
        self.body = body
67
68
    def pack(self, value=None):
69
        """Pack a MultipartRequest using the object's attributes.
70
71
        This method will pack the attribute body and multipart_type before pack
72
        the MultipartRequest object, then will return this struct as a
73
        binary data.
74
75
        Returns:
76
            multiparty_packed (bytes): Binary data with MultipartRequest
77
                                       packed.
78
        """
79
        buff = self.body
80
        if not value:
81
            value = self.body
82
83
        if value:
84
            if isinstance(value, (list, FixedTypeList)):
85
                obj = self._get_body_instance()
86
                obj.extend(value)
87
            elif hasattr(value, 'pack'):
88
                obj = value
89
90
            self.body = obj.pack()
91
92
        multiparty_packed = super().pack()
93
        self.body = buff
94
95
        return multiparty_packed
96
97
    def unpack(self, buff, offset=0):
98
        """Unpack a binary message into this object's attributes.

pyof/v0x04/controller2switch/multipart_reply.py 1 location

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