fixed R0912 / too-many-branches
This commit is contained in:
parent
9a860f32dc
commit
9b0d12deac
|
@ -160,12 +160,12 @@ def network_group(host):
|
||||||
return network_type
|
return network_type
|
||||||
|
|
||||||
|
|
||||||
|
if PY3:
|
||||||
def checkIPAddress(host, private=False):
|
def checkIPAddress(host, private=False):
|
||||||
"""
|
"""
|
||||||
Returns hostStandardFormat if it is a valid IP address,
|
Returns hostStandardFormat if it is a valid IP address,
|
||||||
otherwise returns False
|
otherwise returns False
|
||||||
"""
|
"""
|
||||||
if not isinstance(host, str):
|
|
||||||
if host[0:12] == b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF':
|
if host[0:12] == b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF':
|
||||||
hostStandardFormat = socket.inet_ntop(socket.AF_INET, host[12:])
|
hostStandardFormat = socket.inet_ntop(socket.AF_INET, host[12:])
|
||||||
return checkIPv4Address(host[12:], hostStandardFormat, private)
|
return checkIPv4Address(host[12:], hostStandardFormat, private)
|
||||||
|
@ -185,7 +185,13 @@ def checkIPAddress(host, private=False):
|
||||||
# not 64-bit compatible so let us drop the IPv6 address.
|
# not 64-bit compatible so let us drop the IPv6 address.
|
||||||
return False
|
return False
|
||||||
return checkIPv6Address(host, hostStandardFormat, private)
|
return checkIPv6Address(host, hostStandardFormat, private)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
def checkIPAddress(host, private=False):
|
||||||
|
"""
|
||||||
|
Returns hostStandardFormat if it is a valid IP address,
|
||||||
|
otherwise returns False
|
||||||
|
"""
|
||||||
if host[0:12] == '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF':
|
if host[0:12] == '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF':
|
||||||
hostStandardFormat = socket.inet_ntop(socket.AF_INET, host[12:])
|
hostStandardFormat = socket.inet_ntop(socket.AF_INET, host[12:])
|
||||||
return checkIPv4Address(host[12:], hostStandardFormat, private)
|
return checkIPv4Address(host[12:], hostStandardFormat, private)
|
||||||
|
@ -207,12 +213,12 @@ def checkIPAddress(host, private=False):
|
||||||
return checkIPv6Address(host, hostStandardFormat, private)
|
return checkIPv6Address(host, hostStandardFormat, private)
|
||||||
|
|
||||||
|
|
||||||
|
if PY3:
|
||||||
def checkIPv4Address(host, hostStandardFormat, private=False):
|
def checkIPv4Address(host, hostStandardFormat, private=False):
|
||||||
"""
|
"""
|
||||||
Returns hostStandardFormat if it is an IPv4 address,
|
Returns hostStandardFormat if it is an IPv4 address,
|
||||||
otherwise returns False
|
otherwise returns False
|
||||||
"""
|
"""
|
||||||
if not isinstance(host, str):
|
|
||||||
if host[0] == 127: # 127/8
|
if host[0] == 127: # 127/8
|
||||||
if not private:
|
if not private:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
|
@ -235,7 +241,13 @@ def checkIPv4Address(host, hostStandardFormat, private=False):
|
||||||
'Ignoring IP address in private range: %s', hostStandardFormat)
|
'Ignoring IP address in private range: %s', hostStandardFormat)
|
||||||
return hostStandardFormat if private else False
|
return hostStandardFormat if private else False
|
||||||
return False if private else hostStandardFormat
|
return False if private else hostStandardFormat
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
def checkIPv4Address(host, hostStandardFormat, private=False):
|
||||||
|
"""
|
||||||
|
Returns hostStandardFormat if it is an IPv4 address,
|
||||||
|
otherwise returns False
|
||||||
|
"""
|
||||||
if host[0] == '\x7F': # 127/8
|
if host[0] == '\x7F': # 127/8
|
||||||
if not private:
|
if not private:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
|
|
Reference in New Issue
Block a user