(match, entities=entities, encoding=encoding)
| 231 | encoding = None |
| 232 | |
| 233 | def replace_entities(match, entities=entities, encoding=encoding): |
| 234 | ent = match.group() |
| 235 | if ent[1] == "#": |
| 236 | return unescape_charref(ent[2:-1], encoding) |
| 237 | |
| 238 | repl = entities.get(ent) |
| 239 | if repl is not None: |
| 240 | if hasattr(repl, "decode") and encoding is not None: |
| 241 | try: |
| 242 | repl = repl.decode(encoding) |
| 243 | except UnicodeError: |
| 244 | repl = ent |
| 245 | else: |
| 246 | repl = ent |
| 247 | |
| 248 | return repl |
| 249 | |
| 250 | return re.sub(r"&#?[A-Za-z0-9]+?;", replace_entities, data) |
| 251 |
nothing calls this directly
no test coverage detected
searching dependent graphs…