Merge branch 'master' into develop
This commit is contained in:
commit
962dfad216
6 changed files with 44 additions and 18 deletions
|
@ -109,7 +109,7 @@ class FeatureMechanisms(BasePlugin):
|
||||||
elif value == 'realm':
|
elif value == 'realm':
|
||||||
result[value] = self.xmpp.boundjid.domain
|
result[value] = self.xmpp.boundjid.domain
|
||||||
elif value == 'service-name':
|
elif value == 'service-name':
|
||||||
result[value] = self.xmpp.address[0]
|
result[value] = self.xmpp._service_name
|
||||||
elif value == 'service':
|
elif value == 'service':
|
||||||
result[value] = 'xmpp'
|
result[value] = 'xmpp'
|
||||||
elif value in creds:
|
elif value in creds:
|
||||||
|
|
|
@ -156,6 +156,7 @@ class XEP_0045(BasePlugin):
|
||||||
entry = pr['muc'].getStanzaValues()
|
entry = pr['muc'].getStanzaValues()
|
||||||
entry['show'] = pr['show']
|
entry['show'] = pr['show']
|
||||||
entry['status'] = pr['status']
|
entry['status'] = pr['status']
|
||||||
|
entry['alt_nick'] = pr['nick']
|
||||||
if pr['type'] == 'unavailable':
|
if pr['type'] == 'unavailable':
|
||||||
if entry['nick'] in self.rooms[entry['room']]:
|
if entry['nick'] in self.rooms[entry['room']]:
|
||||||
del self.rooms[entry['room']][entry['nick']]
|
del self.rooms[entry['room']][entry['nick']]
|
||||||
|
|
15
sleekxmpp/thirdparty/statemachine.py
vendored
15
sleekxmpp/thirdparty/statemachine.py
vendored
|
@ -29,7 +29,7 @@ class StateMachine(object):
|
||||||
if state in self.__states:
|
if state in self.__states:
|
||||||
raise IndexError("The state '%s' is already in the StateMachine." % state)
|
raise IndexError("The state '%s' is already in the StateMachine." % state)
|
||||||
self.__states.append(state)
|
self.__states.append(state)
|
||||||
finally:
|
finally:
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,11 +83,14 @@ class StateMachine(object):
|
||||||
if not to_state in self.__states:
|
if not to_state in self.__states:
|
||||||
raise ValueError("StateMachine does not contain to_state %s." % to_state)
|
raise ValueError("StateMachine does not contain to_state %s." % to_state)
|
||||||
|
|
||||||
|
if self.__current_state == to_state:
|
||||||
|
return True
|
||||||
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
while not self.lock.acquire(False):
|
while not self.lock.acquire(False):
|
||||||
time.sleep(.001)
|
time.sleep(.001)
|
||||||
if (start + wait - time.time()) <= 0.0:
|
if (start + wait - time.time()) <= 0.0:
|
||||||
log.debug("Could not acquire lock")
|
log.debug("==== Could not acquire lock in %s sec: %s -> %s ", wait, self.__current_state, to_state)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
while not self.__current_state in from_states:
|
while not self.__current_state in from_states:
|
||||||
|
@ -108,7 +111,7 @@ class StateMachine(object):
|
||||||
|
|
||||||
# some 'false' value returned from func,
|
# some 'false' value returned from func,
|
||||||
# indicating that transition should not occur:
|
# indicating that transition should not occur:
|
||||||
if not return_val:
|
if not return_val:
|
||||||
return return_val
|
return return_val
|
||||||
|
|
||||||
log.debug(' ==== TRANSITION %s -> %s', self.__current_state, to_state)
|
log.debug(' ==== TRANSITION %s -> %s', self.__current_state, to_state)
|
||||||
|
@ -193,9 +196,9 @@ class StateMachine(object):
|
||||||
while not self.__current_state in states:
|
while not self.__current_state in states:
|
||||||
# detect timeout:
|
# detect timeout:
|
||||||
remainder = start + wait - time.time()
|
remainder = start + wait - time.time()
|
||||||
if remainder > 0:
|
if remainder > 0:
|
||||||
self.lock.wait(remainder)
|
self.lock.wait(remainder)
|
||||||
else:
|
else:
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
return False
|
return False
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
|
@ -241,7 +244,7 @@ class _StateCtx:
|
||||||
while not self.state_machine[self.from_state] or not self.state_machine.lock.acquire(False):
|
while not self.state_machine[self.from_state] or not self.state_machine.lock.acquire(False):
|
||||||
# detect timeout:
|
# detect timeout:
|
||||||
remainder = start + self.wait - time.time()
|
remainder = start + self.wait - time.time()
|
||||||
if remainder > 0:
|
if remainder > 0:
|
||||||
self.state_machine.lock.wait(remainder)
|
self.state_machine.lock.wait(remainder)
|
||||||
else:
|
else:
|
||||||
log.debug('StateMachine timeout while waiting for state: %s', self.from_state)
|
log.debug('StateMachine timeout while waiting for state: %s', self.from_state)
|
||||||
|
|
|
@ -4,6 +4,8 @@ import hashlib
|
||||||
|
|
||||||
def unicode(text):
|
def unicode(text):
|
||||||
if sys.version_info < (3, 0):
|
if sys.version_info < (3, 0):
|
||||||
|
if isinstance(text, str):
|
||||||
|
text = text.decode('utf-8')
|
||||||
import __builtin__
|
import __builtin__
|
||||||
return __builtin__.unicode(text)
|
return __builtin__.unicode(text)
|
||||||
return str(text)
|
return str(text)
|
||||||
|
|
|
@ -102,7 +102,7 @@ def resolve(host, port=None, service=None, proto='tcp',
|
||||||
try:
|
try:
|
||||||
# If `host` is an IPv4 literal, we can return it immediately.
|
# If `host` is an IPv4 literal, we can return it immediately.
|
||||||
ipv4 = socket.inet_aton(host)
|
ipv4 = socket.inet_aton(host)
|
||||||
yield (host, port)
|
yield (host, host, port)
|
||||||
except socket.error:
|
except socket.error:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ def resolve(host, port=None, service=None, proto='tcp',
|
||||||
# it immediately.
|
# it immediately.
|
||||||
if hasattr(socket, 'inet_pton'):
|
if hasattr(socket, 'inet_pton'):
|
||||||
ipv6 = socket.inet_pton(socket.AF_INET6, host)
|
ipv6 = socket.inet_pton(socket.AF_INET6, host)
|
||||||
yield (host, port)
|
yield (host, host, port)
|
||||||
except socket.error:
|
except socket.error:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -128,16 +128,16 @@ def resolve(host, port=None, service=None, proto='tcp',
|
||||||
results = []
|
results = []
|
||||||
if host == 'localhost':
|
if host == 'localhost':
|
||||||
if use_ipv6:
|
if use_ipv6:
|
||||||
results.append(('::1', port))
|
results.append((host, '::1', port))
|
||||||
results.append(('127.0.0.1', port))
|
results.append((host, '127.0.0.1', port))
|
||||||
if use_ipv6:
|
if use_ipv6:
|
||||||
for address in get_AAAA(host, resolver=resolver):
|
for address in get_AAAA(host, resolver=resolver):
|
||||||
results.append((address, port))
|
results.append((host, address, port))
|
||||||
for address in get_A(host, resolver=resolver):
|
for address in get_A(host, resolver=resolver):
|
||||||
results.append((address, port))
|
results.append((host, address, port))
|
||||||
|
|
||||||
for address, port in results:
|
for host, address, port in results:
|
||||||
yield address, port
|
yield host, address, port
|
||||||
|
|
||||||
|
|
||||||
def get_A(host, resolver=None):
|
def get_A(host, resolver=None):
|
||||||
|
@ -297,7 +297,10 @@ def get_SRV(host, port, service, proto='tcp', resolver=None):
|
||||||
for running_sum in sums:
|
for running_sum in sums:
|
||||||
if running_sum >= selected:
|
if running_sum >= selected:
|
||||||
rec = sums[running_sum]
|
rec = sums[running_sum]
|
||||||
sorted_recs.append((rec.target.to_text(), rec.port))
|
host = rec.target.to_text()
|
||||||
|
if host.endswith('.'):
|
||||||
|
host = host[:-1]
|
||||||
|
sorted_recs.append((host, rec.port))
|
||||||
answers[priority].remove(rec)
|
answers[priority].remove(rec)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
|
@ -192,6 +192,7 @@ class XMLStream(object):
|
||||||
|
|
||||||
#: The expected name of the server, for validation.
|
#: The expected name of the server, for validation.
|
||||||
self._expected_server_name = ''
|
self._expected_server_name = ''
|
||||||
|
self._service_name = ''
|
||||||
|
|
||||||
#: The desired, or actual, address of the connected server.
|
#: The desired, or actual, address of the connected server.
|
||||||
self.address = (host, int(port))
|
self.address = (host, int(port))
|
||||||
|
@ -473,8 +474,10 @@ class XMLStream(object):
|
||||||
|
|
||||||
if self.default_domain:
|
if self.default_domain:
|
||||||
try:
|
try:
|
||||||
self.address = self.pick_dns_answer(self.default_domain,
|
host, address, port = self.pick_dns_answer(self.default_domain,
|
||||||
self.address[1])
|
self.address[1])
|
||||||
|
self.address = (address, port)
|
||||||
|
self._service_name = host
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
log.debug("No remaining DNS records to try.")
|
log.debug("No remaining DNS records to try.")
|
||||||
self.dns_answers = None
|
self.dns_answers = None
|
||||||
|
@ -723,6 +726,20 @@ class XMLStream(object):
|
||||||
self.event("disconnected", direct=True)
|
self.event("disconnected", direct=True)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def abort(self):
|
||||||
|
self.session_started_event.clear()
|
||||||
|
self.stop.set()
|
||||||
|
if self._disconnect_wait_for_threads:
|
||||||
|
self._wait_for_threads()
|
||||||
|
try:
|
||||||
|
self.socket.shutdown(Socket.SHUT_RDWR)
|
||||||
|
self.socket.close()
|
||||||
|
self.filesocket.close()
|
||||||
|
except Socket.error:
|
||||||
|
pass
|
||||||
|
self.state.transition_any(['connected', 'disconnected'], 'disconnected', func=lambda: True)
|
||||||
|
self.event("killed", direct=True)
|
||||||
|
|
||||||
def reconnect(self, reattempt=True, wait=False, send_close=True):
|
def reconnect(self, reattempt=True, wait=False, send_close=True):
|
||||||
"""Reset the stream's state and reconnect to the server."""
|
"""Reset the stream's state and reconnect to the server."""
|
||||||
log.debug("reconnecting...")
|
log.debug("reconnecting...")
|
||||||
|
|
Loading…
Reference in a new issue