annotate orpg/chat/chat_util.py @ 155:bf799efe7a8a alpha

Traipse Alpha 'OpenRPG' {091125-02} 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. !Infinite Loops return error instead of freezing the software! 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. Modified ID's to prevent non updated clients from ruining the fix.
author sirebral
date Wed, 25 Nov 2009 12:32:34 -0600
parents 1ed2feab0db9
children
rev   line source
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
1 # utility function; see Post() in chatwnd.py
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
2
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
3 import re
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 0
diff changeset
4 import string
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 0
diff changeset
5 from orpg.orpgCore import *
138
1ed2feab0db9 Traipse Alpha 'OpenRPG' {091021-00}
sirebral
parents: 71
diff changeset
6 from orpg.tools.orpg_log import logger, debug
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
7 from orpg.tools.decorators import debugging
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
8
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
9 #============================================
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
10 # simple_html_repair(string)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
11 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
12 # Crude html/xml parser/verifier.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
13 # Catches many mistyped and/or malformed
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
14 # html tags and prevents them from causing
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
15 # issues with the chat display (see chatwnd.py)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
16 # DOES NOT catch misused but properly formated
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
17 # html like <script> or <li> which are known
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
18 # to cause issues with the chat display
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
19 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
20 # Created 04-25-2005 by Snowdog
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 0
diff changeset
21 #=============================================
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
22
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 0
diff changeset
23 def simple_html_repair(string):
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
24 "Returns string with extra > symbols to isolate badly formated HTML"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
25 #walk though string checking positions of < and > tags.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
26 first_instance = string.find('<')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
27 if first_instance == -1: return string #no html, bail out.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
28
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
29 #strip string of an instances of ">>" and "<<" recursively
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
30 #while (string.find(">>") != -1):string = string.replace(">>",">")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
31 while (string.find("<<") != -1):string = string.replace("<<","<")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
32
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
33 last_start = first_instance
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
34 in_tag_flag = 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
35 a = first_instance + 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
36 while a < len(string):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
37 if string[a] == '<':
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
38 if in_tag_flag == 1:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
39 #attempt to figure out best place to put missing >
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
40 #search from last_start to current position
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
41 at_front = 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
42 for best_pos in range(last_start,a):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
43 if (str(string[best_pos]).isspace())and (at_front == 0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
44 break
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
45 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
46 at_front = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
47 best_pos = best_pos + 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
48 a = best_pos
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
49 string = string[:a]+">"+string[a:]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
50 in_tag_flag = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
51 #jump back up one character to catch the last > and reset the in_tag_flag
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
52 a = a - 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
53 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
54 in_tag_flag = 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
55 last_start = a
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
56
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
57 if string[a] == '>':
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
58 last_start = a #found a closing tag, move start of scan block up.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
59 in_tag_flag = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
60 if (a >= (len(string)-1))and(in_tag_flag == 1):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
61 #at end of string and need a closing tag marker
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
62 string = string +">"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
63 a = a+1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
64
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
65 #strip string of an instances of "<>"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
66 string = string.replace("<>","")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
67
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
68 #sanity check. Count the < and > characters, if there arn't enough > chars
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
69 #tack them on the end to avoid open-tag conditions
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
70 diff = string.count('<') - string.count('>')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
71 if diff > 0:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
72 for d in range(1,diff):
138
1ed2feab0db9 Traipse Alpha 'OpenRPG' {091021-00}
sirebral
parents: 71
diff changeset
73 string = string+">"
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 0
diff changeset
74 return string
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
75
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
76 # Depricated! Might as well use the already made component.get('xml')
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 0
diff changeset
77 def strip_unicode(txt):
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
78 for i in xrange(len(txt)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
79 if txt[i] not in string.printable:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
80 try:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
81 txt = txt.replace(txt[i], '&#' + str(ord(txt[i])) + ';')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
82 except:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
83 txt = txt.replace(txt[i], '{?}')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
84 return txt
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
85
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
86 #================================================
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
87 # strip_script_tags(string)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
88 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
89 # removes all script tags (start and end)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
90 # 04-26-2005 Snowdog
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 0
diff changeset
91 #================================================
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
92
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
93 def strip_script_tags(string):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
94 #kill the <script> issue
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
95 p = re.compile( '<(\s*)(/*)[Ss][Cc][Rr][Ii][Pp][Tt](.*?)>')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
96 string = p.sub( "<!-- script tag removed //-->", string)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
97 return string
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
98
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
99 #================================================
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
100 # strip_li_tags(string)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
101 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
102 # removes all li tags (start and end)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
103 # 05-13-2005
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
104 #================================================
138
1ed2feab0db9 Traipse Alpha 'OpenRPG' {091021-00}
sirebral
parents: 71
diff changeset
105
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
106 def strip_li_tags(string):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
107 #kill the <li> issue
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
108 string = re.sub( r'<(\s*)[Ll][Ii](.*?)>', r'<b><font color="#000000" size=+1>*</font></b> ', string)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
109 string = re.sub( r'<(/*)[Ll][Ii](.*?)>', r'<br />', string)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
110 return string
138
1ed2feab0db9 Traipse Alpha 'OpenRPG' {091021-00}
sirebral
parents: 71
diff changeset
111
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
112 #================================================
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
113 # strip_body_tags(string)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
114 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
115 # removes all body tags (start and end) from messages
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
116 # should not break the setting of custom background colors
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
117 # through legitimate means such as the OpenRPG settings.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
118 # 07-27-2005 by mDuo13
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
119 #================================================
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
120
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
121 def strip_body_tags(string):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
122 bodytag_regex = re.compile(r"""<\/?body.*?>""", re.I)
138
1ed2feab0db9 Traipse Alpha 'OpenRPG' {091021-00}
sirebral
parents: 71
diff changeset
123 string = re.sub(bodytag_regex, "", string)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
124 return string
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
125
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
126 #================================================
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
127 # strip_misalignment_tags(string)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
128 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
129 # removes the alignment aspect of <p> tags, since
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
130 # simply closing one doesn't actually fix the text
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
131 # alignment. (I'm assuming this is a bug in wxWindows'
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
132 # html parser.)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
133 # However, closing <center> tags does
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
134 # return the text to its normal alignment, so this
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
135 # algorithm simply closes them, allowing them to be
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
136 # used legitimately without causing much annoyance.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
137 # 07-27-2005 mDuo13
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 0
diff changeset
138 #================================================
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
139
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
140 def strip_misalignment_tags(string):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
141 alignment_regex = re.compile(r"""<p([^>]*?)align\s*=\s*('.*?'|".*?"|[^\s>]*)(.*?)>""", re.I)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
142 string = re.sub(alignment_regex, "<p\\1\\3>", string)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
143
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
144 center_regex = re.compile(r"""<center.*?>""", re.I)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
145 endcenter_regex = re.compile(r"""</center.*?>""", re.I)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
146 num_centertags = center_regex.findall(string)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
147 num_endcentertags = endcenter_regex.findall(string)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
148 if num_centertags > num_endcentertags:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
149 missing_tags = len(num_centertags) - len(num_endcentertags)
138
1ed2feab0db9 Traipse Alpha 'OpenRPG' {091021-00}
sirebral
parents: 71
diff changeset
150 string = string + missing_tags*"</center>"#yes, you can do this.
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
151 return string
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
152
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
153 #================================================
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
154 # strip_img_tags(string)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
155 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
156 # removes all img tags (start and end)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
157 # 05-13-2005
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
158 # redone 07-11-2005 by mDuo13
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 0
diff changeset
159 #================================================
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
160
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
161 def strip_img_tags(string):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
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.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
163 #p = re.sub( r'<(\s*)(/*)[Ii][Mm][Gg][ ][Ss][Rr][Cc][=](.*?)>', r'<!-- img tag removed //--> <a href=\3>\3</a>', string)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
164
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
165 #this regex is substantially more powerful than the one above
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
166 img_tag_regex = re.compile(r"""<img.*?src\s*?=\s*('.*?'|".*?"|[^\s>]*).*?>""", re.I)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
167 #this is what replaces the regex match. the \\1 refers to the URL from the previous string
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
168 img_repl_str = "<a href=\\1>[img]</a>"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
169
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
170 #replaces all instances of images in the string with links
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
171 p = re.sub(img_tag_regex, img_repl_str, string)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 138
diff changeset
172 return p