本文整理汇总了Python中Client.Client.run方法的典型用法代码示例。如果您正苦于以下问题:Python Client.run方法的具体用法?Python Client.run怎么用?Python Client.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Client.Client
的用法示例。
在下文中一共展示了Client.run方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: submitParsingRequest
# 需要导入模块: from Client import Client [as 别名]
# 或者: from Client.Client import run [as 别名]
def submitParsingRequest(self,
parsingRequest):
gearmanClient = Client(ClientManager.JOB_SERVER_ADDRESS_LIST,
parsingRequest)
gearmanClient.run()
gearmanClient = None
示例2: ClientRunTests
# 需要导入模块: from Client import Client [as 别名]
# 或者: from Client.Client import run [as 别名]
class ClientRunTests(unittest.TestCase):
def setUp(self):
self.client_key = 1231241
self.client_id = 'client_id_element'
self.mock_server = AbstractQueueEntity()
self.mock_server.input_queue.put = MagicMock()
self.mock_server_output_queue = Queue()
self.mock_server_input_queue = Queue()
self.client = Client(client_id=None, client_key=123, server=self.mock_server, server_id=None)
self.client.prepare_message_for_server = MagicMock(return_value='mock_response')
self.prepareQueues()
self.client.establish_connection = MagicMock(
return_value=(self.mock_server_input_queue, self.mock_server_output_queue))
def prepareQueues(self):
self.mock_server_output_queue.put(self.client.error_signal)
def test_run_puts_on_server_input_queue_result_of_own_prepare_message_for_server(self):
self.client.print_error_message = MagicMock()
self.mock_server_output_queue.put('mock')
self.client.run()
self.assertTrue(self.client.prepare_message_for_server.called)
self.assertFalse(self.mock_server_input_queue.empty())
self.assertEqual(self.mock_server_input_queue.get(), 'mock_response')
def test_run_when_gets_a_message_from_server_will_call_connect_from_server(self):
self.mock_server_output_queue.get()
self.mock_server_output_queue.put('mock_message_from_server')
self.client.process_message_from_server = MagicMock()
self.client.run()
self.assertTrue(self.client.process_message_from_server.called)
self.client.process_message_from_server.assert_called_with('mock_message_from_server')
def test_run_when_gets_calls_print_ok_message_if_connect_from_server_returns_ok_message(self):
self.client.print_ok_response = MagicMock()
self.mock_server_output_queue.put('mock_message_from_server')
self.client.process_message_from_server = MagicMock(return_value=self.client.ok_signal)
self.client.run()
self.assertTrue(self.client.print_ok_response.called)
def test_run_when_gets_calls_print_error_message_if_connect_from_server_returns_error_signal(self):
self.client.prepare_message_for_server = MagicMock(return_value='mock_response')
self.client.print_error_message = MagicMock()
self.mock_server_output_queue.put('mock_message_from_server')
self.client.process_message_from_server = MagicMock(return_value=self.client.error_signal)
self.client.run()
self.assertTrue(self.client.print_error_message.called)
示例3: POST
# 需要导入模块: from Client import Client [as 别名]
# 或者: from Client.Client import run [as 别名]
def POST(self):
# Open a temporary file
file = open("%s/in_%f.dat" % (directory, random()), 'wb')
inputs = web.input(video = {}, type = {}, start = {}, end = {}, faces = {})
file.write(inputs['video'].value)
# Flush the file
file.flush()
os.fsync(file.fileno())
file.close()
start = None
end = None
if len(inputs["start"]) > 0:
start = int(inputs["start"])
if len(inputs["end"]) > 0:
end = int(inputs["end"])
client = Client(file.name, int(inputs['type']), start = start, end = end)
segmentNames = client.run(Segmenter(), inputs['faces'] == "on", "THEO", "ogg", False)
return render.video(segments = segmentNames)
示例4: ClientTests
# 需要导入模块: from Client import Client [as 别名]
# 或者: from Client.Client import run [as 别名]
class ClientTests(unittest.TestCase):
def setUp(self):
self.client = Client(name='name',
g='generator',
p='size',
input_queue='input_queue',
output_queue='output_queue',
rsa_obj='rsa-objc',
keys='keys',
server_id='server_id')
def test_is_instance_of_thread(self):
self.assertTrue(isinstance(self.client, threading.Thread))
def test_create_private_key_returns_a_random_number_smaller_than_p_minus_two(self):
p = 100
self.client.p = p
probe_size = 100
result = all([0 <= self.client.create_private_key() <= p - 2 for _ in range(probe_size)])
self.assertTrue(result)
def test_create_private_key_returns_a_prime_number(self):
p = 100
self.client.p = p
probe_size = 100
flag = all([is_prime(self.client.create_private_key()) for _ in range(probe_size)])
self.assertTrue(flag)
def test_has_a_finished_successfully_property_set_to_None(self):
self.assertTrue(hasattr(self.client, 'finished_successfully'))
self.assertEqual(self.client.finished_successfully, None)
def test_has_send_final_message_method(self):
self.client.send_final_message()
def test_create_initial_message_returns_correct_number(self):
p = 4121
self.client.p = p
g = 123
self.client.g = g
alpha = 231
self.client.alpha = alpha
expected = g ** alpha % p
actual = self.client.generate_own_number()
self.assertEqual(actual, expected)
def test_decode_message_method_returns_exchanged_key_as_first_argument(self):
p = 41
self.client.p = p
alpha = 17
self.client.alpha = alpha
message = 16
expected = alpha ** message % p
result = self.client.generate_shared_key(message)
self.assertEqual(result, expected)
@patch('Client.Cipher')
def test_run_creates_alpha_by_calling_create_private_key(self, mock_cipher):
self.client.output_queue = MagicMock()
MagicMock().attach_mock(self.client.output_queue, 'put')
value = 'mock_value'
self.client.create_private_key = MagicMock(return_value=value)
self.client.generate_own_number = MagicMock()
self.client.input_queue = MagicMock()
self.client.rsa_obj = MagicMock()
self.client.run()
self.assertEqual(self.client.alpha, value)
@patch('Client.Cipher')
def test_run_creates_initial_message_saves_it_and_puts_on_output_queue(self, mock_cipher):
self.client.create_private_key = MagicMock()
self.client.output_queue = MagicMock()
MagicMock().attach_mock(self.client.output_queue, 'put')
mock_message = 'mock_message'
self.client.generate_own_number = MagicMock(return_value=('%s' % mock_message))
self.client.input_queue = MagicMock()
self.client.rsa_obj = MagicMock()
self.client.run()
self.client.output_queue.put.assert_called_once_with(mock_message)
self.assertEqual(self.client.own_number, mock_message)
@patch('Client.Cipher')
def test_run_calls_get_on_input_queue_and_sets_finish_flag_to_false_for_error(self, mock_cipher):
self.client.create_private_key = MagicMock()
self.client.output_queue = MagicMock()
MagicMock().attach_mock(self.client.output_queue, 'put')
self.client.generate_own_number = MagicMock()
self.client.input_queue = MagicMock()
error_signal = 'ERROR'
self.client.input_queue.get = MagicMock(return_value=error_signal)
self.client.rsa_obj = MagicMock()
#.........这里部分代码省略.........
示例5: OptionParser
# 需要导入模块: from Client import Client [as 别名]
# 或者: from Client.Client import run [as 别名]
unspecifiedVideos = ["res/hungergames-720p.mp4", "res/skyfall.mp4", "res/tangled.mp4"]
unspecifiedFrameLengths = [50, 100, 150, 200, 250, 300, 350, 400, 450, 500]
if __name__ == "__main__":
parser = OptionParser()
parser.add_option("-v", "--videos", dest = "videos" , type = "string", action = "append", default = [])
parser.add_option("-s", "--start" , dest = "start" , type = "int" , action = "store" , default = 250)
parser.add_option("-f", "--frames", dest = "frameLengths", type="int" , action = "append", default = [])
opts, args = parser.parse_args()
if opts.videos is None or opts.videos == []:
opts.videos = unspecifiedVideos
if opts.frameLengths is None or opts.frameLengths == []:
opts.frameLengths = unspecifiedFrameLengths
for vid in opts.videos:
print("*** Video : ", vid)
for length in opts.frameLengths:
try:
print(" --- Length : " + str(opts.start) + " -> " + str(opts.start + length))
client = Client(vid, SplitType.ON_FACE_CLUSTERS, start = opts.start, end = opts.start + length)
t1 = timeit(lambda: client.run(Segmenter(), True, "THEO", "OGG", False, options = {"verbose" : 0, "write" : False}), number = 1)
t2 = timeit(lambda: client.run(Segmenter(), True, "THEO", "OGG", False, options = {"verbose" : 0, "write" : False}), number = 1)
print(" Total: %f" % t1)
print(" Clustering/Segmentation: %f" % t2)
print(" Facial recognition: %f" % (t1 - t2))
except Exception, err:
print traceback.format_exc()