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

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

Issue 10839: email module should not allow some header field repetitions
Patch Set: Created 8 years 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/_policybase.py ('k') | Lib/test/test_email/test_message.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 """This will be the home for the policy that hooks in the new 1 """This will be the home for the policy that hooks in the new
2 code that adds all the email6 features. 2 code that adds all the email6 features.
3 """ 3 """
4 4
5 from email._policybase import Policy, Compat32, compat32 5 from email._policybase import Policy, Compat32, compat32
6 from email.utils import _has_surrogates 6 from email.utils import _has_surrogates
7 from email.headerregistry import HeaderRegistry as HeaderRegistry 7 from email.headerregistry import HeaderRegistry as HeaderRegistry
8 8
9 __all__ = [ 9 __all__ = [
10 'Compat32', 10 'Compat32',
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 value. In this case a ValueError is raised if the input value contains 101 value. In this case a ValueError is raised if the input value contains
102 CR or LF characters. 102 CR or LF characters.
103 103
104 """ 104 """
105 if hasattr(value, 'name') and value.name.lower() == name.lower(): 105 if hasattr(value, 'name') and value.name.lower() == name.lower():
106 return (name, value) 106 return (name, value)
107 if isinstance(value, str) and len(value.splitlines())>1: 107 if isinstance(value, str) and len(value.splitlines())>1:
108 raise ValueError("Header values may not contain linefeed " 108 raise ValueError("Header values may not contain linefeed "
109 "or carriage return characters") 109 "or carriage return characters")
110 return (name, self.header_factory(name, value)) 110 return (name, self.header_factory(name, value))
111
112 def header_max_count(self, name):
113 """+
114 Returns the max_count attribute from the specialized header class
115 that would be used to construct a header of type 'name'.
116 """
117 return self.header_factory[name].max_count
111 118
112 def header_fetch_parse(self, name, value): 119 def header_fetch_parse(self, name, value):
113 """+ 120 """+
114 If the value has a 'name' attribute, it is returned to unmodified. 121 If the value has a 'name' attribute, it is returned to unmodified.
115 Otherwise the name and the value with any linesep characters removed 122 Otherwise the name and the value with any linesep characters removed
116 are passed to the header_factory method, and the resulting custom 123 are passed to the header_factory method, and the resulting custom
117 header object is returned. Any surrogateescaped bytes get turned 124 header object is returned. Any surrogateescaped bytes get turned
118 into the unicode unknown-character glyph. 125 into the unicode unknown-character glyph.
119 126
120 """ 127 """
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 return self.header_factory(name, ''.join(lines)).fold(policy=self) 177 return self.header_factory(name, ''.join(lines)).fold(policy=self)
171 return name + ': ' + self.linesep.join(lines) + self.linesep 178 return name + ': ' + self.linesep.join(lines) + self.linesep
172 179
173 180
174 default = EmailPolicy() 181 default = EmailPolicy()
175 # Make the default policy use the class default header_factory 182 # Make the default policy use the class default header_factory
176 del default.header_factory 183 del default.header_factory
177 strict = default.clone(raise_on_defect=True) 184 strict = default.clone(raise_on_defect=True)
178 SMTP = default.clone(linesep='\r\n') 185 SMTP = default.clone(linesep='\r\n')
179 HTTP = default.clone(linesep='\r\n', max_line_length=None) 186 HTTP = default.clone(linesep='\r\n', max_line_length=None)
OLDNEW
« no previous file with comments | « Lib/email/_policybase.py ('k') | Lib/test/test_email/test_message.py » ('j') | no next file with comments »

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