• File: feedparser.cpython-38.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python38/lib64/python3.8/email/__pycache__/feedparser.cpython-38.pyc
  • Date Modified: 10/26/2026 8:15 PM
  • File size: 10.41 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
U

ifX@sdZddgZddlZddlmZddlmZddlmZddl	m
Z
ed	Zed
Z
edZed
ZedZd
ZdZeZGdddeZGdddZGdddeZdS)aFeedParser - An email feed parser.

The feed parser implements an interface for incrementally parsing an email
message, line by line.  This has advantages for certain applications, such as
those reading email messages off a socket.

FeedParser.feed() is the primary interface for pushing new data into the
parser.  It returns when there's nothing more it can do with the available
data.  When you have no more data to push into the parser, call .close().
This completes the parsing and returns the root message object.

The other advantage of this parser is that it will never raise a parsing
exception.  Instead, when it finds something unexpected, it adds a 'defect' to
the current message.  Defects are just instances that live on the message
object's .defects attribute.

FeedParserBytesFeedParserN)errors)compat32)deque)StringIOz
\r\n|\r|\nz(\r\n|\r|\n)z(\r\n|\r|\n)\Zz%^(From |[\041-\071\073-\176]*:|[\t ])
c@s`eZdZdZddZddZddZdd	Zd
dZdd
Z	ddZ
ddZddZddZ
dS)BufferedSubFileakA file-ish object that can have new data loaded into it.

    You can also push and pop line-matching predicates onto a stack.  When the
    current predicate matches the current line, a false EOF response
    (i.e. empty string) is returned instead.  This lets the parser adhere to a
    simple abstraction -- it parses until EOF closes the current message.
    cCs$tdd|_t|_g|_d|_dS)Nr)newlineF)r_partialr_lines	_eofstack_closedselfr5/opt/alt/python38/lib64/python3.8/email/feedparser.py__init__5szBufferedSubFile.__init__cCs|j|dSN)rappend)rZpredrrrpush_eof_matcher@sz BufferedSubFile.push_eof_matchercCs
|jSr)rpoprrrrpop_eof_matcherCszBufferedSubFile.pop_eof_matchercCs<|jd||j|jd|jd|_dS)NrT)rseek	pushlines	readlinestruncaterrrrrcloseFs

zBufferedSubFile.closecCsL|js|jrdStS|j}t|jD]}||r(|j|dSq(|SNr)r
rNeedMoreDatapopleftreversedr
appendleft)rlineZateofrrrreadlineNs
zBufferedSubFile.readlinecCs|tk	st|j|dSr)r AssertionErrorr
r#rr$rrr
unreadline`szBufferedSubFile.unreadlinecCsx|j|d|kr d|kr dS|jd|j}|jd|j|ddsj|j|||dS)z$Push some new data into this object.r	
Nr)rwriterrrendswithrr)rdatapartsrrrpushes

