예제 #1
0
파일: jsub.py 프로젝트: nandub/pygale
def handleChat(msg, file=sys.stdout, termwidth=80):
#	print 'Received message:', msg, dir(msg)
	sender_jid = msg.get_from()
	if sender_jid:
		sender = sender_jid.node + '@' + sender_jid.domain
		if sender_jid.resource:
			sender = sender + '/' + sender_jid.resource
	else:
		sender = 'unknown sender'

	subject = msg.get_subject()
	thread = msg.get_thread()
	to_jid = msg.get_to()
	if subject:
		to = to_jid.node + '.' + subject + '@' + to_jid.domain
	else:
		to = to_jid.node + '@' + to_jid.domain
	if to_jid.resource:
		to = to + '/' + to_jid.resource
	type = msg.get_type()
	body = msg.get_body()
	if not body:
		return
	else:
		body = pretty.format(body)
	date = time.strftime('%m-%d %H:%M:%S', time.localtime(time.time()))

	file.write('\r' + ('-' * termwidth) + '\n')
	header = 'To: %s' % pretty.bold_location(to)
	file.write(header + '\n')

	if body:
		file.write(body.encode('latin-1'))
	bolded_sig = "-- %s at %s --" %\
		(sender, date)
	normal_sig = "-- %s at %s --" % (sender, date)
	bolded_sig = ' ' * (termwidth-len(normal_sig)) + bolded_sig
	nonbolded_sig = ' ' * (termwidth-len(normal_sig)) + normal_sig
	if file.isatty():
		file.write(bolded_sig + '\n')
	else:
		file.write(nonbolded_sig + '\n')
	return True
예제 #2
0
파일: jsub.py 프로젝트: nandub/pygale
def handleGroupChat(msg, file=sys.stdout, termwidth=80):
	sender_jid = msg.get_from()
	if sender_jid:
		if sender_jid.resource:
			sender = sender_jid.resource
		else:
			sender = '*no-handle*'
	else:
		sender = '*unsigned*'

	subject = msg.get_subject()
	thread = msg.get_thread()
	if subject:
		to = sender_jid.node + '.' + subject + '@' + sender_jid.domain
	else:
		to = sender_jid.node + '@' + sender_jid.domain
	body = msg.get_body()
	if not body:
		return
	else:
		body = pretty.format(body)
	date = time.strftime('%m-%d %H:%M:%S', time.localtime(time.time()))

	file.write('\r' + ('-' * termwidth) + '\n')
	header = 'To: %s' % pretty.bold_location(to)
	file.write(header + '\n')

	if body:
		file.write(body.encode('latin-1'))
	bolded_sig = "-- %s at %s --" %\
		(sender, date)
	normal_sig = "-- %s at %s --" % (sender, date)
	bolded_sig = ' ' * (termwidth-len(normal_sig)) + bolded_sig
	nonbolded_sig = ' ' * (termwidth-len(normal_sig)) + normal_sig
	if file.isatty():
		file.write(bolded_sig + '\n')
	else:
		file.write(nonbolded_sig + '\n')
	return True