summaryrefslogtreecommitdiffstats
path: root/Lib/xml/sax/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/xml/sax/__init__.py')
-rw-r--r--Lib/xml/sax/__init__.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/xml/sax/__init__.py b/Lib/xml/sax/__init__.py
index 5d0fea5..324558d 100644
--- a/Lib/xml/sax/__init__.py
+++ b/Lib/xml/sax/__init__.py
@@ -23,3 +23,27 @@ from _exceptions import *
from saxutils import *
from _exceptions import SAXParseException
import xmlreader
+
+def parse( filename_or_stream, handler, errorHandler=ErrorHandler() ):
+ parser=ExpatParser()
+ parser.setContentHandler( handler )
+ parse.setErrorHandler( errorHandler )
+ parser.parse( filename_or_stream )
+
+# this may not work yet...Expat doesn't handle buffer inputs
+def parseString( string, handler, errorHandler=ErrorHandler() ):
+ try:
+ import cStringIO
+ stringio=cStringIO.StringIO
+ except ImportError:
+ import StringIO
+ stringio=StringIO.StringIO
+
+ bufsize=len( string )
+ buf=stringio( string )
+
+ parser=ExpatParser()
+ parser.setContentHandler( handler )
+ parse.setErrorHandler( errorHandler )
+ parser.parse( buf )
+