Encodes HTML entities in the given string ("<" => "<"). For example, to display " hello " in a browser, we need to pass "<em>hello</em>" (otherwise "hello" in italic is displayed).
(string)
| 234 | RE_UNICODE = re.compile(r'&(#?)(x|X?)(\w+);') # É |
| 235 | |
| 236 | def encode_entities(string): |
| 237 | """ Encodes HTML entities in the given string ("<" => "<"). |
| 238 | For example, to display "<em>hello</em>" in a browser, |
| 239 | we need to pass "<em>hello</em>" (otherwise "hello" in italic is displayed). |
| 240 | """ |
| 241 | if isinstance(string, (str, unicode)): |
| 242 | string = RE_AMPERSAND.sub("&", string) |
| 243 | string = string.replace("<", "<") |
| 244 | string = string.replace(">", ">") |
| 245 | string = string.replace('"', """) |
| 246 | string = string.replace("'", "'") |
| 247 | return string |
| 248 | |
| 249 | def decode_entities(string): |
| 250 | """ Decodes HTML entities in the given string ("<" => "<"). |
no outgoing calls
no test coverage detected
searching dependent graphs…