mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 20:52:42 +01:00
New isSocketAddress() method
Introduction of the isSocketAddress() method which will use the existing getSocket() method in order to validate whether the provided string is a valid socket address.
This commit is contained in:
parent
7be7b98e68
commit
3e72aa5da5
@ -77,6 +77,17 @@ def getSocket(host, port=None, socks_proxy=None, vhost=None, vhostv6=None):
|
||||
else:
|
||||
raise socket.error('Something wonky happened.')
|
||||
|
||||
def isSocketAddress(s):
|
||||
if ':' in s:
|
||||
host, port = s.rsplit(':', 1)
|
||||
try:
|
||||
int(port)
|
||||
sock = getSocket(host, port)
|
||||
return True
|
||||
except (ValueError, socket.error):
|
||||
pass
|
||||
return False
|
||||
|
||||
def isIP(s):
|
||||
"""Returns whether or not a given string is an IP address.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user