zBufferedSubFile.pushcCs|j|dSr)r
extend)rlinesrrrrzszBufferedSubFile.pushlinescCs|Srrrrrr__iter__}szBufferedSubFile.__iter__cCs|}|dkrt|Sr)r%
StopIterationr'rrr__next__szBufferedSubFile.__next__N)__name__
__module____qualname____doc__rrrrr%r(r/rr2r4rrrrr
-sr
c@s`eZdZdZdedddZddZdd	Zd
dZdd
Z	ddZ
ddZddZddZ
dS)rzA feed-style parser of email.NpolicycCs||_d|_|dkr<|jdkr2ddlm}||_qn|j|_n2||_z||jdWntk
rld|_YnXt|_g|_	|
j|_d|_
d|_d|_dS)a_factory is called with no arguments to create a new message obj

        The policy keyword specifies a policy object that controls a number of
        aspects of the parser's operation.  The default policy maintains
        backward compatibility.

        FNr)Messager9T)r:_old_style_factoryZmessage_factoryZ
email.messager;_factory	TypeErrorr
_input	_msgstack	_parsegenr4_parse_cur_last_headersonly)rr=r:r;rrrrs$

zFeedParser.__init__cCs
d|_dS)NT)rErrrr_set_headersonlyszFeedParser._set_headersonlycCs|j||dS)zPush more data into the parser.N)r?r/_call_parserr-rrrfeedszFeedParser.feedcCs&z|Wntk
r YnXdSr)rBr3rrrrrGszFeedParser._call_parsecCsR|j||}|jr$t|dkrN|sNt	}|j
|||S)z<Parse all remaining data and return the root message object.	multipart)r?rrG_pop_messager@r&get_content_maintypeZis_multipartrZ!MultipartInvariantViolationDefectr:
handle_defect)rrootdefectrrrrs

zFeedParser.closecCsn|jr|}n|j|jd}|jr<|jdkr<|d|jrR|jd||j|||_||_	dS)Nr9zmultipart/digestzmessage/rfc822r*)
r<r=r:rCget_content_typeZset_default_typer@ZattachrrD)rmsgrrr_new_messages

zFeedParser._new_messagecCs(|j}|jr|jd|_nd|_|S)Nr*)r@rrC)rretvalrrrrKs

zFeedParser._pop_messageccs$|g}|jD]Z}|tkr&tVqt|sbt|s^t}|j	|j
||j|qn||q|
||jrg}|j}|tkrtVq|dkrq||q|j
t|dS|j
dkr|jtj|D]}|tkrtVqqq|}|j|j}|tkrDtVqqDq|j}|tkrjtVqDqjqD|dkrxq|j|qdS|j
dkr|D] }|tkrtVqqĐq|dS|j
dkr|j
}|dkrRt}|j	|j
|g}|jD]$}|tkr.tVq||q|j
t|dSt|j
dddkrt}|j	|j
|d|}t d	t!|d
}	d}
g}d}d}
|j}|tkrtVq|dkrq|	|}|r|"d
rd}
|"d}q|
rr|r^|d}t#$|}|rP|dt%|"d|d<t||j
_&d}
|j|q|j}|tkrtVqr|	|}|sr|j|qqr|j|	j|D] }|tkrtVqqq|j'dkrT|j'j(}|dkrd|j'_(n:|dk	rt#$|}|rt%|"d}|d||j'_(nD|j'j)}t*|trt#$|}|r|dt%|"d}||j'_)|j||j
|_'n|
st+||q|
r4t,}|j	|j
||j
t|g}|jD]}|tkrtVqqt||j
_(dS|
sVt-}|j	|j
|dS|rddg}ng}|jD]$}|tkrtVqn||qn|r|d}t.|}|r|t%|"dd|d<t||j
_(dSg}|jD]$}|tkrtVq||q|j
t|dS)Nrzmessage/delivery-statusmessagerJzcontent-transfer-encoding8bit)Z7bitrUZbinaryz--z(?P<sep>z4)(?P<end>--)?(?P<ws>[ \t]*)(?P<linesep>\r\n|\r|\n)?$TFendlinesepr*r)/rRr?r headerREmatchNLCRErZ MissingHeaderBodySeparatorDefectr:rMrCr(r_parse_headersrEr%Zset_payloadEMPTYSTRINGjoinrPrrArKrrLZget_boundaryZNoBoundaryInMultipartDefectstrgetlowerZ-InvalidMultipartContentTransferEncodingDefectrecompileescapegroup	NLCRE_eolsearchlenpreamblerDepilogueZ_payload
isinstancer&ZStartBoundaryNotFoundDefectZCloseBoundaryNotFoundDefect	NLCRE_bol)rZheadersr$rOr1rSrQboundaryZ	separatorZ
boundaryreZcapturing_preamblerhrWZclose_boundary_seenmoZlastlineZeolmorirVZpayload	firstlineZbolmorrrrAsb











































zFeedParser._parsegenc	Csjd}g}t|D]8\}}|ddkrR|sFt|}|j|j|q||q|rt|jj|j|dg}}|	dr|dkrt
|}|r|dt|
d}|j|qn<|t|dkr|j|dSt|}|jj|q|d}|dkr&td}|jj|q|dks8td|d|}|g}q|rf|jj|j|dS)	Nrrz 	zFrom :zMissing header name.z3_parse_headers fed line with no : and no leading WS)	enumeraterZ#FirstHeaderLineIsContinuationDefectr:rMrCrZset_rawZheader_source_parse
startswithrerfrgrdZset_unixfromr?r(ZMisplacedEnvelopeHeaderDefectZdefectsfindZInvalidHeaderDefectr&)	rr1Z
lastheaderZ	lastvaluelinenor$rOrmirrrr[sH








zFeedParser._parse_headers)N)r5r6r7r8rrrFrIrGrrRrKrAr[rrrrrs

~cs eZdZdZfddZZS)rz(Like FeedParser, but feed accepts bytes.cst|dddS)Nasciisurrogateescape)superrIdecoderH	__class__rrrIszBytesFeedParser.feed)r5r6r7r8rI
__classcell__rrrzrrs)r8__all__raZemailrZemail._policybasercollectionsriorrbrZrkreZNLCRE_crackrXr\NLobjectr r
rrrrrr<module>s(




[