Support IPV6 and IPV4 domainparts
https://tools.ietf.org/html/rfc7622#section-3.2
This commit is contained in:
parent
4650615010
commit
49a78ae8ed
|
@ -173,17 +173,24 @@ def prep(user, server, resource):
|
|||
"""
|
||||
# This function comes from
|
||||
#http://svn.twistedmatrix.com/cvs/trunk/twisted/words/protocols/jabber/jid.py
|
||||
if user is not None:
|
||||
if len(user) < 1 or len(user) > 1023:
|
||||
raise InvalidFormat(_('Username must be between 1 and 1023 chars'))
|
||||
try:
|
||||
from nbxmpp.stringprepare import nodeprep
|
||||
user = nodeprep.prepare(user)
|
||||
except UnicodeError:
|
||||
raise InvalidFormat(_('Invalid character in username.'))
|
||||
else:
|
||||
user = None
|
||||
|
||||
ip_address = False
|
||||
|
||||
try:
|
||||
socket.inet_aton(server)
|
||||
ip_address = True
|
||||
except socket.error:
|
||||
pass
|
||||
|
||||
if not ip_address and hasattr(socket, 'inet_pton'):
|
||||
try:
|
||||
socket.inet_pton(socket.AF_INET6, server.strip('[]'))
|
||||
server = '[%s]' % server.strip('[]')
|
||||
ip_address = True
|
||||
except (socket.error, ValueError):
|
||||
pass
|
||||
|
||||
if not ip_address:
|
||||
if server is not None:
|
||||
if len(server) < 1 or len(server) > 1023:
|
||||
raise InvalidFormat(_('Server must be between 1 and 1023 chars'))
|
||||
|
@ -195,6 +202,17 @@ def prep(user, server, resource):
|
|||
else:
|
||||
raise InvalidFormat(_('Server address required.'))
|
||||
|
||||
if user is not None:
|
||||
if len(user) < 1 or len(user) > 1023:
|
||||
raise InvalidFormat(_('Username must be between 1 and 1023 chars'))
|
||||
try:
|
||||
from nbxmpp.stringprepare import nodeprep
|
||||
user = nodeprep.prepare(user)
|
||||
except UnicodeError:
|
||||
raise InvalidFormat(_('Invalid character in username.'))
|
||||
else:
|
||||
user = None
|
||||
|
||||
if resource is not None:
|
||||
if len(resource) < 1 or len(resource) > 1023:
|
||||
raise InvalidFormat(_('Resource must be between 1 and 1023 chars'))
|
||||
|
|
Loading…
Reference in New Issue