End all 'say' messages with a 'normal' ansi character to prevent bleedage. Also, added the beginnings of an IMC2 ansi parser.

This commit is contained in:
Greg Taylor 2009-04-25 07:13:19 +00:00
parent 0ad8c88c22
commit 9abde7b60f
5 changed files with 83 additions and 4 deletions

60
src/imc2/imc_ansi.py Normal file
View file

@ -0,0 +1,60 @@
from src import ansi
from src.ansi import BaseParser, ANSITable
class IMCANSIParser(BaseParser):
"""
This parser is per the IMC2 specification.
"""
def __init__(self):
self.ansi_subs = [
# Random
(r'~Z', ANSITable.ansi["normal"]),
# Dark Grey
(r'~D', ANSITable.ansi["hilite"] + ANSITable.ansi["black"]),
(r'~z', ANSITable.ansi["hilite"] + ANSITable.ansi["black"]),
# Grey/reset
(r'~w', ANSITable.ansi["normal"]),
(r'~d', ANSITable.ansi["normal"]),
(r'~!', ANSITable.ansi["normal"]),
# Bold/hilite
(r'~L', ANSITable.ansi["hilite"]),
# White
(r'~W', ANSITable.ansi["normal"] + ANSITable.ansi["hilite"]),
# Dark Green
(r'~g', ANSITable.ansi["normal"] + ANSITable.ansi["green"]),
# Green
(r'~G', ANSITable.ansi["hilite"] + ANSITable.ansi["green"]),
# Dark magenta
(r'~p', ANSITable.ansi["normal"] + ANSITable.ansi["magenta"]),
(r'~m', ANSITable.ansi["normal"] + ANSITable.ansi["magenta"]),
# Magenta
(r'~M', ANSITable.ansi["hilite"] + ANSITable.ansi["magenta"]),
(r'~P', ANSITable.ansi["hilite"] + ANSITable.ansi["magenta"]),
# Black
(r'~x', ANSITable.ansi["normal"] + ANSITable.ansi["black"]),
# Cyan
(r'~c', ANSITable.ansi["normal"] + ANSITable.ansi["cyan"]),
# Dark Yellow (brown)
(r'~Y', ANSITable.ansi["hilite"] + ANSITable.ansi["yellow"]),
# Yellow
(r'~y', ANSITable.ansi["normal"] + ANSITable.ansi["yellow"]),
# Dark Blue
(r'~B', ANSITable.ansi["normal"] + ANSITable.ansi["blue"]),
# Blue
(r'~C', ANSITable.ansi["hilite"] + ANSITable.ansi["blue"]),
# Dark Red
(r'~r', ANSITable.ansi["normal"] + ANSITable.ansi["red"]),
# Red
(r'~R', ANSITable.ansi["normal"] + ANSITable.ansi["red"]),
# Dark Blue
(r'~b', ANSITable.ansi["normal"] + ANSITable.ansi["blue"]),
## Formatting
(r'\\r', ANSITable.ansi["normal"]),
(r'\\n', ANSITable.ansi["return"]),
]
def parse_ansi(*args, **kwargs):
"""
Shortcut to use the IMC2 ANSI parser.
"""
return ansi.parse_ansi(parser=IMCANSIParser(), *args, **kwargs)

View file

@ -2,11 +2,15 @@
This module handles some of the -reply packets like whois-reply.
"""
from src.objects.models import Object
from src.imc2 import imc_ansi
def handle_whois_reply(packet):
try:
pobject = Object.objects.get(id=packet.target)
pobject.emit_to('Whois reply: %s' % packet.optional_data.get('text', 'Unknown'))
response_text = imc_ansi.parse_ansi(packet.optional_data.get('text',
'Unknown'))
pobject.emit_to('Whois reply from %s: %s' % (packet.origin,
response_text))
except Object.DoesNotExist:
# No match found for whois sender. Ignore it.
pass