src/reportlab/lib/utils.py
changeset 3349 b67514b01536
parent 3328 4d7f836cd947
child 3355 cc00d31bc99e
equal deleted inserted replaced
3348:d44de6313b58 3349:b67514b01536
  1127         A[e] += msg
  1127         A[e] += msg
  1128     else:
  1128     else:
  1129         A.append(msg)
  1129         A.append(msg)
  1130     v.args = tuple(A)
  1130     v.args = tuple(A)
  1131     raise t,v,b
  1131     raise t,v,b
       
  1132     
       
  1133 def escapeOnce(data):
       
  1134     """Ensure XML output is escaped just once, irrespective of input
       
  1135 
       
  1136     >>> escapeOnce('A & B')
       
  1137     'A & B'
       
  1138     >>> escapeOnce('C & D')
       
  1139     'C & D'
       
  1140     >>> escapeOnce('E & F')
       
  1141     'E & F'
       
  1142 
       
  1143     """
       
  1144     data = data.replace("&", "&")
       
  1145 
       
  1146     #...but if it was already escaped, make sure it
       
  1147     # is not done twice....this will turn any tags
       
  1148     # back to how they were at the start.
       
  1149     data = data.replace("&", "&")
       
  1150     data = data.replace(">", ">")
       
  1151     data = data.replace("<", "<")
       
  1152     data = data.replace("&#", "&#")
       
  1153 
       
  1154     #..and just in case someone had double-escaped it, do it again
       
  1155     data = data.replace("&", "&")
       
  1156     data = data.replace(">", ">")
       
  1157     data = data.replace("<", "<")
       
  1158     return data
       
  1159