Delay load the ipaddress module
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
# vim:fileencoding=utf-8
|
# vim:fileencoding=utf-8
|
||||||
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
import ipaddress
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
@@ -288,12 +287,13 @@ def quotes(text: str, s: int, e: int) -> Tuple[int, int]:
|
|||||||
|
|
||||||
@postprocessor
|
@postprocessor
|
||||||
def ip(text: str, s: int, e: int) -> Tuple[int, int]:
|
def ip(text: str, s: int, e: int) -> Tuple[int, int]:
|
||||||
|
from ipaddress import ip_address
|
||||||
# Check validity of IPs (or raise InvalidMatch)
|
# Check validity of IPs (or raise InvalidMatch)
|
||||||
ip = text[s:e]
|
ip = text[s:e]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ipaddress.ip_address(ip)
|
ip_address(ip)
|
||||||
except ValueError:
|
except Exception:
|
||||||
raise InvalidMatch("Invalid IP")
|
raise InvalidMatch("Invalid IP")
|
||||||
|
|
||||||
return s, e
|
return s, e
|
||||||
|
|||||||
Reference in New Issue
Block a user