Network/IRC/IrcUtilities.py

changeset 2280
8e85ca3fabe7
parent 2265
72e6f479987b
child 2302
f29e9405c851
equal deleted inserted replaced
2279:cbf90feec16f 2280:8e85ca3fabe7
21 r"""(?:[\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)""") 21 r"""(?:[\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)""")
22 __ColorRe = re.compile( 22 __ColorRe = re.compile(
23 r"""((?:\x03(?:0[0-9]|1[0-5]|[0-9])?(?:,(?:0[0-9]|1[0-5]|[0-9]))?)""" 23 r"""((?:\x03(?:0[0-9]|1[0-5]|[0-9])?(?:,(?:0[0-9]|1[0-5]|[0-9]))?)"""
24 r"""|\x02|\x03|\x13|\x15|\x16|\x17|\x1d|\x1f)""") 24 r"""|\x02|\x03|\x13|\x15|\x16|\x17|\x1d|\x1f)""")
25 25
26
26 def ircTimestamp(): 27 def ircTimestamp():
27 """ 28 """
28 Module method to generate a time stamp string. 29 Module method to generate a time stamp string.
29 30
30 @return time stamp (string) 31 @return time stamp (string)
43 Preferences.getIrc("TimestampColour"), 44 Preferences.getIrc("TimestampColour"),
44 QTime.currentTime().toString(formatString)) 45 QTime.currentTime().toString(formatString))
45 else: 46 else:
46 return "" 47 return ""
47 48
49
48 def ircFilter(msg): 50 def ircFilter(msg):
49 """ 51 """
50 Module method to make the message HTML compliant and detect URLs. 52 Module method to make the message HTML compliant and detect URLs.
51 53
52 @param msg message to process (string) 54 @param msg message to process (string)
60 parts = __ColorRe.split(msg) 62 parts = __ColorRe.split(msg)
61 msgParts = [] 63 msgParts = []
62 for part in parts: 64 for part in parts:
63 if part == "\x02": # bold 65 if part == "\x02": # bold
64 if openTags and openTags[-1] == "b": 66 if openTags and openTags[-1] == "b":
65 msgParts.append("</" + openTags.pop(-1) +">") 67 msgParts.append("</" + openTags.pop(-1) + ">")
66 else: 68 else:
67 msgParts.append("<b>") 69 msgParts.append("<b>")
68 openTags.append("b") 70 openTags.append("b")
69 elif part in ["\x03", "\x17"]: 71 elif part in ["\x03", "\x17"]:
70 if Preferences.getIrc("EnableIrcColours"): 72 if Preferences.getIrc("EnableIrcColours"):
71 if openTags and openTags[-1] == "span": 73 if openTags and openTags[-1] == "span":
72 msgParts.append("</" + openTags.pop(-1) +">") 74 msgParts.append("</" + openTags.pop(-1) + ">")
73 else: 75 else:
74 continue 76 continue
75 else: 77 else:
76 continue 78 continue
77 elif part == "\x0f": # reset 79 elif part == "\x0f": # reset
78 while openTags: 80 while openTags:
79 msgParts.append("</" + openTags.pop(-1) +">") 81 msgParts.append("</" + openTags.pop(-1) + ">")
80 elif part == "\x13": # strikethru 82 elif part == "\x13": # strikethru
81 if openTags and openTags[-1] == "s": 83 if openTags and openTags[-1] == "s":
82 msgParts.append("</" + openTags.pop(-1) +">") 84 msgParts.append("</" + openTags.pop(-1) + ">")
83 else: 85 else:
84 msgParts.append("<s>") 86 msgParts.append("<s>")
85 openTags.append("s") 87 openTags.append("s")
86 elif part in ["\x15", "\x1f"]: # underline 88 elif part in ["\x15", "\x1f"]: # underline
87 if openTags and openTags[-1] == "u": 89 if openTags and openTags[-1] == "u":
88 msgParts.append("</" + openTags.pop(-1) +">") 90 msgParts.append("</" + openTags.pop(-1) + ">")
89 else: 91 else:
90 msgParts.append("<u>") 92 msgParts.append("<u>")
91 openTags.append("u") 93 openTags.append("u")
92 elif part == "\x16": 94 elif part == "\x16":
93 # revert color not supported 95 # revert color not supported
94 continue 96 continue
95 elif part == "\x1d": # italic 97 elif part == "\x1d": # italic
96 if openTags and openTags[-1] == "i": 98 if openTags and openTags[-1] == "i":
97 msgParts.append("</" + openTags.pop(-1) +">") 99 msgParts.append("</" + openTags.pop(-1) + ">")
98 else: 100 else:
99 msgParts.append("<i>") 101 msgParts.append("<i>")
100 openTags.append("i") 102 openTags.append("i")
101 elif part.startswith("\x03"): 103 elif part.startswith("\x03"):
102 if Preferences.getIrc("EnableIrcColours"): 104 if Preferences.getIrc("EnableIrcColours"):

eric ide

mercurial