MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / FeedParser

Class FeedParser

tools/python-3.11.9-amd64/Lib/email/feedparser.py:134–527  ·  view source on GitHub ↗

A feed-style parser of email.

Source from the content-addressed store, hash-verified

132
133
134class FeedParser:
135 """A feed-style parser of email."""
136
137 def __init__(self, _factory=None, *, policy=compat32):
138 """_factory is called with no arguments to create a new message obj
139
140 The policy keyword specifies a policy object that controls a number of
141 aspects of the parser's operation. The default policy maintains
142 backward compatibility.
143
144 """
145 self.policy = policy
146 self._old_style_factory = False
147 if _factory is None:
148 if policy.message_factory is None:
149 from email.message import Message
150 self._factory = Message
151 else:
152 self._factory = policy.message_factory
153 else:
154 self._factory = _factory
155 try:
156 _factory(policy=self.policy)
157 except TypeError:
158 # Assume this is an old-style factory
159 self._old_style_factory = True
160 self._input = BufferedSubFile()
161 self._msgstack = []
162 self._parse = self._parsegen().__next__
163 self._cur = None
164 self._last = None
165 self._headersonly = False
166
167 # Non-public interface for supporting Parser's headersonly flag
168 def _set_headersonly(self):
169 self._headersonly = True
170
171 def feed(self, data):
172 """Push more data into the parser."""
173 self._input.push(data)
174 self._call_parse()
175
176 def _call_parse(self):
177 try:
178 self._parse()
179 except StopIteration:
180 pass
181
182 def close(self):
183 """Parse all remaining data and return the root message object."""
184 self._input.close()
185 self._call_parse()
186 root = self._pop_message()
187 assert not self._msgstack
188 # Look for final set of defects
189 if root.get_content_maintype() == 'multipart' \
190 and not root.is_multipart() and not self._headersonly:
191 defect = errors.MultipartInvariantViolationDefect()

Callers 2

read_multiMethod · 0.90
parseMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected