Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/defusedxml/minidom.py: 67%

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

15 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.dom.minidom 

7""" 

8from __future__ import print_function, absolute_import 

9 

10from xml.dom.minidom import _do_pulldom_parse 

11from . import expatbuilder as _expatbuilder 

12from . import pulldom as _pulldom 

13 

14__origin__ = "xml.dom.minidom" 

15 

16 

17def parse( 

18 file, parser=None, bufsize=None, forbid_dtd=False, forbid_entities=True, forbid_external=True 

19): 

20 """Parse a file into a DOM by filename or file object.""" 

21 if parser is None and not bufsize: 

22 return _expatbuilder.parse( 

23 file, 

24 forbid_dtd=forbid_dtd, 

25 forbid_entities=forbid_entities, 

26 forbid_external=forbid_external, 

27 ) 

28 else: 

29 return _do_pulldom_parse( 

30 _pulldom.parse, 

31 (file,), 

32 { 

33 "parser": parser, 

34 "bufsize": bufsize, 

35 "forbid_dtd": forbid_dtd, 

36 "forbid_entities": forbid_entities, 

37 "forbid_external": forbid_external, 

38 }, 

39 ) 

40 

41 

42def parseString( 

43 string, parser=None, forbid_dtd=False, forbid_entities=True, forbid_external=True 

44): 

45 """Parse a file into a DOM from a string.""" 

46 if parser is None: 

47 return _expatbuilder.parseString( 

48 string, 

49 forbid_dtd=forbid_dtd, 

50 forbid_entities=forbid_entities, 

51 forbid_external=forbid_external, 

52 ) 

53 else: 

54 return _do_pulldom_parse( 

55 _pulldom.parseString, 

56 (string,), 

57 { 

58 "parser": parser, 

59 "forbid_dtd": forbid_dtd, 

60 "forbid_entities": forbid_entities, 

61 "forbid_external": forbid_external, 

62 }, 

63 )