本文整理汇总了Python中Message.Message类的典型用法代码示例。如果您正苦于以下问题:Python Message类的具体用法?Python Message怎么用?Python Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createResponse
def createResponse(self):
''' Get response from similarity check. If good, send reply '''
new = Message('lastEmail.txt')
# print "Incoming Mail: " + '\n' + new.getBody()
subject = new.getSubject()
subject = "AMR Response: " + subject
# print new.getBody()
tool = 's' # Chose g for Gensim or s for Scikit Learn
modelToUse = "lda"
if tool == 'g':
match, accuracy, self.models = main.emailCheck(
self.path, self.corpusName, modelToUse, "gensim",
new, self.models)
elif tool == 's':
match, accuracy, self.models = main.emailCheck(
self.path, self.corpusName, modelToUse, "scikit",
new, self.models)
else:
match, accuracy = None, None
if match is not None:
# print "Outgoing Mail: " + '\n' + match.getBody()
reply = self.buildReply(match, accuracy)
# print reply
self.send(reply, subject)
return True
return False
示例2: add_new_conversation
def add_new_conversation(cls, sender, receiver, title, content):
"""Adds new conversation with receiver for sender, returns Conversation object
"""
#TODO: check if sender and receiver aren't the same person, if so, add only once
skey = ndb.Key('User', sender)
rkey = ndb.Key('User', receiver)
if sender == receiver:
rl = [skey]
rln = [sender]
else:
rl = [rkey, skey]
rln = [sender, receiver]
conv = Conversation(
owner = sender,
receivers_list = rl,
receivers_list_norm = rln,
title = title,
)
msg = Message(
sender = sender,
content = content
)
k = msg.put()
conv.insert_message(k)
ck = conv.put()
User.add_conversation_for_users(ck, sender, receiver)
return conv, msg
示例3: takeUserInput
def takeUserInput(self):
print("--------------------------------------------------------------------------")
print("-----------------------Welcome to Safeway!!-------------------------------")
enterOption = input("Press 1 to Enter, Press 2 to Exit")
if enterOption == 1:
print("-----------------------------------------------------------------------")
new_customer = ""
while True:
print("-----------------------------------------------------------------------")
print("Enter 1 for creating a customer")
print("Enter 2 for generating a random customer")
print("Enter 3 to exit")
option = input("Please Enter your choice")
print("\n")
if option == 1:
new_customer = Customer()
del new_customer.items[:]
while True:
print("Enter 1 for Adding Item")
print("Enter 2 to see all the Items")
print("Enter 3 If finished shopping")
option2 = input("Please Enter your choice")
if option2 == 1:
item = Item.Item()
new_customer.items.append(item)
print("---------------------New Item Added-------------------------\n")
elif option2 == 2:
print("Item Name Item Price\n")
print("-----------------------------------------")
for i in new_customer.items:
print(str(i.name)+" "+ str(i.value))
print("\n")
elif option2 ==3:
message = Message('addcustomer', new_customer)
m = message.get_message_json()
self.protocol.sendLine(m)
print("Customer sent to the queue")
break
if option==2:
message = Message('addcustomer', Customer())
m = message.get_message_json()
self.protocol.sendLine(m)
print("Customer sent to the queue")
continue
if option ==3:
break
if enterOption == 2:
print("Good Bye")
sys.exit()
示例4: createFromBytes
def createFromBytes(self, msgtype, data):
Message.createFromBytes(self, msgtype, data)
self.options = unpack(">B", data[0])[0]
numcerts = unpack(">B", data[1])[0]
for i in range(0, numcerts):
# TODO: Not implemented
pass
示例5: createKeywordText
def createKeywordText(path, corpusName):
''' This function takes in the location of the email files and finds the
keywords from all of the files and saves the corpus to a text file that
can be read later '''
saveCorpus = open(corpusName + ".txt", 'w')
saveCorpusIndex = open(corpusName + ".index", 'w')
messages = []
i = 0
errors = 0
l = len(os.listdir(path))
for filename in os.listdir(path):
print "Working on", str(filename)
if errors == 10:
print "More than 10 errors. Stopping."
break
else:
new = Message(path + filename)
messages.append(new)
result = new.getError()
tokens = ' '.join(map(str, messages[i].getTokens()))
saveCorpus.write(tokens + '\n')
saveCorpusIndex.write(filename + '\n')
if result:
errors += 1
i += 1
print("Completed " + str(i) + " of " + str(l) + '\n')
saveCorpus.close()
saveCorpusIndex.close()
print "Errors creating keyword text = " + str(errors)
return True
示例6: sendmail
def sendmail(From, To, Cc=None, Bcc=None, Subject="",
Body="", File=None, Filename="", InReplyTo=None):
text = makePart(Body, "quoted-printable")
if File is not None:
data = File.read()
if data:
attach = makePart(data, "base64")
ext = os.path.splitext(Filename)[1]
ctype = mimetypes.guess_type(ext)[0] or "application/octet-stream"
attach["Content-Type"] = ctype
Filename = os.path.split(Filename)[1]
attach["Content-Disposition"] = 'attachment; filename="%s"' % Filename
msg = Message(StringIO())
msg.boundary = choose_boundary()
msg["Content-Type"] = 'multipart/mixed; boundary="%s"' % msg.boundary
msg.parts.extend([text, attach])
else: msg = text
else: msg = text
msg["From"] = From
msg["To"] = To
if Cc: msg["Cc"] = Cc
if Bcc: msg["Bcc"] = Bcc
if InReplyTo: msg["In-Reply-To"] = InReplyTo
msg["Subject"] = Subject or ""
msg["Mime-Version"] = "1.0"
text["Content-Type"] = "text/plain; charset=ISO-8859-1"
msg["X-Mailer"] = XMailer
Recipients = msg.getaddrlist("to") + msg.getaddrlist("cc") + msg.getaddrlist("bcc")
for i in range(len(Recipients)):
Recipients[i] = Recipients[i][1]
return sendMessage(From, Recipients, msg)
示例7: __init__
def __init__(self):
"""Initialize the request.
Subclasses are responsible for invoking super
and initializing self._time.
"""
Message.__init__(self)
self._transaction = None
示例8: createFromValues
def createFromValues(self, taskid, ts, hmac, certhash, trace):
# set message type and length (72B for taskid, ts, hmac and
# certhash plus length of traceroute)
Message.createFromValues(self, messageTypes["TASK_REPLY_KNOWN_CERT"], 72 + len(trace))
self.taskid = taskid
self.ts = ts
self.hmac = hmac
self.certhash = certhash
self.trace = trace
示例9: getAvailability
def getAvailability(strProvider, serviceStr, bidId):
messageGetAvailability = Message('')
messageGetAvailability.setMethod(Message.GET_AVAILABILITY)
messageGetAvailability.setParameter('Provider', strProvider)
messageGetAvailability.setParameter('Service', serviceStr)
messageGetAvailability.setParameter('Bid', bidId)
return messageGetAvailability
示例10: send_availability
def send_availability(strProv,strResource, quantity):
messageAvail = Message('')
messageAvail.setMethod(Message.SEND_AVAILABILITY)
messageAvail.setParameter('Provider', strProv)
messageAvail.setParameter('Resource', strResource)
messageAvail.setParameter('Quantity', quantity)
return messageAvail
示例11: verifyPurchaseMessage
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)
示例12: createFromValues
def createFromValues(self, options, certs, hostname, ip, port):
self.certchain = []
chainlength = 0
for cert in certs:
derobj = ssl.PEM_cert_to_DER_cert(cert)
chainlength += len(derobj)
self.certchain.append(derobj)
Message.createFromValues(self, messageTypes['CERT_VERIFY_REQUEST'], 4 + chainlength + len(hostname) + len(ip) + len(str(port)))
self.options = options
self.hostname = hostname
self.ip = ip
self.port = port
示例13: createFromValues
def createFromValues(self, taskid, ts, hmac, certchain, trace):
# Convert certs to DER
self.certchain = []
for cert in certchain[:min(255,len(certchain))]:
self.certchain.append(ssl.PEM_cert_to_DER_cert(cert))
certlength = sum(len(x) for x in self.certchain)
# set message type and length ( 41 Bytes for taskid, ts, hmac and number of certificates
# plus length of trace and length of cert chain.
Message.createFromValues(self, messageTypes['TASK_REPLY_NEW_CERT'], 41 + len(trace) + certlength)
self.taskid = taskid
self.ts = ts
self.hmac = hmac
self.trace = trace
示例14: __getitem__
def __getitem__(self, index):
if type(index) == type(""):
self.chdir(index)
return self
if type(index) == type(()): index, preview = index
else: preview = false
if preview: resp, data = self.con.query("fetch", (index, '(FLAGS RFC822.HEADER RFC822.SIZE)'))
else: resp, data = self.con.query("fetch", (index, '(FLAGS RFC822 RFC822.SIZE)'))
m = Message(StringIO(data[0][1]), preview)
m.unique_num = int(index)
m.Size = int(data[1][find(data[1], "RFC822.SIZE")+11:-1])
m.SizeStr = bytesizestr(m.Size)
return m
示例15: run
def run(self):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('', self.port))
while True:
data, ip_addr = s.recvfrom(1024)
incomeMessage = Message()
incomeMessage.decapsulate(data)
# print (incomeMessage.header.type)
# print (incomeMessage.header.length)
# start a new thread to handle message
_thread.start_new_thread(self.handleMessage, (incomeMessage, ip_addr))