Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def handle(self, msg):
msg_type = msg.get_msg_type()
if msg_type == self._type_man.getnumber_bytype('ACK'):
cup.log.info(
'get msg_type:ACK, msg_len:%d, msg_flag:%d, msg_src:%s, '
'msg_dest:%s, uniqid:%d' %
(
msg.get_msg_len(),
msg.get_flag(),
str(msg.get_from_addr()),
str(msg.get_to_addr()),
msg.get_uniq_id()
)
)
elif msg_type == self._type_man.getnumber_bytype('KILL'):
print 'KILL'
else:
self.default_handle(msg)
@classmethod
def _handle_attachments(cls, outer, attachments):
if type(attachments) == str:
attrs = [attachments]
elif type(attachments) == list:
attrs = attachments
else:
attrs = []
for attached in attrs:
if not os.path.isfile(attached):
log.warn('attached is not a file:%s' % attached)
continue
# Guess the content type based on the file's extension. Encoding
# will be ignored, although we should check for simple things like
# gzip'd or compressed files.
ctype, encoding = mimetypes.guess_type(attached)
if ctype is None or encoding is not None:
# No guess could be made, or the file is encoded (compressed)
# use a generic bag-of-bits type.
ctype = 'application/octet-stream'
maintype, subtype = ctype.split('/', 1)
try:
if maintype == 'text':
with open(attached, 'rb') as fhandle:
# Note: we should handle calculating the charset
msg = text.MIMEText(
fhandle.read(), _subtype=subtype
def _main(argv):
"""main function"""
log.init_comlog('arrow_master', log.INFO,
_TOP_PATH + '/log/arrow_master.log',
log.ROTATION,
1024000000,
False
)
signal.signal(signal.SIGTERM, signal_handler)
if len(argv) < 2:
sys.stderr.write('should specify conf path')
sys.exit(-1)
master = Master(argv[1])
master.loop()
def _main(argv):
"""main function"""
log.init_comlog('arrow_master', log.INFO,
_TOP_PATH + '/log/arrow_master.log',
log.ROTATION,
1024000000,
False
)
signal.signal(signal.SIGTERM, signal_handler)
if len(argv) < 2:
sys.stderr.write('should specify conf path')
sys.exit(-1)
master = Master(argv[1])
master.loop()
def _cleanup_context(send_queue, peerinfo):
"""cleanup context"""
log.debug('to cleanup socket, peer:{0}'.format(peerinfo))
log.debug(
'cleanup: send_queue of socket size:{0}'.format(
send_queue.qsize()
)
)
while True:
try:
item = send_queue.get_nowait()
msg = item[2]
del msg
except queue.Empty:
break
if context is None:
def push_data(self, data):
"""
push data into the msg. Return pushed length.
Return -1 if we should shutdown the socket channel.
:raise exception:
may raise IndexError when coming msg has problems.
"""
if self._msg_finish:
log.warn('The CNetMsg has already been pushed enough data')
return 0
if len(data) == 0:
log.warn(
'You just pushed into the msg with a zero-length data'
)
return 0
sign = True
data_ind = 0
data_max = len(data)
# log.info('msg data read-order:{0}, context:{1}'.format(self._read_order,
# self.get_msg_context().get_context_info()))
data_key = self._ORDER[self._read_order]
while sign:
# One loop handle one data_key until there all the data is handled.
try:
self._data[data_key]
except KeyError:
self._data[data_key] = ''
loop_data_max = (
def _lock_release(self, b_rw_lock):
if b_rw_lock is True:
self._lock.acquire_writelock()
else:
self._lock.acquire_readlock()
try:
yield
# pylint: disable=W0703
except Exception as error:
cup.log.warn('something happend in cache:%s' % error)
finally:
if b_rw_lock is True:
self._lock.release_writelock()
else:
self._lock.release_readlock()
def login(self, username, passwords):
"""
if the smtp need login, plz call this method before you call
sendmail
"""
log.info('smtp server will login with user {0}'.format(username))
self._login_params = (username, passwords)