Use bytearray.fromhex instead of binascii.unhexlify.

This commit is contained in:
Claudiu Popa 2014-09-10 03:21:00 +03:00
parent 18c82a0592
commit bd9bbdfd97
2 changed files with 2 additions and 7 deletions

View File

@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import binascii
import mock import mock
import netifaces import netifaces
import struct import struct
@ -30,8 +29,7 @@ class DHCPUtilsTests(unittest.TestCase):
def test_get_dhcp_request_data(self): def test_get_dhcp_request_data(self):
fake_mac_address = '010203040506' fake_mac_address = '010203040506'
fake_mac_address_a = fake_mac_address.encode('ascii', 'strict') fake_mac_address_b = bytearray.fromhex(fake_mac_address)
fake_mac_address_b = bytearray(binascii.unhexlify(fake_mac_address_a))
data = b'\x01' data = b'\x01'
data += b'\x01' data += b'\x01'

View File

@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import binascii
import datetime import datetime
import netifaces import netifaces
import random import random
@ -34,9 +33,7 @@ LOG = logging.getLogger(__name__)
def _get_dhcp_request_data(id_req, mac_address, requested_options, def _get_dhcp_request_data(id_req, mac_address, requested_options,
vendor_id): vendor_id):
mac_address_ascii = mac_address.replace(':', '').encode('ascii', 'strict') mac_address_b = bytearray.fromhex(mac_address.replace(':', ''))
mac_address_b = bytearray(binascii.unhexlify(mac_address_ascii))
# See: http://www.ietf.org/rfc/rfc2131.txt # See: http://www.ietf.org/rfc/rfc2131.txt
data = b'\x01' data = b'\x01'
data += b'\x01' data += b'\x01'