ÿØÿàJFIFÿþ ÿÛC       ÿÛC ÿÀÿÄÿÄ"#QrÿÄÿÄ&1!A"2qQaáÿÚ ?Øy,æ/3JæÝ¹È߲؋5êXw²±ÉyˆR”¾I0ó2—PI¾IÌÚiMö¯–þrìN&"KgX:Šíµ•nTJnLK„…@!‰-ý ùúmë;ºgµŒ&ó±hw’¯Õ@”Ü— 9ñ-ë.²1<yà‚¹ïQÐU„ہ?.’¦èûbß±©Ö«Âw*VŒ) `$‰bØÔŸ’ëXÖ-ËTÜíGÚ3ð«g Ÿ§¯—Jx„–’U/ÂÅv_s(Hÿ@TñJÑãõçn­‚!ÈgfbÓc­:él[ðQe 9ÀPLbÃãCµm[5¿ç'ªjglå‡Ûí_§Úõl-;"PkÞÞÁQâ¼_Ñ^¢SŸx?"¸¦ùY騐ÒOÈ q’`~~ÚtËU¹CڒêV  I1Áß_ÿÙ ǁaWc@s dZddlZddlZddlmZmZmZejddkr\eZ e Z n e Z e Z e dZdeefdYZd efd YZejd jZejd jZejd jZdefdYZdefdYZdS(s cssselect.xpath =============== Translation of parsed CSS selectors to XPath expressions. :copyright: (c) 2007-2012 Ian Bicking and contributors. See AUTHORS for more details. :license: BSD, see LICENSE for more details. iN(tparset parse_seriest SelectorErroriicCs+|jddjd}t|||S(Ntasciitreplace(tencodetdecodetgetattr(tobjtnametdefault((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt_unicode_safe_getattrstExpressionErrorcBseZdZRS(s3Unknown or unsupported selector (eg. pseudo-class).(t__name__t __module__t__doc__(((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyR #st XPathExprcBsSeZdddedZdZdZdZdZdZdZ RS( tt*cCs||_||_||_dS(N(tpathtelementt condition(tselfRRRt star_prefix((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt__init__+s  cCs=t|jt|j}|jr9|d|j7}n|S(Ns[%s](t_unicodeRRR(RR((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt__str__0s cCsd|jj|fS(Ns%s[%s](t __class__R (R((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt__repr__6scCs/|jr"d|j|f|_n ||_|S(Ns %s and (%s)(R(RR((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt add_condition9s  cCs=|jdkrdS|jdtj|jd|_dS(NRs name() = %s(RRtGenericTranslatort xpath_literal(R((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt add_name_test@s cCs|jd7_dS(se Append '*/' to the path to keep the context constrained to a single parent. s*/N(R(R((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytadd_star_prefixHscCsTt||}|jdkr/||j7}n||_|j|_|j|_|S(Ns*/(RRRR(RtcombinertotherR((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytjoinOs   ( R RtFalseRRRRR R!R$(((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyR)s     s('+)s^[a-zA-Z_][a-zA-Z0-9_.-]*$s^[^ \t\r\n\f]+$RcBsEeZdZidd6dd6dd6dd6Zid d 6d d 6d d 6dd6dd6dd6dd6dd6ZdZdZeZeZ eZ e Z ddZ dedZdZedZdZd Zd!Zd"Zd#Zd$Zd%Zd&Zd'Zd(Zd)Zd*Zd+Zeed,Z d-Z!d.Z"d/Z#d0Z$d1Z%d2Z&d3Z'd4Z(d5Z)d6Z*d7Z+d8Z,d9Z-d:Z.e.Z/e.Z0e.Z1e.Z2e.Z3e.Z4e.Z5e.Z6e.Z7d;Z8d<Z9d=Z:d>Z;d?Z<d@Z=dAZ>dBZ?RS(Cs Translator for "generic" XML documents. Everything is case-sensitive, no assumption is made on the meaning of element names and attribute names. t descendantt tchildt>tdirect_adjacentt+tindirect_adjacentt~texiststequalst=tincludess~=t dashmatchs|=t prefixmatchs^=t suffixmatchs$=tsubstringmatchs*=t differents!=tidsxml:langsdescendant-or-self::cs&djfdt|DS(sTranslate a *group of selectors* to XPath. Pseudo-elements are not supported here since XPath only knows about "real" elements. :param css: A *group of selectors* as an Unicode string. :param prefix: This string is prepended to the XPath expression for each selector. The default makes selectors scoped to the context node’s subtree. :raises: :class:`SelectorSyntaxError` on invalid selectors, :class:`ExpressionError` on unknown/unsupported selectors, including pseudo-elements. :returns: The equivalent XPath 1.0 expression as an Unicode string. s | c3s'|]}j|dtVqdS(ttranslate_pseudo_elementsN(tselector_to_xpathtTrue(t.0tselector(tprefixR(s3/usr/lib/python2.7/site-packages/cssselect/xpath.pys s(R$R(RtcssR=((R=Rs3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt css_to_xpathscCst|dd}|s.td|fn|j|}t||jsUt|r||jr||j||j}n|pdt |S(s4Translate a parsed selector to XPath. :param selector: A parsed :class:`Selector` object. :param prefix: This string is prepended to the resulting XPath expression. The default makes selectors scoped to the context node’s subtree. :param translate_pseudo_elements: Unless this is set to ``True`` (as :meth:`css_to_xpath` does), the :attr:`~Selector.pseudo_element` attribute of the selector is ignored. It is the caller's responsibility to reject selectors with pseudo-elements, or to account for them somehow. :raises: :class:`ExpressionError` on unknown/unsupported selectors. :returns: The equivalent XPath 1.0 expression as an Unicode string. t parsed_trees"Expected a parsed selector, got %rRN( RtNonet TypeErrortxpatht isinstancet xpathexpr_clstAssertionErrortpseudo_elementtxpath_pseudo_elementR(RR<R=R8ttreeRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyR9scCstddS(sTranslate a pseudo-element. Defaults to not supporting pseudo-elements at all, but can be overridden by sub-classes. s"Pseudo-elements are not supported.N(R (RRCRG((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyRHscCst|}d|kr%d|}nad|kr>d|}nHddjgt|D](}|rTd|krrdpud|^qT}|S(Nt's'%s't"s"%s"s concat(%s)t,(RR$tsplit_at_single_quotes(tstpart((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyRs      <cCsTt|j}t|d|jd}|dkrJtd|n||S(s%Translate any parsed selector object.sxpath_%ss%s is not supported.N(ttypeR RtlowerRAR (Rtparsed_selectort type_nametmethod((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyRCs  cCsH|j|j}t|d|}||j|j|j|jS(sTranslate a combined selector.sxpath_%s_combinator(tcombinator_mappingt combinatorRRCR<t subselector(RtcombinedRVRT((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_combinedselectorscCs\|j|j}|j|j}|j|jrK|jd|jS|jdSdS(Nsnot(%s)t0(RCR<RWR RR(RtnegationRCt sub_xpath((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_negation s   cCs`d|jjdd}t||d}|sGtd|jn||j|j|S(s$Translate a functional pseudo-class.sxpath_%s_functiont-t_s!The pseudo-class :%s() is unknownN(R RR RAR RCR<(RtfunctionRT((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_functions cCs]d|jjdd}t||d}|sGtd|jn||j|jS(sTranslate a pseudo-class.sxpath_%s_pseudoR^R_sThe pseudo-class :%s is unknownN(tidentRR RAR RCR<(RtpseudoRT((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt xpath_pseudos cCs|j|j}t|d|}|jr>|jj}n |j}t|}|jrd|j|f}|ot|j}n|rd|}nd|j|}|j r|j j}n |j }||j |j ||S(s Translate an attribute selector.sxpath_attrib_%ss%s:%st@sattribute::*[name() = %s]( tattribute_operator_mappingtoperatorRtlower_case_attribute_namestattribRQt is_safe_namet namespaceRtlower_case_attribute_valuestvalueRCR<(RR<RgRTR tsafeRiRm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt xpath_attrib's        cCs(|j|j}|j|d|jS(sTranslate a class selector.s@class(RCR<txpath_attrib_includest class_name(Rtclass_selectorRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt xpath_class=scCs(|j|j}|j|d|jS(sTranslate an ID selector.s@id(RCR<txpath_attrib_equalsR7(Rt id_selectorRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt xpath_hashDscCs|j}|sd}t}n$t|}|jrB|j}n|jrvd|j|f}|opt|j}n|jd|}|s|jn|S(s'Translate a type or universal selector.Rs%s:%sR(RR:Rjtlower_case_element_namesRQRkRER (RR<RRnRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt xpath_elementIs      cCs|jd|S(s;right is a child, grand-child or further descendant of lefts/descendant-or-self::*/(R$(Rtlefttright((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_descendant_combinator`scCs|jd|S(s#right is an immediate child of leftt/(R$(RRyRz((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_child_combinatordscCs)|jd|}|j|jdS(s)right is a sibling immediately after lefts/following-sibling::sposition() = 1(R$R R(RRyRzRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt xpath_direct_adjacent_combinatorhs cCs|jd|S(s1right is a sibling after left, immediately or nots/following-sibling::(R$(RRyRz((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt"xpath_indirect_adjacent_combinatornsc Csbyt|j\}}Wn$tk r?td|jnX|rS|jn|j|dkr|r|d|}n|jd|S|r| }| }n|dkrt| }n d| }|dkrd||fg}ng}|dkr|jd|n&|dkr9|r9|jd |nd j |}|r^|j|n|S( NsInvalid series: '%r'is last() - %ssposition() = %ss+%sis(position() %s) mod %s = 0sposition() >= %ssposition() < (last() %s)s and ( Rt argumentst ValueErrorR R R!RtstrtappendR$( RRCR`tlastR tatbtb_negtexpr((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_nth_child_functionus8          cCs|j||dtS(NR(RR:(RRCR`((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_nth_last_child_functionscCs4|jdkrtdn|j||dtS(NRs"*:nth-of-type() is not implementedR (RR RR%(RRCR`((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_nth_of_type_functions  cCs:|jdkrtdn|j||dtdtS(NRs"*:nth-of-type() is not implementedRR (RR RR:R%(RRCR`((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_nth_last_of_type_functions  cCs^|jdgdgfkr4td|jn|jdj}|jd|j|S(NtSTRINGtIDENTs9Expected a single string or ident for :contains(), got %riscontains(., %s)(targument_typesR RRmRR(RRCR`Rm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_contains_functionscCs^|jdgdgfkr4td|jn|jdj}|jd|j|S(NRRs5Expected a single string or ident for :lang(), got %rislang(%s)(RR RRmRR(RRCR`Rm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_lang_functionscCs |jdS(Nsnot(parent::*)(R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_root_pseudoscCs!|j|j|jdS(Nsposition() = 1(R!R R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_first_child_pseudos  cCs!|j|j|jdS(Nsposition() = last()(R!R R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_last_child_pseudos  cCs5|jdkrtdn|j|jdS(NRs"*:first-of-type is not implementedsposition() = 1(RR R!R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_first_of_type_pseudos   cCs5|jdkrtdn|j|jdS(NRs!*:last-of-type is not implementedsposition() = last()(RR R!R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_last_of_type_pseudos   cCs!|j|j|jdS(Ns last() = 1(R R!R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_only_child_pseudos  cCs+|jdkrtdn|jdS(NRs!*:only-of-type is not implementeds last() = 1(RR R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_only_of_type_pseudos cCs |jdS(Nsnot(*) and not(string-length())(R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_empty_pseudoscCs |jdS(s:Common implementation for pseudo-classes that never match.RZ(R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytpseudo_never_matchesscCs| s t|j||S(N(RFR(RRCR Rm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_attrib_existss  cCs$|jd||j|f|S(Ns%s = %s(RR(RRCR Rm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyRts cCsP|r,|jd|||j|fn |jd||j|f|S(Nsnot(%s) or %s != %ss%s != %s(RR(RRCR Rm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_attrib_differents   cCsKt|r:|jd|||jd|dfn |jd|S(Ns:%s and contains(concat(' ', normalize-space(%s), ' '), %s)R'RZ(tis_non_whitespaceRR(RRCR Rm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyRps  % c Cs:|jd|||j|||j|df|S(Ns'%s and (%s = %s or starts-with(%s, %s))R^(RR(RRCR Rm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_attrib_dashmatchs  cCs=|r,|jd|||j|fn |jd|S(Ns%s and starts-with(%s, %s)RZ(RR(RRCR Rm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_attrib_prefixmatch#s   cCsM|r<|jd|||t|d|j|fn |jd|S(Ns/%s and substring(%s, string-length(%s)-%s) = %siRZ(RtlenR(RRCR Rm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_attrib_suffixmatch+s - cCs=|r,|jd|||j|fn |jd|S(Ns%s and contains(%s, %s)RZ(RR(RRCR Rm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_attrib_substringmatch5s   (@R RRRURft id_attributetlang_attributeR%RwRhRlRRER?R9RHt staticmethodRRCRYR]RaRdRoRsRvRxR{R}R~RR:RRRRRRRRRRRRRRRtxpath_link_pseudotxpath_visited_pseudotxpath_hover_pseudotxpath_active_pseudotxpath_focus_pseudotxpath_target_pseudotxpath_enabled_pseudotxpath_disabled_pseudotxpath_checked_pseudoRRtRRpRRRR(((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyRgs               (                 tHTMLTranslatorcBsMeZdZdZedZdZdZdZdZ dZ RS(s Translator for (X)HTML documents. Has a more useful implementation of some pseudo-classes based on HTML-specific element names and attribute names, as described in the `HTML5 specification`_. It assumes no-quirks mode. The API is the same as :class:`GenericTranslator`. .. _HTML5 specification: http://www.w3.org/TR/html5/links.html#selectors :param xhtml: If false (the default), element names and attribute names are case-insensitive. tlangcCs(||_|s$t|_t|_ndS(N(txhtmlR:RwRh(RR((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyRRs  cCs |jdS(Ns(@selected and name(.) = 'option') or (@checked and (name(.) = 'input' or name(.) = 'command')and (@type = 'checkbox' or @type = 'radio'))(R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyRYscCsq|jdgdgfkr4td|jn|jdj}|jd|j|j|jdfS(NRRs5Expected a single string or ident for :lang(), got %risancestor-or-self::*[@lang][1][starts-with(concat(translate(@%s, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), '-'), %s)]R^(RR RRmRRRRQ(RRCR`Rm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyRascCs |jdS(NsA@href and (name(.) = 'a' or name(.) = 'link' or name(.) = 'area')(R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyRoscCs |jdS(Ns ( @disabled and ( (name(.) = 'input' and @type != 'hidden') or name(.) = 'button' or name(.) = 'select' or name(.) = 'textarea' or name(.) = 'command' or name(.) = 'fieldset' or name(.) = 'optgroup' or name(.) = 'option' ) ) or ( ( (name(.) = 'input' and @type != 'hidden') or name(.) = 'button' or name(.) = 'select' or name(.) = 'textarea' ) and ancestor::fieldset[@disabled] ) (R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyRvscCs |jdS(Ns' ( @href and ( name(.) = 'a' or name(.) = 'link' or name(.) = 'area' ) ) or ( ( name(.) = 'command' or name(.) = 'fieldset' or name(.) = 'optgroup' ) and not(@disabled) ) or ( ( (name(.) = 'input' and @type != 'hidden') or name(.) = 'button' or name(.) = 'select' or name(.) = 'textarea' or name(.) = 'keygen' ) and not (@disabled or ancestor::fieldset[@disabled]) ) or ( name(.) = 'option' and not( @disabled or ancestor::optgroup[@disabled] ) ) (R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyRs( R RRRR%RRRRRR(((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyR?s     (Rtsystretcssselect.parserRRRt version_infot basestringt _basestringtunicodeRRRAR t RuntimeErrorR tobjectRtcompiletsplitRMtmatchRjRRR(((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt s"    1