Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(25)

Side by Side Diff: Lib/email/_policybase.py

Issue 10839: email module should not allow some header field repetitions
Patch Set: Created 7 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/email/message.py ('k') | Lib/email/policy.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Policy framework for the email package. 1 """Policy framework for the email package.
2 2
3 Allows fine grained feature control of how the package parses and emits data. 3 Allows fine grained feature control of how the package parses and emits data.
4 """ 4 """
5 5
6 import abc 6 import abc
7 from email import header 7 from email import header
8 from email import charset as _charset 8 from email import charset as _charset
9 from email.utils import _has_surrogates 9 from email.utils import _has_surrogates
10 10
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 186
187 Called by handle_defect if raise_on_defect is False. This method is 187 Called by handle_defect if raise_on_defect is False. This method is
188 part of the Policy API so that Policy subclasses can implement custom 188 part of the Policy API so that Policy subclasses can implement custom
189 defect handling. The default implementation calls the append method of 189 defect handling. The default implementation calls the append method of
190 the defects attribute of obj. The objects used by the email package by 190 the defects attribute of obj. The objects used by the email package by
191 default that get passed to this method will always have a defects 191 default that get passed to this method will always have a defects
192 attribute with an append method. 192 attribute with an append method.
193 193
194 """ 194 """
195 obj.defects.append(defect) 195 obj.defects.append(defect)
196
197 def header_max_count(self, name):
198 """Return the maximum allowed number of headers named 'name'.
199
200 Called when a header is added to a Message object. If the returned
201 value is not 0 or None, and there are already a number of headers with
202 the name 'name' equal to the value returned, a ValueError is raised.
203
204 Because the default behavior of Message's __setitem__ is to append the
205 value to the list of headers, it is easy to create duplicate headers
206 without realizing it. This method allows certain headers to be limited
207 in the number of instances of that header that may be added to a
208 Message programmatically. (The limit is not observed by the parser,
209 which will faithfully produce as many headers as exist in the message
210 being parsed.)
211
212 The default implementation returns None for all header names.
213 """
214 return None
196 215
197 @abc.abstractmethod 216 @abc.abstractmethod
198 def header_source_parse(self, sourcelines): 217 def header_source_parse(self, sourcelines):
199 """Given a list of linesep terminated strings constituting the lines of 218 """Given a list of linesep terminated strings constituting the lines of
200 a single header, return the (name, value) tuple that should be stored 219 a single header, return the (name, value) tuple that should be stored
201 in the model. The input lines should retain their terminating linesep 220 in the model. The input lines should retain their terminating linesep
202 characters. The lines passed in by the email package may contain 221 characters. The lines passed in by the email package may contain
203 surrogateescaped binary data. 222 surrogateescaped binary data.
204 """ 223 """
205 raise NotImplementedError 224 raise NotImplementedError
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 # Assume it is a Header-like object. 354 # Assume it is a Header-like object.
336 h = value 355 h = value
337 if h is not None: 356 if h is not None:
338 parts.append(h.encode(linesep=self.linesep, 357 parts.append(h.encode(linesep=self.linesep,
339 maxlinelen=self.max_line_length)) 358 maxlinelen=self.max_line_length))
340 parts.append(self.linesep) 359 parts.append(self.linesep)
341 return ''.join(parts) 360 return ''.join(parts)
342 361
343 362
344 compat32 = Compat32() 363 compat32 = Compat32()
OLDNEW
« no previous file with comments | « Lib/email/message.py ('k') | Lib/email/policy.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+