Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/validators/mac_address.py: 100%

5 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:08 +0000

1"""MAC Address.""" 

2# -*- coding: utf-8 -*- 

3 

4# standard 

5import re 

6 

7# local 

8from .utils import validator 

9 

10 

11@validator 

12def mac_address(value: str, /): 

13 """Return whether or not given value is a valid MAC address. 

14 

15 This validator is based on [WTForms MacAddress validator][1]. 

16 

17 [1]: https://github.com/wtforms/wtforms/blob/master/src/wtforms/validators.py#L482 

18 

19 Examples: 

20 >>> mac_address('01:23:45:67:ab:CD') 

21 # Output: True 

22 >>> mac_address('00:00:00:00:00') 

23 # Output: ValidationFailure(func=mac_address, args={'value': '00:00:00:00:00'}) 

24 

25 Args: 

26 value: 

27 MAC address string to validate. 

28 

29 Returns: 

30 (Literal[True]): 

31 If `value` is a valid MAC address. 

32 (ValidationFailure): 

33 If `value` is an invalid MAC address. 

34 

35 > *New in version 0.2.0*. 

36 """ 

37 return re.match(r"^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$", value) if value else False