<s> from __future__ import absolute_import , unicode_literals <EOL> import copy <EOL> import re <EOL> from xml . sax . saxutils import escape as _xmlescape <EOL> try : <EOL> import base64 , binascii <EOL> except ImportError : <EOL> base64 = binascii = None <EOL> else : <EOL> _base64decode = getattr ( base64 , '<STR_LIT>' , base64 . decodestring ) <EOL> try : <EOL> from html . entities import name2codepoint , entitydefs <EOL> except ImportError : <EOL> from htmlentitydefs import name2codepoint , entitydefs <EOL> from . html import _cp1252 <EOL> from . namespaces import _base , cc , dc , georss , itunes , mediarss , psc <EOL> from . sanitizer import _sanitizeHTML , _HTMLSanitizer <EOL> from . util import FeedParserDict <EOL> from . urls import _urljoin , _makeSafeAbsoluteURI , _resolveRelativeURIs <EOL> bytes_ = type ( b'<STR_LIT>' ) <EOL> try : <EOL> chr = unichr <EOL> except NameError : <EOL> pass <EOL> class _FeedParserMixin ( <EOL> _base . Namespace , <EOL> cc . Namespace , <EOL> dc . Namespace , <EOL> georss . Namespace , <EOL> itunes . Namespace , <EOL> mediarss . Namespace , <EOL> psc . Namespace , <EOL> ) : <EOL> namespaces = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:content>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:email>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:image>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:l>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:str>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> _matchnamespaces = { } <EOL> can_be_relative_uri = set ( [ '<STR_LIT>' , '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:url>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> can_contain_relative_uris = set ( [ '<STR_LIT:content>' , '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT:info>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:description>' ] ) <EOL> can_contain_dangerous_markup = set ( [ '<STR_LIT:content>' , '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT:info>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:description>' ] ) <EOL> html_types = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self ) : <EOL> if not self . _matchnamespaces : <EOL> for k , v in self . namespaces . items ( ) : <EOL> self . _matchnamespaces [ k . lower ( ) ] = v <EOL> self . feeddata = FeedParserDict ( ) <EOL> self . entries = [ ] <EOL> self . version = '<STR_LIT>' <EOL> self . namespacesInUse = { } <EOL> self . infeed = <NUM_LIT:0> <EOL> self . inentry = <NUM_LIT:0> <EOL> self . incontent = <NUM_LIT:0> <EOL> self . intextinput = <NUM_LIT:0> <EOL> self . inimage = <NUM_LIT:0> <EOL> self . inauthor = <NUM_LIT:0> <EOL> self . incontributor = <NUM_LIT:0> <EOL> self . inpublisher = <NUM_LIT:0> <EOL> self . insource = <NUM_LIT:0> <EOL> self . sourcedata = FeedParserDict ( ) <EOL> self . contentparams = FeedParserDict ( ) <EOL> self . _summaryKey = None <EOL> self . namespacemap = { } <EOL> self . elementstack = [ ] <EOL> self . basestack = [ ] <EOL> self . langstack = [ ] <EOL> self . svgOK = <NUM_LIT:0> <EOL> self . title_depth = - <NUM_LIT:1> <EOL> self . depth = <NUM_LIT:0> <EOL> if self . lang : <EOL> self . feeddata [ '<STR_LIT>' ] = self . lang . replace ( '<STR_LIT:_>' , '<STR_LIT:->' ) <EOL> self . property_depth_map = { } <EOL> super ( _FeedParserMixin , self ) . __init__ ( ) <EOL> def unknown_starttag ( self , tag , attrs ) : <EOL> self . depth += <NUM_LIT:1> <EOL> attrs = [ self . _normalize_attributes ( attr ) for attr in attrs ] <EOL> attrsD = dict ( attrs ) <EOL> baseuri = attrsD . get ( '<STR_LIT>' , attrsD . get ( '<STR_LIT>' ) ) or self . baseuri <EOL> if isinstance ( baseuri , bytes_ ) : <EOL> baseuri = baseuri . decode ( self . encoding , '<STR_LIT:ignore>' ) <EOL> if self . baseuri : <EOL> self . baseuri = _makeSafeAbsoluteURI ( self . baseuri , baseuri ) or self . baseuri <EOL> else : <EOL> self . baseuri = _urljoin ( self . baseuri , baseuri ) <EOL> lang = attrsD . get ( '<STR_LIT>' , attrsD . get ( '<STR_LIT>' ) ) <EOL> if lang == '<STR_LIT>' : <EOL> lang = None <EOL> elif lang is None : <EOL> lang = self . lang <EOL> if lang : <EOL> if tag in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . feeddata [ '<STR_LIT>' ] = lang . replace ( '<STR_LIT:_>' , '<STR_LIT:->' ) <EOL> self . lang = lang <EOL> self . basestack . append ( self . baseuri ) <EOL> self . langstack . append ( lang ) <EOL> for prefix , uri in attrs : <EOL> if prefix . startswith ( '<STR_LIT>' ) : <EOL> self . trackNamespace ( prefix [ <NUM_LIT:6> : ] , uri ) <EOL> elif prefix == '<STR_LIT>' : <EOL> self . trackNamespace ( None , uri ) <EOL> if self . incontent and not self . contentparams . get ( '<STR_LIT:type>' , '<STR_LIT>' ) . endswith ( '<STR_LIT>' ) : <EOL> if tag in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return <EOL> self . contentparams [ '<STR_LIT:type>' ] = '<STR_LIT>' <EOL> if self . incontent and self . contentparams . get ( '<STR_LIT:type>' ) == '<STR_LIT>' : <EOL> if tag . find ( '<STR_LIT::>' ) != - <NUM_LIT:1> : <EOL> prefix , tag = tag . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> namespace = self . namespacesInUse . get ( prefix , '<STR_LIT>' ) <EOL> if tag == '<STR_LIT>' and namespace == '<STR_LIT>' : <EOL> attrs . append ( ( '<STR_LIT>' , namespace ) ) <EOL> if tag == '<STR_LIT>' and namespace == '<STR_LIT>' : <EOL> attrs . append ( ( '<STR_LIT>' , namespace ) ) <EOL> if tag == '<STR_LIT>' : <EOL> self . svgOK += <NUM_LIT:1> <EOL> return self . handle_data ( '<STR_LIT>' % ( tag , self . strattrs ( attrs ) ) , escape = <NUM_LIT:0> ) <EOL> if tag . find ( '<STR_LIT::>' ) != - <NUM_LIT:1> : <EOL> prefix , suffix = tag . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> else : <EOL> prefix , suffix = '<STR_LIT>' , tag <EOL> prefix = self . namespacemap . get ( prefix , prefix ) <EOL> if prefix : <EOL> prefix = prefix + '<STR_LIT:_>' <EOL> if ( not prefix ) and tag not in ( '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT:description>' , '<STR_LIT:name>' ) : <EOL> self . intextinput = <NUM_LIT:0> <EOL> if ( not prefix ) and tag not in ( '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT:description>' , '<STR_LIT:url>' , '<STR_LIT>' , '<STR_LIT:width>' , '<STR_LIT>' ) : <EOL> self . inimage = <NUM_LIT:0> <EOL> methodname = '<STR_LIT>' + prefix + suffix <EOL> try : <EOL> method = getattr ( self , methodname ) <EOL> return method ( attrsD ) <EOL> except AttributeError : <EOL> unknown_tag = prefix + suffix <EOL> if len ( attrsD ) == <NUM_LIT:0> : <EOL> return self . push ( unknown_tag , <NUM_LIT:1> ) <EOL> else : <EOL> context = self . _getContext ( ) <EOL> context [ unknown_tag ] = attrsD <EOL> def unknown_endtag ( self , tag ) : <EOL> if tag . find ( '<STR_LIT::>' ) != - <NUM_LIT:1> : <EOL> prefix , suffix = tag . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> else : <EOL> prefix , suffix = '<STR_LIT>' , tag <EOL> prefix = self . namespacemap . get ( prefix , prefix ) <EOL> if prefix : <EOL> prefix = prefix + '<STR_LIT:_>' <EOL> if suffix == '<STR_LIT>' and self . svgOK : <EOL> self . svgOK -= <NUM_LIT:1> <EOL> methodname = '<STR_LIT>' + prefix + suffix <EOL> try : <EOL> if self . svgOK : <EOL> raise AttributeError ( ) <EOL> method = getattr ( self , methodname ) <EOL> method ( ) <EOL> except AttributeError : <EOL> self . pop ( prefix + suffix ) <EOL> if self . incontent and not self . contentparams . get ( '<STR_LIT:type>' , '<STR_LIT>' ) . endswith ( '<STR_LIT>' ) : <EOL> if tag in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return <EOL> self . contentparams [ '<STR_LIT:type>' ] = '<STR_LIT>' <EOL> if self . incontent and self . contentparams . get ( '<STR_LIT:type>' ) == '<STR_LIT>' : <EOL> tag = tag . split ( '<STR_LIT::>' ) [ - <NUM_LIT:1> ] <EOL> self . handle_data ( '<STR_LIT>' % tag , escape = <NUM_LIT:0> ) <EOL> if self . basestack : <EOL> self . basestack . pop ( ) <EOL> if self . basestack and self . basestack [ - <NUM_LIT:1> ] : <EOL> self . baseuri = self . basestack [ - <NUM_LIT:1> ] <EOL> if self . langstack : <EOL> self . langstack . pop ( ) <EOL> if self . langstack : <EOL> self . lang = self . langstack [ - <NUM_LIT:1> ] <EOL> self . depth -= <NUM_LIT:1> <EOL> def handle_charref ( self , ref ) : <EOL> if not self . elementstack : <EOL> return <EOL> ref = ref . lower ( ) <EOL> if ref in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> text = '<STR_LIT>' % ref <EOL> else : <EOL> if ref [ <NUM_LIT:0> ] == '<STR_LIT:x>' : <EOL> c = int ( ref [ <NUM_LIT:1> : ] , <NUM_LIT:16> ) <EOL> else : <EOL> c = int ( ref ) <EOL> text = chr ( c ) . encode ( '<STR_LIT:utf-8>' ) <EOL> self . elementstack [ - <NUM_LIT:1> ] [ <NUM_LIT:2> ] . append ( text ) <EOL> def handle_entityref ( self , ref ) : <EOL> if not self . elementstack : <EOL> return <EOL> if ref in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> text = '<STR_LIT>' % ref <EOL> elif ref in self . entities : <EOL> text = self . entities [ ref ] <EOL> if text . startswith ( '<STR_LIT>' ) and text . endswith ( '<STR_LIT:;>' ) : <EOL> return self . handle_entityref ( text ) <EOL> else : <EOL> try : <EOL> name2codepoint [ ref ] <EOL> except KeyError : <EOL> text = '<STR_LIT>' % ref <EOL> else : <EOL> text = chr ( name2codepoint [ ref ] ) . encode ( '<STR_LIT:utf-8>' ) <EOL> self . elementstack [ - <NUM_LIT:1> ] [ <NUM_LIT:2> ] . append ( text ) <EOL> def handle_data ( self , text , escape = <NUM_LIT:1> ) : <EOL> if not self . elementstack : <EOL> return <EOL> if escape and self . contentparams . get ( '<STR_LIT:type>' ) == '<STR_LIT>' : <EOL> text = _xmlescape ( text ) <EOL> self . elementstack [ - <NUM_LIT:1> ] [ <NUM_LIT:2> ] . append ( text ) <EOL> def handle_comment ( self , text ) : <EOL> pass <EOL> def handle_pi ( self , text ) : <EOL> pass <EOL> def handle_decl ( self , text ) : <EOL> pass <EOL> def parse_declaration ( self , i ) : <EOL> if self . rawdata [ i : i + <NUM_LIT:9> ] == '<STR_LIT>' : <EOL> k = self . rawdata . find ( '<STR_LIT>' , i ) <EOL> if k == - <NUM_LIT:1> : <EOL> k = len ( self . rawdata ) <EOL> return k <EOL> self . handle_data ( _xmlescape ( self . rawdata [ i + <NUM_LIT:9> : k ] ) , <NUM_LIT:0> ) <EOL> return k + <NUM_LIT:3> <EOL> else : <EOL> k = self . rawdata . find ( '<STR_LIT:>>' , i ) <EOL> if k >= <NUM_LIT:0> : <EOL> return k + <NUM_LIT:1> <EOL> else : <EOL> return k <EOL> def mapContentType ( self , contentType ) : <EOL> contentType = contentType . lower ( ) <EOL> if contentType == '<STR_LIT:text>' or contentType == '<STR_LIT>' : <EOL> contentType = '<STR_LIT>' <EOL> elif contentType == '<STR_LIT:html>' : <EOL> contentType = '<STR_LIT>' <EOL> elif contentType == '<STR_LIT>' : <EOL> contentType = '<STR_LIT>' <EOL> return contentType <EOL> def trackNamespace ( self , prefix , uri ) : <EOL> loweruri = uri . lower ( ) <EOL> if not self . version : <EOL> if ( prefix , loweruri ) == ( None , '<STR_LIT>' ) : <EOL> self . version = '<STR_LIT>' <EOL> elif loweruri == '<STR_LIT>' : <EOL> self . version = '<STR_LIT>' <EOL> elif loweruri == '<STR_LIT>' : <EOL> self . version = '<STR_LIT>' <EOL> if loweruri . find ( '<STR_LIT>' ) != - <NUM_LIT:1> : <EOL> uri = '<STR_LIT>' <EOL> loweruri = uri <EOL> if loweruri in self . _matchnamespaces : <EOL> self . namespacemap [ prefix ] = self . _matchnamespaces [ loweruri ] <EOL> self . namespacesInUse [ self . _matchnamespaces [ loweruri ] ] = uri <EOL> else : <EOL> self . namespacesInUse [ prefix or '<STR_LIT>' ] = uri <EOL> def resolveURI ( self , uri ) : <EOL> return _urljoin ( self . baseuri or '<STR_LIT>' , uri ) <EOL> def decodeEntities ( self , element , data ) : <EOL> return data <EOL> def strattrs ( self , attrs ) : <EOL> return '<STR_LIT>' . join ( [ '<STR_LIT>' % ( t [ <NUM_LIT:0> ] , _xmlescape ( t [ <NUM_LIT:1> ] , { '<STR_LIT:">' : '<STR_LIT>' } ) ) for t in attrs ] ) <EOL> def push ( self , element , expectingText ) : <EOL> self . elementstack . append ( [ element , expectingText , [ ] ] ) <EOL> def pop ( self , element , stripWhitespace = <NUM_LIT:1> ) : <EOL> if not self . elementstack : <EOL> return <EOL> if self . elementstack [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] != element : <EOL> return <EOL> element , expectingText , pieces = self . elementstack . pop ( ) <EOL> if self . version == '<STR_LIT>' and self . contentparams . get ( '<STR_LIT:type>' , '<STR_LIT:text>' ) == '<STR_LIT>' : <EOL> while pieces and len ( pieces ) > <NUM_LIT:1> and not pieces [ - <NUM_LIT:1> ] . strip ( ) : <EOL> del pieces [ - <NUM_LIT:1> ] <EOL> while pieces and len ( pieces ) > <NUM_LIT:1> and not pieces [ <NUM_LIT:0> ] . strip ( ) : <EOL> del pieces [ <NUM_LIT:0> ] <EOL> if pieces and ( pieces [ <NUM_LIT:0> ] == '<STR_LIT>' or pieces [ <NUM_LIT:0> ] . startswith ( '<STR_LIT>' ) ) and pieces [ - <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> depth = <NUM_LIT:0> <EOL> for piece in pieces [ : - <NUM_LIT:1> ] : <EOL> if piece . startswith ( '<STR_LIT>' ) : <EOL> depth -= <NUM_LIT:1> <EOL> if depth == <NUM_LIT:0> : <EOL> break <EOL> elif piece . startswith ( '<STR_LIT:<>' ) and not piece . endswith ( '<STR_LIT>' ) : <EOL> depth += <NUM_LIT:1> <EOL> else : <EOL> pieces = pieces [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> for ( i , v ) in enumerate ( pieces ) : <EOL> if isinstance ( v , bytes_ ) : <EOL> pieces [ i ] = v . decode ( '<STR_LIT:utf-8>' ) <EOL> output = '<STR_LIT>' . join ( pieces ) <EOL> if stripWhitespace : <EOL> output = output . strip ( ) <EOL> if not expectingText : <EOL> return output <EOL> if base64 and self . contentparams . get ( '<STR_LIT>' , <NUM_LIT:0> ) : <EOL> try : <EOL> output = _base64decode ( output ) <EOL> except binascii . Error : <EOL> pass <EOL> except binascii . Incomplete : <EOL> pass <EOL> except TypeError : <EOL> output = _base64decode ( output . encode ( '<STR_LIT:utf-8>' ) ) . decode ( '<STR_LIT:utf-8>' ) <EOL> if ( element in self . can_be_relative_uri ) and output : <EOL> if not element == '<STR_LIT:id>' or self . guidislink : <EOL> output = self . resolveURI ( output ) <EOL> if not self . contentparams . get ( '<STR_LIT>' , <NUM_LIT:0> ) : <EOL> output = self . decodeEntities ( element , output ) <EOL> if not self . version . startswith ( '<STR_LIT>' ) and self . contentparams . get ( '<STR_LIT:type>' ) == '<STR_LIT>' : <EOL> if self . lookslikehtml ( output ) : <EOL> self . contentparams [ '<STR_LIT:type>' ] = '<STR_LIT>' <EOL> try : <EOL> del self . contentparams [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> pass <EOL> try : <EOL> del self . contentparams [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> pass <EOL> is_htmlish = self . mapContentType ( self . contentparams . get ( '<STR_LIT:type>' , '<STR_LIT>' ) ) in self . html_types <EOL> if is_htmlish and RESOLVE_RELATIVE_URIS : <EOL> if element in self . can_contain_relative_uris : <EOL> output = _resolveRelativeURIs ( output , self . baseuri , self . encoding , self . contentparams . get ( '<STR_LIT:type>' , '<STR_LIT>' ) ) <EOL> if is_htmlish and SANITIZE_HTML : <EOL> if element in self . can_contain_dangerous_markup : <EOL> output = _sanitizeHTML ( output , self . encoding , self . contentparams . get ( '<STR_LIT:type>' , '<STR_LIT>' ) ) <EOL> if self . encoding and isinstance ( output , bytes_ ) : <EOL> output = output . decode ( self . encoding , '<STR_LIT:ignore>' ) <EOL> if self . encoding in ( '<STR_LIT:utf-8>' , '<STR_LIT>' ) and not isinstance ( output , bytes_ ) : <EOL> try : <EOL> output = output . encode ( '<STR_LIT>' ) . decode ( '<STR_LIT:utf-8>' ) <EOL> except ( UnicodeEncodeError , UnicodeDecodeError ) : <EOL> pass <EOL> if not isinstance ( output , bytes_ ) : <EOL> output = output . translate ( _cp1252 ) <EOL> if element in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return output <EOL> if element == '<STR_LIT:title>' and - <NUM_LIT:1> < self . title_depth <= self . depth : <EOL> return output <EOL> if self . inentry and not self . insource : <EOL> if element == '<STR_LIT:content>' : <EOL> self . entries [ - <NUM_LIT:1> ] . setdefault ( element , [ ] ) <EOL> contentparams = copy . deepcopy ( self . contentparams ) <EOL> contentparams [ '<STR_LIT:value>' ] = output <EOL> self . entries [ - <NUM_LIT:1> ] [ element ] . append ( contentparams ) <EOL> elif element == '<STR_LIT>' : <EOL> if not self . inimage : <EOL> output = output . replace ( '<STR_LIT>' , '<STR_LIT:&>' ) <EOL> output = re . sub ( "<STR_LIT>" , "<STR_LIT>" , output ) <EOL> self . entries [ - <NUM_LIT:1> ] [ element ] = output <EOL> if output : <EOL> self . entries [ - <NUM_LIT:1> ] [ '<STR_LIT>' ] [ - <NUM_LIT:1> ] [ '<STR_LIT>' ] = output <EOL> else : <EOL> if element == '<STR_LIT:description>' : <EOL> element = '<STR_LIT>' <EOL> old_value_depth = self . property_depth_map . setdefault ( self . entries [ - <NUM_LIT:1> ] , { } ) . get ( element ) <EOL> if old_value_depth is None or self . depth <= old_value_depth : <EOL> self . property_depth_map [ self . entries [ - <NUM_LIT:1> ] ] [ element ] = self . depth <EOL> self . entries [ - <NUM_LIT:1> ] [ element ] = output <EOL> if self . incontent : <EOL> contentparams = copy . deepcopy ( self . contentparams ) <EOL> contentparams [ '<STR_LIT:value>' ] = output <EOL> self . entries [ - <NUM_LIT:1> ] [ element + '<STR_LIT>' ] = contentparams <EOL> elif ( self . infeed or self . insource ) : <EOL> context = self . _getContext ( ) <EOL> if element == '<STR_LIT:description>' : <EOL> element = '<STR_LIT>' <EOL> context [ element ] = output <EOL> if element == '<STR_LIT>' : <EOL> output = re . sub ( "<STR_LIT>" , "<STR_LIT>" , output ) <EOL> context [ element ] = output <EOL> context [ '<STR_LIT>' ] [ - <NUM_LIT:1> ] [ '<STR_LIT>' ] = output <EOL> elif self . incontent : <EOL> contentparams = copy . deepcopy ( self . contentparams ) <EOL> contentparams [ '<STR_LIT:value>' ] = output <EOL> context [ element + '<STR_LIT>' ] = contentparams <EOL> return output <EOL> def pushContent ( self , tag , attrsD , defaultContentType , expectingText ) : <EOL> self . incontent += <NUM_LIT:1> <EOL> if self . lang : <EOL> self . lang = self . lang . replace ( '<STR_LIT:_>' , '<STR_LIT:->' ) <EOL> self . contentparams = FeedParserDict ( { <EOL> '<STR_LIT:type>' : self . mapContentType ( attrsD . get ( '<STR_LIT:type>' , defaultContentType ) ) , <EOL> '<STR_LIT>' : self . lang , <EOL> '<STR_LIT>' : self . baseuri } ) <EOL> self . contentparams [ '<STR_LIT>' ] = self . _isBase64 ( attrsD , self . contentparams ) <EOL> self . push ( tag , expectingText ) <EOL> def popContent ( self , tag ) : <EOL> value = self . pop ( tag ) <EOL> self . incontent -= <NUM_LIT:1> <EOL> self . contentparams . clear ( ) <EOL> return value <EOL> @ staticmethod <EOL> def lookslikehtml ( s ) : <EOL> if not ( re . search ( r'<STR_LIT>' , s ) or re . search ( r'<STR_LIT>' , s ) ) : <EOL> return <EOL> if any ( ( t for t in re . findall ( r'<STR_LIT>' , s ) if t . lower ( ) not in _HTMLSanitizer . acceptable_elements ) ) : <EOL> return <EOL> if any ( ( e for e in re . findall ( r'<STR_LIT>' , s ) if e not in entitydefs ) ) : <EOL> return <EOL> return <NUM_LIT:1> <EOL> def _mapToStandardPrefix ( self , name ) : <EOL> colonpos = name . find ( '<STR_LIT::>' ) <EOL> if colonpos != - <NUM_LIT:1> : <EOL> prefix = name [ : colonpos ] <EOL> suffix = name [ colonpos + <NUM_LIT:1> : ] <EOL> prefix = self . namespacemap . get ( prefix , prefix ) <EOL> name = prefix + '<STR_LIT::>' + suffix <EOL> return name <EOL> def _getAttribute ( self , attrsD , name ) : <EOL> return attrsD . get ( self . _mapToStandardPrefix ( name ) ) <EOL> def _isBase64 ( self , attrsD , contentparams ) : <EOL> if attrsD . get ( '<STR_LIT>' , '<STR_LIT>' ) == '<STR_LIT>' : <EOL> return <NUM_LIT:1> <EOL> if self . contentparams [ '<STR_LIT:type>' ] . startswith ( '<STR_LIT>' ) : <EOL> return <NUM_LIT:0> <EOL> if self . contentparams [ '<STR_LIT:type>' ] . endswith ( '<STR_LIT>' ) : <EOL> return <NUM_LIT:0> <EOL> if self . contentparams [ '<STR_LIT:type>' ] . endswith ( '<STR_LIT>' ) : <EOL> return <NUM_LIT:0> <EOL> return <NUM_LIT:1> <EOL> def _itsAnHrefDamnIt ( self , attrsD ) : <EOL> href = attrsD . get ( '<STR_LIT:url>' , attrsD . get ( '<STR_LIT>' , attrsD . get ( '<STR_LIT>' , None ) ) ) <EOL> if href : <EOL> try : <EOL> del attrsD [ '<STR_LIT:url>' ] <EOL> except KeyError : <EOL> pass <EOL> try : <EOL> del attrsD [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> pass <EOL> attrsD [ '<STR_LIT>' ] = href <EOL> return attrsD <EOL> def _save ( self , key , value , overwrite = False ) : <EOL> context = self . _getContext ( ) <EOL> if overwrite : <EOL> context [ key ] = value <EOL> else : <EOL> context . setdefault ( key , value ) <EOL> def _getContext ( self ) : <EOL> if self . insource : <EOL> context = self . sourcedata <EOL> elif self . inimage and '<STR_LIT:image>' in self . feeddata : <EOL> context = self . feeddata [ '<STR_LIT:image>' ] <EOL> elif self . intextinput : <EOL> context = self . feeddata [ '<STR_LIT>' ] <EOL> elif self . inentry : <EOL> context = self . entries [ - <NUM_LIT:1> ] <EOL> else : <EOL> context = self . feeddata <EOL> return context <EOL> def _save_author ( self , key , value , prefix = '<STR_LIT>' ) : <EOL> context = self . _getContext ( ) <EOL> context . setdefault ( prefix + '<STR_LIT>' , FeedParserDict ( ) ) <EOL> context [ prefix + '<STR_LIT>' ] [ key ] = value <EOL> self . _sync_author_detail ( ) <EOL> context . setdefault ( '<STR_LIT>' , [ FeedParserDict ( ) ] ) <EOL> context [ '<STR_LIT>' ] [ - <NUM_LIT:1> ] [ key ] = value <EOL> def _save_contributor ( self , key , value ) : <EOL> context = self . _getContext ( ) <EOL> context . setdefault ( '<STR_LIT>' , [ FeedParserDict ( ) ] ) <EOL> context [ '<STR_LIT>' ] [ - <NUM_LIT:1> ] [ key ] = value <EOL> def _sync_author_detail ( self , key = '<STR_LIT>' ) : <EOL> context = self . _getContext ( ) <EOL> detail = context . get ( '<STR_LIT>' % key , [ FeedParserDict ( ) ] ) [ - <NUM_LIT:1> ] <EOL> if detail : <EOL> name = detail . get ( '<STR_LIT:name>' ) <EOL> email = detail . get ( '<STR_LIT:email>' ) <EOL> if name and email : <EOL> context [ key ] = '<STR_LIT>' % ( name , email ) <EOL> elif name : <EOL> context [ key ] = name <EOL> elif email : <EOL> context [ key ] = email <EOL> else : <EOL> author , email = context . get ( key ) , None <EOL> if not author : <EOL> return <EOL> emailmatch = re . search ( r'''<STR_LIT>''' , author ) <EOL> if emailmatch : <EOL> email = emailmatch . group ( <NUM_LIT:0> ) <EOL> author = author . replace ( email , '<STR_LIT>' ) <EOL> author = author . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> author = author . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> author = author . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> author = author . strip ( ) <EOL> if author and ( author [ <NUM_LIT:0> ] == '<STR_LIT:(>' ) : <EOL> author = author [ <NUM_LIT:1> : ] <EOL> if author and ( author [ - <NUM_LIT:1> ] == '<STR_LIT:)>' ) : <EOL> author = author [ : - <NUM_LIT:1> ] <EOL> author = author . strip ( ) <EOL> if author or email : <EOL> context . setdefault ( '<STR_LIT>' % key , detail ) <EOL> if author : <EOL> detail [ '<STR_LIT:name>' ] = author <EOL> if email : <EOL> detail [ '<STR_LIT:email>' ] = email <EOL> def _addTag ( self , term , scheme , label ) : <EOL> context = self . _getContext ( ) <EOL> tags = context . setdefault ( '<STR_LIT>' , [ ] ) <EOL> if ( not term ) and ( not scheme ) and ( not label ) : <EOL> return <EOL> value = FeedParserDict ( term = term , scheme = scheme , label = label ) <EOL> if value not in tags : <EOL> tags . append ( value ) <EOL> def _start_tags ( self , attrsD ) : <EOL> self . push ( '<STR_LIT>' , <NUM_LIT:1> ) <EOL> def _end_tags ( self ) : <EOL> for term in self . pop ( '<STR_LIT>' ) . split ( '<STR_LIT:U+002C>' ) : <EOL> self . _addTag ( term . strip ( ) , None , None ) </s>
