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

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

26 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"""Defuse XML bomb denial of service vulnerabilities 

7""" 

8from __future__ import print_function, absolute_import 

9 

10import warnings 

11 

12from .common import ( 

13 DefusedXmlException, 

14 DTDForbidden, 

15 EntitiesForbidden, 

16 ExternalReferenceForbidden, 

17 NotSupportedError, 

18 _apply_defusing, 

19) 

20 

21 

22def defuse_stdlib(): 

23 """Monkey patch and defuse all stdlib packages 

24 

25 :warning: The monkey patch is an EXPERIMENTAL feature. 

26 """ 

27 defused = {} 

28 

29 with warnings.catch_warnings(): 

30 warnings.filterwarnings("ignore", category=DeprecationWarning, module="defusedxml") 

31 from . import cElementTree 

32 from . import ElementTree 

33 from . import minidom 

34 from . import pulldom 

35 from . import sax 

36 from . import expatbuilder 

37 from . import expatreader 

38 from . import xmlrpc 

39 

40 xmlrpc.monkey_patch() 

41 defused[xmlrpc] = None 

42 

43 defused_mods = [ 

44 cElementTree, 

45 ElementTree, 

46 minidom, 

47 pulldom, 

48 sax, 

49 expatbuilder, 

50 expatreader, 

51 ] 

52 

53 for defused_mod in defused_mods: 

54 stdlib_mod = _apply_defusing(defused_mod) 

55 defused[defused_mod] = stdlib_mod 

56 

57 return defused 

58 

59 

60__version__ = "0.8.0rc2" 

61 

62__all__ = [ 

63 "DefusedXmlException", 

64 "DTDForbidden", 

65 "EntitiesForbidden", 

66 "ExternalReferenceForbidden", 

67 "NotSupportedError", 

68]