本文整理汇总了Python中MessageParser.MessageParser.getType方法的典型用法代码示例。如果您正苦于以下问题:Python MessageParser.getType方法的具体用法?Python MessageParser.getType怎么用?Python MessageParser.getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageParser.MessageParser
的用法示例。
在下文中一共展示了MessageParser.getType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _writeMessageToSocket
# 需要导入模块: from MessageParser import MessageParser [as 别名]
# 或者: from MessageParser.MessageParser import getType [as 别名]
def _writeMessageToSocket(self, data, rewrite=False, nextPart=0, destAddresses=None):
def getWord(type):
""" Used to create logging text only """
if type:
return '(type: %s)' % type
else:
return '(type: UNKNOWN)'
"""
if type == 'SVC':
return '(type: SVC)'
elif type == 'AFTN':
return '(type: AFTN)'
elif type == 'RF':
return '(type: RF)'
elif type == 'RQ':
return '(type: RQ)'
elif type == 'RQM_OK':
return '(type: RQM_OK)'
elif type == 'RQM_UNK':
return '(type: RQM_UNK)'
elif type == 'RQF_OK':
return '(type: RQF_OK)'
elif type == 'RQF_UNK':
return '(type: RQF_UNK)'
else:
return '(type: UNKNOWN)'
"""
mm = self.mm
if len(data) >= 1:
if not rewrite:
self.logger.info("%d new bulletin will be sent" % len(data))
else:
self.logger.info("%d new bulletin will be resent (ack not received / reconnexion)" % len(data))
for index in range(len(data)):
if nextPart == 0:
# We will have access to the first part of the message here (big or not)
mp = MessageParser(data[index], mm, self.logger, True)
mm.header, mm.type = mp.getHeader(), mp.getType()
self.logger.debug("Header: %s, Type: %s" % (mm.header, mm.type))
if mm.header== None and mm.type==None:
self.logger.info(data[index])
self.logger.error("Header %s is not in %s" % (mm.header, mm.routingTable))
if self.slow:
time.sleep(10)
os.unlink(self.dataFromFiles[0][1])
self.logger.info("%s has been erased", os.path.basename(self.dataFromFiles[0][1]))
del self.dataFromFiles[0]
mm.clearPartsToSend()
continue
elif mm.header == None and mm.type=='SVC':
#FIXME: Is it possible to rewrite Service Message?
# If so, the CSN must not change!
mm.setFilingTime()
mm.nextCSN()
messageAFTN = MessageAFTN(self.logger, data[index], mm.stationID, mm.address, MessageAFTN.PRIORITIES[2],
destAddresses or [mm.otherAddress], mm.CSN, mm.filingTime, mm.dateTime)
#self.logger.debug('\n' + messageAFTN.message)
#messageAFTN.setLogger(None)
#mm.archiveObject(self.archivePath + mm.CSN, messageAFTN)
elif mm.header == None and mm.type in ['RQ', 'RF']:
# We will never have to sent such a message, it is only
# there for tests purposes
mm.setFilingTime()
mm.nextCSN()
messageAFTN = MessageAFTN(self.logger, data[index], mm.stationID, mm.address, MessageAFTN.PRIORITIES[2],
destAddresses or [mm.otherAddress], mm.CSN, mm.filingTime, mm.dateTime)
#self.logger.debug('\n' + messageAFTN.message)
#messageAFTN.setLogger(None)
#mm.archiveObject(self.archivePath + mm.CSN, messageAFTN)
elif mm.header == None and mm.type in MessageParser.REPLY_TYPES:
mm.setFilingTime()
mm.nextCSN()
messageAFTN = MessageAFTN(self.logger, data[index], mm.stationID, mm.address, MessageAFTN.PRIORITIES[3],
destAddresses, mm.CSN, mm.filingTime, mm.dateTime)
#self.logger.debug('\n' + messageAFTN.message)
#messageAFTN.setLogger(None)
#mm.archiveObject(self.archivePath + mm.CSN, messageAFTN)
elif mm.type == 'PRI_DESTADD_TEXT':
mm.destAddress = mp.destAddress
if mm.destAddress:
mm.priority = mp.priority
mm.setFilingTime()
mm.nextCSN()
messageAFTN = MessageAFTN(self.logger, mp.text, mm.stationID, mm.address, mm.priority, mm.destAddress, mm.CSN, mm.filingTime, mm.dateTime)
else:
if mm.isFromDisk():
try:
self.logger.warning("%s has been erased (no valid destination address)", os.path.basename(self.dataFromFiles[0][1]))
os.unlink(self.dataFromFiles[0][1])
except OSError, e:
(type, value, tb) = sys.exc_info()
self.logger.error("Unable to unlink %s ! Type: %s, Value: %s" % (self.dataFromFiles[0][1], type, value))
#.........这里部分代码省略.........
示例2: readFromSocket
# 需要导入模块: from MessageParser import MessageParser [as 别名]
# 或者: from MessageParser.MessageParser import getType [as 别名]
def readFromSocket(self):
replyAFTN = ''
mm = self.mm
buf = self.socket.recv(32768)
if len(buf):
self.logger.debug('Raw Buffer: %s' % repr(buf))
message, type = mm.parseReadBuffer(buf) # Only to find if it is an AFTN (SVC included) or Ack message
while message:
if type == 'AFTN':
##############################################################################################
# An AFTN Message has been read on the socket. It can be a SVC Message or a
# Standard Message.
##############################################################################################
self.logger.debug("AFTN Message: %s" % repr(message))
mm.messageIn = MessageAFTN(self.logger)
mm.messageIn.setMessage(message)
if not mm.messageIn.messageToValues():
# Here we have a problem because our parser is unable to parse the message. We print the message,
# get the next message if present and quit the method (no ack sent, no tid verification)
self.logger.error("Method MessageAFTN.messageToValues() has not worked correctly (returned 0)")
self.logger.error(mm.messageIn.textLines)
message, type = mm.parseReadBuffer("") # Only to find if it is an AFTN (SVC included) or Ack message
continue
self.logger.debug(mm.messageIn.textLines)
self.logger.debug('Message as it has been received:')
self.logger.debug('\n' + mm.messageIn.message)
status = mm.isItPart(mm.messageIn.textLines)
# Not part of a big message, possibly a SVC message
if status == 0:
suffix = 'NOT_SVC_NOR_AFTN'
mp = MessageParser(mm.messageIn.textLines)
textType = mp.getType()
if textType == "SVC":
##############################################################################################
# A Service Message has been read on the socket.
##############################################################################################
suffix = 'SVC'
self.logger.info("SVC Message Received(%s): %s (%s)" % (mm.messageIn.getTransmitID(), str(mm.messageIn.getTextLines()), MessageParser.names.get(mp.serviceType,
"The service type of this message is unknown. Contact NavCanada")))
#if mp.serviceType in [8, 9]:
# self.logger.info("*********************** SERVICE MESSAGE *****************************")
# self.logger.info(str(mm.messageIn.getTextLines()))
# self.logger.info("********************* END SERVICE MESSAGE ***************************")
elif textType == "AFTN":
suffix = ''
if mp.getHeader() in ['SI', 'SM']:
# Only one message will be in messages
messages = mm.completeHeader(mm.messageIn)
elif mp.getHeader():
# Only one message will be in messages
messages = ['\n'.join(mm.messageIn.textLines) + '\n']
else:
# Create headers before ingesting
messages = mm.addHeaderToMessage(mm.messageIn)
# Ingest in met px
for m in messages:
mm.ingest(m)
elif textType in ['RQ', 'RF']:
suffix = textType
# request for amis or metser
from RequestReplyAFTN import RequestReplyAFTN
import dateLib
date = dateLib.getYYGGgg()
if textType == 'RQ': # amis
addOn = 'AACN02 ANIK %s\nATTN %s\n\n' % (date, mm.messageIn.originatorAddress)
replyAFTN = 'RQM '
elif textType == 'RF': # metser
addOn = 'AACN44 CWAO %s\nATTN %s\n\n' % (date, mm.messageIn.originatorAddress)
replyAFTN = 'RQF '
self.logger.info('AFTN Request Received: Type = %s, Value = %s' % (textType, mp.request))
# We want to put the answer on amis or metser.
try:
rr = RequestReplyAFTN(mp.request, addOn, mp.sendOn, self.logger)
except:
(type, value, tb) = sys.exc_info()
self.logger.error("In RequestReplyAFTN: Type = %s, Value = %s" % (type, value))
if rr.bulletin:
self.logger.info('Reply is not empty, we will put bulletin in the queue of receiver %s and send an OK message' % rr.receiverName)
# bulletin is not empty, put it in queue and create an "OK" message
rr.putBulletinInQueue()
replyAFTN += 'OK'
else:
self.logger.info('Request is empty, we will send an UNK message')
# bulletin is empty, create an "UNK" message
replyAFTN += 'UNK'
#.........这里部分代码省略.........