本文整理汇总了Python中socketIO_client.SocketIO.wait_for_callbacks方法的典型用法代码示例。如果您正苦于以下问题:Python SocketIO.wait_for_callbacks方法的具体用法?Python SocketIO.wait_for_callbacks怎么用?Python SocketIO.wait_for_callbacks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socketIO_client.SocketIO
的用法示例。
在下文中一共展示了SocketIO.wait_for_callbacks方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestOnlineRecognition
# 需要导入模块: from socketIO_client import SocketIO [as 别名]
# 或者: from socketIO_client.SocketIO import wait_for_callbacks [as 别名]
class TestOnlineRecognition(unittest.TestCase):
def setUp(self):
self.socketIO = SocketIO('localhost', 8000)
self.received_responses = 0
self.expected_responses = 0
time.sleep(1)
def test_online_recognition(self):
self.socketIO.on('result', self.assertMessageHasCorrectSchema)
self.send_chunks()
self.assertEquals(self.expected_responses + 2, self.received_responses)
def send_chunks(self):
self.socketIO.emit('begin', {'model': 'en-towninfo'})
self.socketIO.emit('change_lm', {'new_lm': 'new_lm'})
for chunk in self.chunks():
self.socketIO.emit('chunk', {'chunk': chunk, 'frame_rate': 16000})
self.socketIO.wait_for_callbacks()
self.socketIO.emit('end', {})
self.socketIO.wait_for_callbacks()
self.socketIO.wait_for_callbacks()
self.socketIO.wait_for_callbacks()
def chunks(self):
basedir = os.path.dirname(os.path.realpath(__file__))
wav = wave.open("%s/../resources/test.wav" % basedir, "rb")
while True:
frames = wav.readframes(16384)
if len(frames) == 0:
break
self.expected_responses += 1
yield self.frames_to_base64(frames)
def frames_to_base64(self, frames):
return base64.b64encode(frames)
def assertMessageHasCorrectSchema(self, message):
schema = {
"type": "object",
"properties": {
"status": {"type": "number"},
"final": {"type": "boolean"},
"chunk_id": {"type": "string"},
"request_id": {"type": "string"},
"result": {
"type": "object",
"properties": {
"hypotheses": {
"type": "array",
"items": {
"type": "object",
"properties": {
"transcript": {"type": "string"},
"confidence": {"type": "number"}
},
"required": ["transcript"],
"additionalProperties": False,
}
}
},
"required": ["hypotheses"],
"additionalProperties": False,
},
},
"required": ["status", "result", "final", "request_id"],
"additionalProperties": False,
}
validationResult = validate(message, schema)
self.assertIsNone(validationResult, msg="Message has invalid schema")
self.received_responses += 1
示例2: getArgs
# 需要导入模块: from socketIO_client import SocketIO [as 别名]
# 或者: from socketIO_client.SocketIO import wait_for_callbacks [as 别名]
import sys, getopt
def getArgs():
argv = sys.argv[1:];
inputfile = ''
outputfile = ''
opts, args = getopt.getopt(argv,"heri:o:",["ifile=","ofile="])
optMap = {};
for opt, arg in opts:
optMap[opt] = arg
return optMap
if __name__ == "__main__":
words = []
for line in sys.stdin:
for word in line.replace('\n', '').split(','):
words.append(word)
argMap = getArgs()
address = 'https://ghcap-web.herokuapp.com' if argMap.has_key('-r') else 'http://localhost:9000'
requests.packages.urllib3.disable_warnings()
socket = SocketIO(address + '/socket.io-client', verify=True)
def after(result):
print result
socket.emit('misc:save common words', words, after)
socket.wait_for_callbacks(seconds=20)
示例3: BlueNode
# 需要导入模块: from socketIO_client import SocketIO [as 别名]
# 或者: from socketIO_client.SocketIO import wait_for_callbacks [as 别名]
class BlueNode(QtCore.QThread):
new_data = QtCore.Signal(object)
def __init__(self, login, password):
QtCore.QThread.__init__(self, parent=None)
self.login = {'email': login, 'password': password}
self.socketIO = None
self.running = True
self.connect_to_server()
def connect_to_server(self):
self.socketIO = SocketIO('http://arhiweb.pl', 80, LoggingNamespace)
self.socketIO.on('auth_error', self.on_auth_error)
self.socketIO.on('device_error', self.on_device_error)
self.socketIO.on('device_type_error', self.on_device_type_error)
self.socketIO.on('attribute_error', self.on_attribute_error)
self.socketIO.on('attribute_error', self.on_attribute_error)
self.start()
login_data = json.dumps(self.login)
print(login_data)
self.socketIO.emit('authorization', login_data, self.callbacks_authorization)
def callbacks_authorization(self, *args):
print('callbacks_authorization', args)
def send(self, data):
self.socketIO.emit('my other event', data)
def send_device(self, device):
data = json.dumps(device)
print(data)
self.socketIO.emit('update_devices_list', data, self.callbacks_device)
def callbacks_device(self, *args):
print('callbacks_device ', args)
def send_update_device_value(self, data):
json_data = json.dumps(data)
print(json_data)
self.socketIO.emit('update_device_value', json_data, self.callback_update_device_value)
def callback_update_device_value(self, *args):
print('callback_update_device_value ', args)
def send_update_devices_status(self, data):
self.socketIO.emit('update_devices_status', json.dumps(data), self.callback_update_devices_status)
def callback_update_devices_status(self, *args):
print('update_devices_status ', args)
def on_auth_error(self, *args):
print('on auth ', args)
def on_device_error(self, *args):
print('on device error ', args)
def on_device_type_error(self, *args):
print('device_type_error ', args)
def on_attribute_error(self, *args):
print('attribute_error ', args)
def run(self):
self.socketIO.wait_for_callbacks(seconds=1)
def stop(self):
self.running = False
示例4: TestSocketIO
# 需要导入模块: from socketIO_client import SocketIO [as 别名]
# 或者: from socketIO_client.SocketIO import wait_for_callbacks [as 别名]
class TestSocketIO(TestCase):
def setUp(self):
self.socketIO = SocketIO(HOST, PORT)
self.called_on_response = False
def tearDown(self):
del self.socketIO
def on_response(self, *args):
self.called_on_response = True
for arg in args:
if isinstance(arg, dict):
self.assertEqual(arg, PAYLOAD)
else:
self.assertEqual(arg, DATA)
def is_connected(self, socketIO, connected):
childThreads = [
socketIO._rhythmicThread,
socketIO._listenerThread,
]
for childThread in childThreads:
self.assertEqual(not connected, childThread.done.is_set())
self.assertEqual(connected, socketIO.connected)
def test_disconnect(self):
'Terminate child threads after disconnect'
self.is_connected(self.socketIO, True)
self.socketIO.disconnect()
self.is_connected(self.socketIO, False)
# Use context manager
with SocketIO(HOST, PORT) as self.socketIO:
self.is_connected(self.socketIO, True)
self.is_connected(self.socketIO, False)
def test_message(self):
'Message'
self.socketIO.define(Namespace)
self.socketIO.message()
self.socketIO.wait(0.1)
namespace = self.socketIO.get_namespace()
self.assertEqual(namespace.response, 'message_response')
def test_message_with_data(self):
'Message with data'
self.socketIO.define(Namespace)
self.socketIO.message(DATA)
self.socketIO.wait(0.1)
namespace = self.socketIO.get_namespace()
self.assertEqual(namespace.response, DATA)
def test_message_with_payload(self):
'Message with payload'
self.socketIO.define(Namespace)
self.socketIO.message(PAYLOAD)
self.socketIO.wait(0.1)
namespace = self.socketIO.get_namespace()
self.assertEqual(namespace.response, PAYLOAD)
def test_message_with_callback(self):
'Message with callback'
self.socketIO.message(callback=self.on_response)
self.socketIO.wait_for_callbacks(seconds=0.1)
self.assertEqual(self.called_on_response, True)
def test_message_with_callback_with_data(self):
'Message with callback with data'
self.socketIO.message(DATA, self.on_response)
self.socketIO.wait_for_callbacks(seconds=0.1)
self.assertEqual(self.called_on_response, True)
def test_emit(self):
'Emit'
self.socketIO.define(Namespace)
self.socketIO.emit('emit')
self.socketIO.wait(0.1)
self.assertEqual(self.socketIO.get_namespace().argsByEvent, {
'emit_response': (),
})
def test_emit_with_payload(self):
'Emit with payload'
self.socketIO.define(Namespace)
self.socketIO.emit('emit_with_payload', PAYLOAD)
self.socketIO.wait(0.1)
self.assertEqual(self.socketIO.get_namespace().argsByEvent, {
'emit_with_payload_response': (PAYLOAD,),
})
def test_emit_with_multiple_payloads(self):
'Emit with multiple payloads'
self.socketIO.define(Namespace)
self.socketIO.emit('emit_with_multiple_payloads', PAYLOAD, PAYLOAD)
self.socketIO.wait(0.1)
self.assertEqual(self.socketIO.get_namespace().argsByEvent, {
'emit_with_multiple_payloads_response': (PAYLOAD, PAYLOAD),
})
def test_emit_with_callback(self):
#.........这里部分代码省略.........