File: entities.py

package info (click to toggle)
zope-textindexng2 1%3A2.2.0-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,888 kB
  • ctags: 1,598
  • sloc: ansic: 6,836; python: 6,596; xml: 185; makefile: 137; sh: 41
file content (26 lines) | stat: -rw-r--r-- 713 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
###########################################################################
#
# TextIndexNG                The next generation TextIndex for Zope
#
# This software is governed by a license. See
# LICENSE.txt for the terms of this license.
#
###########################################################################

import re
from entities2uc import entitydefs

# Matches entities
entity_reg = re.compile('&(.*?);')

def handler(x):
    """ Callback to convert entity to UC """
    v = x.group(1)
    return entitydefs.get(v, '')

def convert_entities(text):
    """ replace all entities inside a unicode string """
    assert isinstance(text, unicode)
    text = entity_reg.sub(handler, text)
    return text