| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
import re |
|---|
| 22 |
import string |
|---|
| 23 |
from types import StringType,UnicodeType |
|---|
| 24 |
|
|---|
| 25 |
class JJIGWFatalError(RuntimeError): |
|---|
| 26 |
pass |
|---|
| 27 |
|
|---|
| 28 |
evil_characters_re=re.compile(r"[\000-\010\013\014\016-\037]") |
|---|
| 29 |
def remove_evil_characters(s): |
|---|
| 30 |
return evil_characters_re.sub(" ",s) |
|---|
| 31 |
|
|---|
| 32 |
color_re=re.compile(r"\x03\d\d|\x0f") |
|---|
| 33 |
def strip_colors(s): |
|---|
| 34 |
return color_re.sub("",s) |
|---|
| 35 |
|
|---|
| 36 |
numeric_re=re.compile(r"\d\d\d") |
|---|
| 37 |
channel_re=re.compile(r"^[&#+!][^\000 \007 ,:\r\n]+$") |
|---|
| 38 |
nick_re=re.compile(r"^[a-zA-Z\x5b-\x60\x7b-\x7d\[\]\\`_^{|}][a-zA-Z\x5b-\x60\x7b-\x7d\[\]\\`_^{|}0-9-]*$") |
|---|
| 39 |
nick8_re=re.compile(r"^[a-zA-Z\x5b-\x60\x7b-\x7d\[\]\\`_^{|}\x80-\xff][a-zA-Z\x5b-\x60\x7b-\x7d\[\]\\`_^{|}0-9\x80-\xff-]*$") |
|---|
| 40 |
|
|---|
| 41 |
def escape_node_string(s): |
|---|
| 42 |
s=s.replace(",quot,",'"') |
|---|
| 43 |
s=s.replace(",amp,","&") |
|---|
| 44 |
s=s.replace(",apos,","'") |
|---|
| 45 |
s=s.replace(",slash,","/") |
|---|
| 46 |
s=s.replace(",lt,","<") |
|---|
| 47 |
s=s.replace(",gt,",">") |
|---|
| 48 |
s=s.replace(",at,","@") |
|---|
| 49 |
return s |
|---|
| 50 |
|
|---|
| 51 |
def unescape_node_string(s): |
|---|
| 52 |
s=s.replace('"',",quot,") |
|---|
| 53 |
s=s.replace("&",",amp,") |
|---|
| 54 |
s=s.replace("'",",apos,") |
|---|
| 55 |
s=s.replace("/",",slash,") |
|---|
| 56 |
s=s.replace("<",",lt,") |
|---|
| 57 |
s=s.replace(">",",gt,") |
|---|
| 58 |
s=s.replace("@",",at,") |
|---|
| 59 |
return s |
|---|
| 60 |
|
|---|
| 61 |
def node_to_channel(n,encoding): |
|---|
| 62 |
s=n.encode(encoding,"strict") |
|---|
| 63 |
s=escape_node_string(s) |
|---|
| 64 |
if not channel_re.match(s): |
|---|
| 65 |
raise ValueError,"Bad channel name: %r" % (s,) |
|---|
| 66 |
return s |
|---|
| 67 |
|
|---|
| 68 |
def channel_to_node(ch,encoding): |
|---|
| 69 |
s=unescape_node_string(ch) |
|---|
| 70 |
n=unicode(s,encoding,"strict") |
|---|
| 71 |
return n |
|---|
| 72 |
|
|---|
| 73 |
def node_to_nick(n,encoding,network): |
|---|
| 74 |
s=n.encode(encoding,"strict") |
|---|
| 75 |
s=escape_node_string(s) |
|---|
| 76 |
if not network.valid_nick(s): |
|---|
| 77 |
raise ValueError,"Bad nick name: %r" % (s,) |
|---|
| 78 |
return s |
|---|
| 79 |
|
|---|
| 80 |
def nick_to_node(ch,encoding): |
|---|
| 81 |
s=unescape_node_string(ch) |
|---|
| 82 |
n=unicode(s,encoding,"strict") |
|---|
| 83 |
return n |
|---|
| 84 |
|
|---|
| 85 |
irc_translate_table=string.maketrans( |
|---|
| 86 |
string.ascii_uppercase+"[]\\~", |
|---|
| 87 |
string.ascii_lowercase+"{}|^") |
|---|
| 88 |
|
|---|
| 89 |
def normalize(s): |
|---|
| 90 |
return s.translate(irc_translate_table) |
|---|
| 91 |
|
|---|
| 92 |
class ConnectionInfo: |
|---|
| 93 |
def __init__(self,socket,user): |
|---|
| 94 |
self.localip,self.localport=socket.getsockname() |
|---|
| 95 |
self.remoteip,self.remoteport=socket.getpeername() |
|---|
| 96 |
self.user=user |
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|