| |
26 |
|
| |
27 |
# Protect against crappy output of some unnamed (ehm,
|
| |
28 |
# ehm, jhead) programs. Prepare tables for later use.
|
| |
29 |
nonPCData = ''
|
| |
30 |
|
| |
31 |
# additional procedure for working with Unicode -- normal
|
| |
32 |
# string.maketrans doesn't work with Unicode strings.
|
| |
33 |
# originally from
|
| |
34 |
# http://groups.google.com/group/comp.lang.python/msg/4dbebae9e040a7b3
|
| |
35 |
def maketransU(s1, s2, todel=""):
|
| |
36 |
trans_tab = dict( zip( map(ord, s1), map(ord, s2) ) )
|
| |
37 |
trans_tab.update( (ord(c),None) for c in todel )
|
| |
38 |
return trans_tab
|
| |
39 |
|
| |
40 |
# These are codes of characters which are not PCDATA
|
| |
41 |
# and so they cannot happen in XML file.
|
| |
42 |
nonPCDataRange = range(0x00,0x08)+[0x0b,0x0c]+range(0x0e,0x19)
|
| |
43 |
# The following ones are stricly speaking not incorrect (and XML
|
| |
44 |
# parse won't choke on them), but they are unprintable control
|
| |
45 |
# characters, so they will probably never happen in metadata.
|
| |
46 |
nonPCDataRange += range(0x7f,0x9f)
|
| |
47 |
for i in nonPCDataRange:
|
| |
48 |
nonPCData += chr(i)
|
| |
49 |
allchars = maketransU('','',nonPCData)
|
| |
50 |
|
| |
51 |
|
| 108 |
|
|
| 109 |
|
# ======================================================== patch matej
|
| 110 |
|
# Protect against crappy output of some unnamed (ehm,
|
| 111 |
|
# ehm, jhead) programs.
|
| 112 |
|
nonPCData = ''
|
| 113 |
|
# These are codes of characters which are not PCDATA
|
| 114 |
|
# and so they cannot happen in XML file.
|
| 115 |
|
nonPCDataRange = range(0x00,0x08)+[0x0b,0x0c]+range(0x0e,0x19)
|
| 116 |
|
# The following ones are stricly speaking not incorrect (and XML parse
|
| 117 |
|
# won't choke on them), but they are unprintable control
|
| 118 |
|
# characters, so they will probably never happen in
|
| 119 |
|
# metadata.
|
| 120 |
|
nonPCDataRange += range(0x7f,0x9f)
|
| 121 |
|
for i in nonPCDataRange:
|
| 122 |
|
nonPCData += chr(i)
|
| 123 |
|
allchars = string.maketrans('','')
|
| 124 |
|
out = out.translate(allchars,nonPCData)
|
| 125 |
|
outerr = outerr.translate(allchars,nonPCData)
|
| 126 |
|
# ======================================================== patch matej
|
| 127 |
|
|
| 128 |
|
|