Add hash capabilities to OUI

Signed-off-by: liubo <liubo1@xfusion.com>
(cherry picked from commit 86d780326749cf2d1ddf4eadbec8623e93312076)
This commit is contained in:
liubo 2023-11-14 10:58:26 +08:00 committed by openeuler-sync-bot
parent e5f3f588d4
commit febe789902
2 changed files with 52 additions and 1 deletions

View File

@ -0,0 +1,47 @@
From b6c4203f85dba18074971208c0602c5bada90e8b Mon Sep 17 00:00:00 2001
From: amitmi704 <36094800+amitmi704@users.noreply.github.com>
Date: Sun, 7 Feb 2021 18:54:27 -0600
Subject: [PATCH] Add hash capabilities to OUI (#225)
Closes #224
---
netaddr/eui/__init__.py | 3 +++
netaddr/tests/eui/test_eui.py | 8 ++++++++
2 files changed, 11 insertions(+)
diff --git a/netaddr/eui/__init__.py b/netaddr/eui/__init__.py
index 5639676..07bbdc3 100644
--- a/netaddr/eui/__init__.py
+++ b/netaddr/eui/__init__.py
@@ -100,6 +100,9 @@ class OUI(BaseIdentifier):
else:
raise NotRegisteredError('OUI %r not registered!' % (oui,))
+ def __hash__(self):
+ return hash(self._value)
+
def __eq__(self, other):
if not isinstance(other, OUI):
try:
diff --git a/netaddr/tests/eui/test_eui.py b/netaddr/tests/eui/test_eui.py
index 645a518..c17d0ce 100644
--- a/netaddr/tests/eui/test_eui.py
+++ b/netaddr/tests/eui/test_eui.py
@@ -186,6 +186,14 @@ def test_oui_constructor():
assert oui.reg_count == 3
+def test_oui_hash():
+ oui0 = OUI(0)
+ oui1 = OUI(1)
+ oui_dict = {oui0: None, oui1: None}
+
+ assert list(oui_dict.keys()) == [OUI(0), OUI(1)]
+
+
def test_eui_iab():
mac = EUI('00-50-C2-00-0F-01')
assert mac.is_iab()
--
2.42.0.windows.2

View File

@ -1,6 +1,6 @@
Name: python-netaddr
Version: 0.8.0
Release: 6
Release: 7
Summary: A pure Python network address representation and manipulation library
License: BSD-3-Clause
@ -10,6 +10,7 @@ Source0: https://pypi.python.org/packages/source/n/netaddr/netaddr-%{vers
Patch9000: elimate-ROC-in-python-netaddr.patch
Patch9001: disable-test-oui-information.patch
Patch9002: 0001-Fix-for-is_loopback-behaviour-issue-222-223.patch
Patch9003: 0001-Add-hash-capabilities-to-OUI-225.patch
BuildArch: noarch
BuildRequires: python3-devel python3-setuptools python3-sphinx python3-pytest
@ -58,6 +59,9 @@ py.test-%{python3_version}
%{_bindir}/netaddr
%changelog
* Tue Nov 14 2023 liubo <liubo1@xfusion.com> - 0.8.0-7
- Add hash capabilities to OUI
* Tue Jun 13 2023 zhangpan <zhangpan103@h-partners.com> - 0.8.0-6
- delete taboo words