本文整理汇总了Python中Message.Message.__str__方法的典型用法代码示例。如果您正苦于以下问题:Python Message.__str__方法的具体用法?Python Message.__str__怎么用?Python Message.__str__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Message.Message
的用法示例。
在下文中一共展示了Message.__str__方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: verifyPurchaseMessage
# 需要导入模块: from Message import Message [as 别名]
# 或者: from Message.Message import __str__ [as 别名]
def verifyPurchaseMessage(sock2, qty):
received = sock2.recv(16800)
messagePurchase= Message(received)
print messagePurchase.__str__()
if (not messagePurchase.isMessageStatusOk()):
raise FoundationException("error in creating purchase")
else:
# verify that the quantity purchased.
qtyPurchasedStr = messagePurchase.getParameter('Quantity_Purchased')
qtyPurchased = float(qtyPurchasedStr)
if (qtyPurchased <> qty):
print "error in creating purchase - Qty purchased" + str(qtyPurchased)+ " not equal to " + str(qty)
示例2: verifyAvailabilityMessage
# 需要导入模块: from Message import Message [as 别名]
# 或者: from Message.Message import __str__ [as 别名]
def verifyAvailabilityMessage(sock2, qty):
received = sock2.recv(16800)
messageAvail= Message(received)
print messageAvail.__str__()
if (not messageAvail.isMessageStatusOk()):
raise FoundationException("error in the availability message")
else:
# verify that the quantity purchased.
qtyStr = messageAvail.getParameter('Quantity')
qtyAvail = float(qtyStr)
qtyAvail = round(qtyAvail,2)
if (qtyAvail <> qty):
print "error in the quantity available" + str(qtyAvail)+ "- Qty not equal to " + str(qty)
示例3: test_bid_capacity
# 需要导入模块: from Message import Message [as 别名]
# 或者: from Message.Message import __str__ [as 别名]
def test_bid_capacity():
try:
# Connect to Clock server and send data
print 'Connecting Host:', HOST, ' Port:', PORT
sock.connect((HOST, PORT))
sock.sendall(message1.__str__())
received = ""
received = sock.recv(4096)
recMsg = Message(received)
if (recMsg.isMessageStatusOk()):
connect = Message("")
connect.setMethod(Message.GET_SERVICES)
connect.setParameter("Service",serviceId)
sock.sendall(connect.__str__())
received = sock.recv(4096)
serviceResponse = Message(received)
if (serviceResponse.isMessageStatusOk() == False):
print 'Service not received'
else:
print 'Successful Clock Server Connection'
#print "Sent: {}".format(message1.__str__())
#print "Received: {}".format(received)
# Connect to market Place server and send data
print 'Connecting Host:', HOST2, ' Port:', PORT2
sock2.connect((HOST2, PORT2))
sock2.sendall(message1.__str__())
received = sock2.recv(4096)
recMsg = Message(received)
if (recMsg.isMessageStatusOk()):
# sends the message with the port connect. This assumes that
# the program socket_server.py was previously executed.
port_message = Message("")
port_message.setMethod(Message.SEND_PORT)
port_message.setParameter("Port", agent_properties.l_port_provider)
port_message.setParameter("Type", "provider")
port_message.setParameter("CapacityType","bid")
sock2.sendall(port_message.__str__())
received = sock2.recv(4096)
recMsg = Message(received)
if (recMsg.isMessageStatusOk()):
pass
message, bidId1 = createCapacitatedBid(strProv, serviceId, str(0.155), str(17.5),str(10))
sock2.sendall(message.__str__())
verifyBid(sock2)
message, bidId2 = createCapacitatedBid(strProv, serviceId, str(0.15), str(18),str(15))
sock2.sendall(message.__str__())
verifyBid(sock2)
message, bidId3 = createCapacitatedBid(strProv, serviceId, str(0.145), str(19),str(20))
sock2.sendall(message.__str__())
verifyBid(sock2)
# Number of units consumed: 5
message = purchase(serviceId, bidId1, str(5), str(0.155), str(17.5))
sock2.sendall(message.__str__())
verifyPurchase(sock2,5)
qtyAvail = 10
message = getAvailability(strProv,serviceId, bidId1)
sock2.sendall(message.__str__())
qtyAvail = round(qtyAvail - 5, 2)
verifyAvailability(sock2, qtyAvail)
# Number of units consumed: 5
message = purchase(serviceId, bidId1, str(7), str(0.155), str(17.5))
sock2.sendall(message.__str__())
verifyPurchase(sock2,5)
message = getAvailability(strProv,serviceId, bidId1)
sock2.sendall(message.__str__())
qtyAvail = 0
verifyAvailabilityMessage(sock2, qtyAvail)
finally:
sock.shutdown(socket.SHUT_WR)
sock.close()
sock2.shutdown(socket.SHUT_WR)
sock2.close()
示例4: test_bulk_capacity_service4
# 需要导入模块: from Message import Message [as 别名]
# 或者: from Message.Message import __str__ [as 别名]
def test_bulk_capacity_service4():
message1= Message('')
message1.setMethod(Message.CONNECT)
strProv = "Provider8"
serviceId = "4" # Priority_Class_Streaming
message1.setParameter("Agent", strProv)
try:
# Connect to Clock server and send data
print 'Connecting Host:', HOST, ' Port:', PORT
sock.connect((HOST, PORT))
sock.sendall(message1.__str__())
received = ""
received = sock.recv(4096)
recMsg = Message(received)
if (recMsg.isMessageStatusOk()):
connect = Message("")
connect.setMethod(Message.GET_SERVICES)
connect.setParameter("Service",serviceId)
sock.sendall(connect.__str__())
received = sock.recv(4096)
serviceResponse = Message(received)
if (serviceResponse.isMessageStatusOk() == False):
print 'Service not received'
else:
print 'Successful Clock Server Connection'
#print "Sent: {}".format(message1.__str__())
#print "Received: {}".format(received)
# Connect to market Place server and send data
print 'Connecting Host:', HOST2, ' Port:', PORT2
sock2.connect((HOST2, PORT2))
sock2.sendall(message1.__str__())
received = sock2.recv(4096)
recMsg = Message(received)
if (recMsg.isMessageStatusOk()):
# sends the message with the port connect. This assumes that
# the program socket_server.py was previously executed.
port_message = Message("")
port_message.setMethod(Message.SEND_PORT)
port_message.setParameter("Port", agent_properties.l_port_provider)
port_message.setParameter("Type", "provider")
port_message.setParameter("CapacityType","bulk")
print 'recMsg', port_message.__str__()
sock2.sendall(port_message.__str__())
received = sock2.recv(4096)
recMsg = Message(received)
print 'recMsg', recMsg.__str__()
if (recMsg.isMessageStatusOk()):
pass
time.sleep(1)
print 'Successful Market Place Server Connection'
# send the provider availability
resource = "2"
message = send_availability(strProv,resource, str(120))
print 'message to send:' + message.__str__()
sock2.sendall(message.__str__())
received = sock2.recv(4096)
print received
recMsg= Message(received)
if (not recMsg.isMessageStatusOk()):
raise FoundationException("error in sending availability")
print "It is connected to the agent server"
# creates bids for the service 01
message, bidId1 = createBidService4(strProv, serviceId, str(0), str(0.324563087213))
sock2.sendall(message.__str__())
verifyBid(sock2)
# Number of resource used: 28.386816*(1 + 1)= 13.66
message = purchaseService4(serviceId, bidId1, str(28.386816), str(0), str(0.324563087213))
sock2.sendall(message.__str__())
received = sock2.recv(16800)
messagePur1 = Message(received)
if (not messagePur1.isMessageStatusOk()):
raise FoundationException("error in creating purchase" + messagePur1.__str__())
else:
print 'Message arrived \n' + messagePur1.__str__()
message = getAvailability(strProv,serviceId,'')
sock2.sendall(message.__str__())
qtyAvail = 120 - (28.386816*2)
qtyAvail = round(qtyAvail,2)
verifyAvailability(sock2, qtyAvail)
# Number of resource used: 66.749068 *(1 + 1)= 133.498136, as there are not enough quantities, the the server only purchase 31
message = purchaseService4(serviceId, bidId1, str(66.749068), str(0), str(0.324563087213))
sock2.sendall(message.__str__())
verifyPurchase(sock2,31.613184)
#.........这里部分代码省略.........
示例5: test_bulk_capacity
# 需要导入模块: from Message import Message [as 别名]
# 或者: from Message.Message import __str__ [as 别名]
def test_bulk_capacity():
try:
# Connect to Clock server and send data
print 'Connecting Host:', HOST, ' Port:', PORT
sock.connect((HOST, PORT))
sock.sendall(message1.__str__())
received = ""
received = sock.recv(4096)
recMsg = Message(received)
if (recMsg.isMessageStatusOk()):
connect = Message("")
connect.setMethod(Message.GET_SERVICES)
connect.setParameter("Service",serviceId)
sock.sendall(connect.__str__())
received = sock.recv(4096)
serviceResponse = Message(received)
if (serviceResponse.isMessageStatusOk() == False):
print 'Service not received'
else:
print 'Successful Clock Server Connection'
#print "Sent: {}".format(message1.__str__())
#print "Received: {}".format(received)
# Connect to market Place server and send data
print 'Connecting Host:', HOST2, ' Port:', PORT2
sock2.connect((HOST2, PORT2))
sock2.sendall(message1.__str__())
received = sock2.recv(4096)
recMsg = Message(received)
if (recMsg.isMessageStatusOk()):
# sends the message with the port connect. This assumes that
# the program socket_server.py was previously executed.
port_message = Message("")
port_message.setMethod(Message.SEND_PORT)
port_message.setParameter("Port", agent_properties.l_port_provider)
port_message.setParameter("Type", "provider")
port_message.setParameter("CapacityType","bulk")
print 'recMsg', port_message.__str__()
sock2.sendall(port_message.__str__())
received = sock2.recv(4096)
recMsg = Message(received)
print 'recMsg', recMsg.__str__()
if (recMsg.isMessageStatusOk()):
pass
time.sleep(1)
print 'Successful Market Place Server Connection'
resource = "1"
# send the provider availability
message = send_availability(strProv,resource, str(100))
print 'message to send:' + message.__str__()
sock2.sendall(message.__str__())
received = sock2.recv(4096)
print received
recMsg= Message(received)
if (not recMsg.isMessageStatusOk()):
raise FoundationException("error in sending availability")
print "It is connected to the agent server"
# creates bids for the service 01
message, bidId1 = createBid(strProv, serviceId, str(0.145), str(20))
sock2.sendall(message.__str__())
verifyBid(sock2)
# Number of resource used: 10*(0.4 + 1*(0.916666667)= 13.66
message = purchase(serviceId, bidId1, str(10), str(0.145), str(20))
sock2.sendall(message.__str__())
received = sock2.recv(16800)
messagePur1 = Message(received)
if (not messagePur1.isMessageStatusOk()):
raise FoundationException("error in creating purchase")
message = getAvailability(strProv,serviceId,'')
sock2.sendall(message.__str__())
qtyAvail = round(100 - 13.166,2)
verifyAvailability(sock2, qtyAvail)
message, bidId2 = createBid(strProv, serviceId, str(0.16), str(18))
sock2.sendall(message.__str__())
verifyBid(sock2)
# Number of resource used: 5*(0.4 + 1*(0.6667))=5.333
message = purchase(serviceId, bidId2, str(5), str(0.16), str(18))
sock2.sendall(message.__str__())
verifyPurchase(sock2,5)
message = getAvailability(strProv,serviceId,'')
sock2.sendall(message.__str__())
qtyAvail = round(qtyAvail - 5.333,2)
verifyAvailability(sock2, qtyAvail)
message, bidId3 = createBid(strProv, serviceId, str(0.15), str(21))
sock2.sendall(message.__str__())
#.........这里部分代码省略.........