| 796 | |
| 797 | |
| 798 | class MACField(Field[Optional[str], bytes]): |
| 799 | def __init__(self, name, default): |
| 800 | # type: (str, Optional[Any]) -> None |
| 801 | Field.__init__(self, name, default, "6s") |
| 802 | |
| 803 | def i2m(self, pkt, x): |
| 804 | # type: (Optional[Packet], Optional[str]) -> bytes |
| 805 | if not x: |
| 806 | return b"\0\0\0\0\0\0" |
| 807 | try: |
| 808 | y = mac2str(x) |
| 809 | except (struct.error, OverflowError, ValueError): |
| 810 | y = bytes_encode(x) |
| 811 | return y |
| 812 | |
| 813 | def m2i(self, pkt, x): |
| 814 | # type: (Optional[Packet], bytes) -> str |
| 815 | return str2mac(x) |
| 816 | |
| 817 | def any2i(self, pkt, x): |
| 818 | # type: (Optional[Packet], Any) -> str |
| 819 | if isinstance(x, bytes) and len(x) == 6: |
| 820 | return self.m2i(pkt, x) |
| 821 | return cast(str, x) |
| 822 | |
| 823 | def i2repr(self, pkt, x): |
| 824 | # type: (Optional[Packet], Optional[str]) -> str |
| 825 | x = self.i2h(pkt, x) |
| 826 | if x is None: |
| 827 | return repr(x) |
| 828 | if self in conf.resolve: |
| 829 | x = conf.manufdb._resolve_MAC(x) |
| 830 | return x |
| 831 | |
| 832 | def randval(self): |
| 833 | # type: () -> RandMAC |
| 834 | return RandMAC() |
| 835 | |
| 836 | |
| 837 | class LEMACField(MACField): |
no outgoing calls
no test coverage detected