3 ms·
If the code is in a library it is not your call to decide what is satisfactory performance and what requirements are. A user of your library could decide that r
by d0mine 17y ago
If the code is in a library it is not your call to decide what is satisfactory performance and what requirements are. A user of your library could decide that running this code inside JVM (via Jython) is more important than using C extensions for speed.
Real world example, an excellent tool -- Universal Feed Parser http://www.feedparser.org/ http://www.feedparser.org/
# If a real XML parser is available, feedparser will attempt to use it. feedparser has
# been tested with the built-in SAX parser, PyXML, and libxml2. On platforms where the
# Python distribution does not come with an XML parser (such as Mac OS X 10.2 and some
# versions of FreeBSD), feedparser will quietly fall back on regex-based parsing.
try:
import xml.sax
xml.sax.make_parser(PREFERRED_XML_PARSERS) # test for valid parsers
from xml.sax.saxutils import escape as _xmlescape
_XML_AVAILABLE = 1
except:
_XML_AVAILABLE = 0
def _xmlescape(data,entities={}):
data = data.replace('&', '&')
data = data.replace('>', '>')
data = data.replace('<', '<')
for char, entity in entities:
data = data.replace(char, entity)
return data