Mercurial > traipse_dev
comparison orpg/orpg_xml.py @ 23:551cd440acce traipse_dev
Final Dev build of the Day. Should reduce RAM usage more.
author | sirebral |
---|---|
date | Sat, 25 Jul 2009 21:05:18 -0500 |
parents | 4385a7d0efd1 |
children | c54768cffbd4 |
comparison
equal
deleted
inserted
replaced
22:88cea66228d6 | 23:551cd440acce |
---|---|
51 return t_node | 51 return t_node |
52 | 52 |
53 def strip_unicode(txt): | 53 def strip_unicode(txt): |
54 for i in xrange(len(txt)): | 54 for i in xrange(len(txt)): |
55 if txt[i] not in string.printable: | 55 if txt[i] not in string.printable: |
56 try: | 56 try: txt = txt.replace(txt[i], '&#' + str(ord(txt[i])) + ';') |
57 txt = txt.replace(txt[i], '&#' + str(ord(txt[i])) + ';') | 57 except: txt = txt.replace(txt[i], '{?}') |
58 except: | |
59 txt = txt.replace(txt[i], '{?}') | |
60 return txt | 58 return txt |
61 | 59 |
62 def strip_text(txt): | 60 def strip_text(txt): |
63 # The following block strips out 8-bit characters | 61 # The following block strips out 8-bit characters |
64 u_txt = "" | 62 u_txt = "" |
65 bad_txt_found = 0 | 63 bad_txt_found = 0 |
66 txt = strip_unicode(txt) | 64 txt = strip_unicode(txt) |
67 for c in txt: | 65 for c in txt: |
68 if ord(c) < 128: | 66 if ord(c) < 128: u_txt += c |
69 u_txt += c | 67 else: bad_txt_found = 1 |
70 else: | 68 if bad_txt_found: print "Some non 7-bit ASCII characters found and stripped" |
71 bad_txt_found = 1 | |
72 if bad_txt_found: | |
73 print "Some non 7-bit ASCII characters found and stripped" | |
74 return u_txt | 69 return u_txt |