Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/defusedxml/sax.py: 34%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

29 statements  

1# defusedxml 

2# 

3# Copyright (c) 2013 by Christian Heimes <christian@python.org> 

4# Licensed to PSF under a Contributor Agreement. 

5# See https://www.python.org/psf/license for licensing details. 

6"""Defused xml.sax 

7""" 

8from __future__ import print_function, absolute_import 

9 

10from xml.sax import InputSource as _InputSource 

11from xml.sax import ErrorHandler as _ErrorHandler 

12 

13from . import expatreader 

14 

15__origin__ = "xml.sax" 

16 

17 

18def parse( 

19 source, 

20 handler, 

21 errorHandler=_ErrorHandler(), 

22 forbid_dtd=False, 

23 forbid_entities=True, 

24 forbid_external=True, 

25): 

26 parser = make_parser() 

27 parser.setContentHandler(handler) 

28 parser.setErrorHandler(errorHandler) 

29 parser.forbid_dtd = forbid_dtd 

30 parser.forbid_entities = forbid_entities 

31 parser.forbid_external = forbid_external 

32 parser.parse(source) 

33 

34 

35def parseString( 

36 string, 

37 handler, 

38 errorHandler=_ErrorHandler(), 

39 forbid_dtd=False, 

40 forbid_entities=True, 

41 forbid_external=True, 

42): 

43 from io import BytesIO 

44 

45 if errorHandler is None: 

46 errorHandler = _ErrorHandler() 

47 parser = make_parser() 

48 parser.setContentHandler(handler) 

49 parser.setErrorHandler(errorHandler) 

50 parser.forbid_dtd = forbid_dtd 

51 parser.forbid_entities = forbid_entities 

52 parser.forbid_external = forbid_external 

53 

54 inpsrc = _InputSource() 

55 inpsrc.setByteStream(BytesIO(string)) 

56 parser.parse(inpsrc) 

57 

58 

59def make_parser(parser_list=[]): 

60 return expatreader.create_parser()