comparison orpg/chat/chat_util.py @ 138:1ed2feab0db9 alpha

Traipse Alpha 'OpenRPG' {091021-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Cleaning up for Beta) Added Bookmarks Fix to Remote Admin Commands Minor fix to text based Server Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Added 'boot' command to remote admin Added confirmation window for sent nodes Minor changes to allow for portability to an OpenSUSE linux OS Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Zoom Mouse plugin added Images added to Plugin UI Switching to Element Tree Map efficiency, from FlexiRPG Added Status Bar to Update Manager default_manifest.xml renamed to default_upmana.xml Cleaner clode for saved repositories New TrueDebug Class in orpg_log (See documentation for usage) Mercurial's hgweb folder is ported to upmana Pretty important update that can help remove thousands of dead children from your gametree. Children, <forms />, <group_atts />, <horizontal />, <cols />, <rows />, <height />, etc... are all tags now. Check your gametree and look for dead children!! New Gametree Recursion method, mapping, and context sensitivity. !!Alpha Still- Watch out for infinite loops!! New Syntax added for custom PC sheets Tip of the Day added, from Core and community Fixed Whiteboard ID to prevent random line or text deleting. Appended tr_ to ID's to prevent non updated clients from ruining the fix.
author sirebral
date Sat, 21 Nov 2009 03:19:34 -0600
parents 449a8900f9ac
children bf799efe7a8a
comparison
equal deleted inserted replaced
137:54446a995007 138:1ed2feab0db9
1 # utility function; see Post() in chatwnd.py 1 # utility function; see Post() in chatwnd.py
2 2
3 import re 3 import re
4 import string 4 import string
5 from orpg.orpgCore import * 5 from orpg.orpgCore import *
6 from orpg.tools.orpg_log import logger 6 from orpg.tools.orpg_log import logger, debug
7 from orpg.tools.decorators import debugging 7 from orpg.tools.decorators import debugging
8 8
9 #============================================ 9 #============================================
10 # simple_html_repair(string) 10 # simple_html_repair(string)
11 # 11 #
17 # html like <script> or <li> which are known 17 # html like <script> or <li> which are known
18 # to cause issues with the chat display 18 # to cause issues with the chat display
19 # 19 #
20 # Created 04-25-2005 by Snowdog 20 # Created 04-25-2005 by Snowdog
21 #============================================= 21 #=============================================
22 @debugging 22
23 def simple_html_repair(string): 23 def simple_html_repair(string):
24 "Returns string with extra > symbols to isolate badly formated HTML" 24 "Returns string with extra > symbols to isolate badly formated HTML"
25 #walk though string checking positions of < and > tags. 25 #walk though string checking positions of < and > tags.
26 first_instance = string.find('<') 26 first_instance = string.find('<')
27 if first_instance == -1: return string #no html, bail out. 27 if first_instance == -1: return string #no html, bail out.
71 if diff > 0: 71 if diff > 0:
72 for d in range(1,diff): 72 for d in range(1,diff):
73 string = string+">" 73 string = string+">"
74 return string 74 return string
75 75
76 """ Depricated! Might as well use the already made component.get('xml') 76 # Depricated! Might as well use the already made component.get('xml')
77 def strip_unicode(txt): 77 def strip_unicode(txt):
78 for i in xrange(len(txt)): 78 for i in xrange(len(txt)):
79 if txt[i] not in string.printable: 79 if txt[i] not in string.printable:
80 try: 80 try:
81 txt = txt.replace(txt[i], '&#' + str(ord(txt[i])) + ';') 81 txt = txt.replace(txt[i], '&#' + str(ord(txt[i])) + ';')
82 except: 82 except:
83 txt = txt.replace(txt[i], '{?}') 83 txt = txt.replace(txt[i], '{?}')
84 return txt 84 return txt
85 """
86 85
87 #================================================ 86 #================================================
88 # strip_script_tags(string) 87 # strip_script_tags(string)
89 # 88 #
90 # removes all script tags (start and end) 89 # removes all script tags (start and end)
91 # 04-26-2005 Snowdog 90 # 04-26-2005 Snowdog
92 #================================================ 91 #================================================
93 @debugging 92
94 def strip_script_tags(string): 93 def strip_script_tags(string):
95 #kill the <script> issue 94 #kill the <script> issue
96 p = re.compile( '<(\s*)(/*)[Ss][Cc][Rr][Ii][Pp][Tt](.*?)>') 95 p = re.compile( '<(\s*)(/*)[Ss][Cc][Rr][Ii][Pp][Tt](.*?)>')
97 string = p.sub( "<!-- script tag removed //-->", string) 96 string = p.sub( "<!-- script tag removed //-->", string)
98 return string 97 return string
101 # strip_li_tags(string) 100 # strip_li_tags(string)
102 # 101 #
103 # removes all li tags (start and end) 102 # removes all li tags (start and end)
104 # 05-13-2005 103 # 05-13-2005
105 #================================================ 104 #================================================
106 @debugging 105
107 def strip_li_tags(string): 106 def strip_li_tags(string):
108 #kill the <li> issue 107 #kill the <li> issue
109 string = re.sub( r'<(\s*)[Ll][Ii](.*?)>', r'<b><font color="#000000" size=+1>*</font></b> ', string) 108 string = re.sub( r'<(\s*)[Ll][Ii](.*?)>', r'<b><font color="#000000" size=+1>*</font></b> ', string)
110 string = re.sub( r'<(/*)[Ll][Ii](.*?)>', r'<br />', string) 109 string = re.sub( r'<(/*)[Ll][Ii](.*?)>', r'<br />', string)
111 return string 110 return string
116 # removes all body tags (start and end) from messages 115 # removes all body tags (start and end) from messages
117 # should not break the setting of custom background colors 116 # should not break the setting of custom background colors
118 # through legitimate means such as the OpenRPG settings. 117 # through legitimate means such as the OpenRPG settings.
119 # 07-27-2005 by mDuo13 118 # 07-27-2005 by mDuo13
120 #================================================ 119 #================================================
121 @debugging 120
122 def strip_body_tags(string): 121 def strip_body_tags(string):
123 bodytag_regex = re.compile(r"""<\/?body.*?>""", re.I) 122 bodytag_regex = re.compile(r"""<\/?body.*?>""", re.I)
124 string = re.sub(bodytag_regex, "", string) 123 string = re.sub(bodytag_regex, "", string)
125 return string 124 return string
126 125
135 # return the text to its normal alignment, so this 134 # return the text to its normal alignment, so this
136 # algorithm simply closes them, allowing them to be 135 # algorithm simply closes them, allowing them to be
137 # used legitimately without causing much annoyance. 136 # used legitimately without causing much annoyance.
138 # 07-27-2005 mDuo13 137 # 07-27-2005 mDuo13
139 #================================================ 138 #================================================
140 @debugging 139
141 def strip_misalignment_tags(string): 140 def strip_misalignment_tags(string):
142 alignment_regex = re.compile(r"""<p([^>]*?)align\s*=\s*('.*?'|".*?"|[^\s>]*)(.*?)>""", re.I) 141 alignment_regex = re.compile(r"""<p([^>]*?)align\s*=\s*('.*?'|".*?"|[^\s>]*)(.*?)>""", re.I)
143 string = re.sub(alignment_regex, "<p\\1\\3>", string) 142 string = re.sub(alignment_regex, "<p\\1\\3>", string)
144 143
145 center_regex = re.compile(r"""<center.*?>""", re.I) 144 center_regex = re.compile(r"""<center.*?>""", re.I)
156 # 155 #
157 # removes all img tags (start and end) 156 # removes all img tags (start and end)
158 # 05-13-2005 157 # 05-13-2005
159 # redone 07-11-2005 by mDuo13 158 # redone 07-11-2005 by mDuo13
160 #================================================ 159 #================================================
161 @debugging 160
162 def strip_img_tags(string): 161 def strip_img_tags(string):
163 #This is a Settings definable feature, Allowing users to enable or disable image display to fix the client crash due to large img posted to chat. 162 #This is a Settings definable feature, Allowing users to enable or disable image display to fix the client crash due to large img posted to chat.
164 #p = re.sub( r'<(\s*)(/*)[Ii][Mm][Gg][ ][Ss][Rr][Cc][=](.*?)>', r'<!-- img tag removed //--> <a href=\3>\3</a>', string) 163 #p = re.sub( r'<(\s*)(/*)[Ii][Mm][Gg][ ][Ss][Rr][Cc][=](.*?)>', r'<!-- img tag removed //--> <a href=\3>\3</a>', string)
165 164
166 #this regex is substantially more powerful than the one above 165 #this regex is substantially more powerful than the one above