FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
validators/src/validators/mac_address.py at master · python-validators/validators · GitHub
python-validators
validators
Repository navigation
Code
Issues
6
(6)
Pull requests
34
(34)
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
validators
/
src
/
validators
/
mac_address.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
36 lines (26 loc) · 996 Bytes
Breadcrumbs
validators
/
src
/
validators
/
mac_address.py
Copy path
File metadata and controls
36 lines (26 loc) · 996 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""MAC Address."""
# standard
import
re
# local
from
.
utils
import
validator
@
validator
def
mac_address
(
value
:
str
,
/
):
"""Return whether or not given value is a valid MAC address.
This validator is based on [WTForms MacAddress validator][1].
[1]: https://github.com/wtforms/wtforms/blob/master/src/wtforms/validators.py#L482
Examples:
>>> mac_address('01:23:45:67:ab:CD')
True
>>> mac_address('00:00:00:00:00')
ValidationError(func=mac_address, args={'value': '00:00:00:00:00'})
Args:
value:
MAC address string to validate.
Returns:
(Literal[True]): If `value` is a valid MAC address.
(ValidationError): If `value` is an invalid MAC address.
"""
# Check for mixed separators: MAC addresses cannot use both ':' and '-' simultaneously
if
":"
in
value
and
"-"
in
value
:
return
False
return
re
.
match
(
r"^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$"
,
value
)
if
value
else
False
Back
|
FazBrowse Home
|
New Git URL