Coverage for phml\utils\transform\sanitize\schema.py: 89%

9 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-30 09:38 -0600

1from dataclasses import dataclass, field 

2 

3 

4@dataclass 

5class Schema: 

6 """Dataclass of information on how to sanatize a phml tree. 

7 

8 `strip (list[str])`: The elements to strip from the tree. 

9 `protocols (dict[str, list])`: Collection of element name and allowed protocal value list 

10 `tagNames (list[str])`: List of allowed tag names. 

11 `attributes (dict[str, list[str | list[str]]])`: Collection of element name and allowed property 

12 names. 

13 `required (dict[str, str | list[str]])`: Collection of element names and their required 

14 properties and required property values. 

15 """ 

16 

17 strip: list[str] = field(default_factory=lambda: ['script']) 

18 ancestors: dict[str, list] = field( 

19 default_factory=lambda: { 

20 "tbody": ['table'], 

21 "tfoot": ['table'], 

22 "thead": ['table'], 

23 "td": ['table'], 

24 "th": ['table'], 

25 "tr": ['table'], 

26 } 

27 ) 

28 protocols: dict[str, list] = field( 

29 default_factory=lambda: { 

30 "href": ['http', 'https', 'mailto', 'xmpp', 'irc', 'ircs'], 

31 "cite": ['http', 'https'], 

32 "src": ['http', 'https'], 

33 "longDesc": ['http', 'https'], 

34 } 

35 ) 

36 tagNames: list[str] = field( 

37 default_factory=lambda: [ 

38 'h1', 

39 'h2', 

40 'h3', 

41 'h4', 

42 'h5', 

43 'h6', 

44 'br', 

45 'b', 

46 'i', 

47 'strong', 

48 'em', 

49 'a', 

50 'pre', 

51 'code', 

52 'img', 

53 'tt', 

54 'div', 

55 'ins', 

56 'del', 

57 'sup', 

58 'sub', 

59 'p', 

60 'ol', 

61 'ul', 

62 'table', 

63 'thead', 

64 'tbody', 

65 'tfoot', 

66 'blockquote', 

67 'dl', 

68 'dt', 

69 'dd', 

70 'kbd', 

71 'q', 

72 'samp', 

73 'var', 

74 'hr', 

75 'ruby', 

76 'rt', 

77 'rp', 

78 'li', 

79 'tr', 

80 'td', 

81 'th', 

82 's', 

83 'strike', 

84 'summary', 

85 'details', 

86 'caption', 

87 'figure', 

88 'figcaption', 

89 'abbr', 

90 'bdo', 

91 'cite', 

92 'dfn', 

93 'mark', 

94 'small', 

95 'span', 

96 'time', 

97 'wbr', 

98 'input', 

99 ] 

100 ) 

101 attributes: dict[str, list[str | list[str]]] = field( 

102 default_factory=lambda: { 

103 "a": ['href'], 

104 "img": ['src', 'longDesc'], 

105 "input": [['type', 'checkbox'], ['disabled', True]], 

106 "li": [['class', 'task-list-item']], 

107 "div": ['itemScope', 'itemType'], 

108 "blockquote": ['cite'], 

109 "del": ['cite'], 

110 "ins": ['cite'], 

111 "q": ['cite'], 

112 '*': [ 

113 'abbr', 

114 'accept', 

115 'acceptCharset', 

116 'accessKey', 

117 'action', 

118 'align', 

119 'alt', 

120 'ariaDescribedBy', 

121 'ariaHidden', 

122 'ariaLabel', 

123 'ariaLabelledBy', 

124 'axis', 

125 'border', 

126 'cellPadding', 

127 'cellSpacing', 

128 'char', 

129 'charOff', 

130 'charSet', 

131 'checked', 

132 'clear', 

133 'cols', 

134 'colSpan', 

135 'color', 

136 'compact', 

137 'coords', 

138 'dateTime', 

139 'dir', 

140 'disabled', 

141 'encType', 

142 'htmlFor', 

143 'frame', 

144 'headers', 

145 'height', 

146 'hrefLang', 

147 'hSpace', 

148 'isMap', 

149 'id', 

150 'label', 

151 'lang', 

152 'maxLength', 

153 'media', 

154 'method', 

155 'multiple', 

156 'name', 

157 'noHref', 

158 'noShade', 

159 'noWrap', 

160 'open', 

161 'prompt', 

162 'readOnly', 

163 'rel', 

164 'rev', 

165 'rows', 

166 'rowSpan', 

167 'rules', 

168 'scope', 

169 'selected', 

170 'shape', 

171 'size', 

172 'span', 

173 'start', 

174 'summary', 

175 'tabIndex', 

176 'target', 

177 'title', 

178 'type', 

179 'useMap', 

180 'vAlign', 

181 'value', 

182 'vSpace', 

183 'width', 

184 'itemProp', 

185 ], 

186 } 

187 ) 

188 required: dict[str, str | list[str]] = field( 

189 default_factory=lambda: { 

190 "input": { 

191 "type": 'checkbox', 

192 "disabled": True, 

193 } 

194 } 

195 )