
\c           @   s"  d  Z  d d l Z d d l m Z d d l m Z m Z m Z m Z d d l	 m
 Z d d l m Z m Z m Z m Z m Z m Z d d l Z d d l m Z m Z d d l m Z d d	 l m Z e r'd d
 l m Z m Z m Z m  Z  m! Z! m" Z" m# Z# m$ Z$ d d l% m& Z& d d l' m( Z( n  d e) f d     YZ* d d l+ m, Z, d   Z- i d d 6d d 6e, d 6d d 6d d 6d d 6d d 6d d 6d  d! 6d" d# 6d$ d% 6d& d' 6d( d) 6d* d+ 6d, d- 6d. d/ 6d0 d1 6Z. d2 e) f d3     YZ/ e/   Z0 d4 e f d5     YZ1 d6 e) f d7     YZ2 d S(8   s   
    sphinx.search
    ~~~~~~~~~~~~~

    Create a full-text search index for offline search.

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
iN(   t   path(   t	   iteritemst
   itervaluest	   text_typet   string_types(   t   cPickle(   t   rawt   commentt   titlet   Textt   NodeVisitort   SkipNode(   t   jsdumpt
   rpartition(   t
   htmlescape(   t   splitter_code(   t   Anyt   Dictt   IOt   Iterablet   Listt   Tuplet   Typet   Set(   t   nodes(   t   BuildEnvironmentt   SearchLanguagec           B   sk   e  Z d  Z d Z d Z e   Z d Z d Z	 e
 j d  Z d   Z d   Z d   Z d   Z d   Z RS(	   sI  
    This class is the base class for search natural language preprocessors.  If
    you want to add support for a new language, you should override the methods
    of this class.

    You should override `lang` class property too (e.g. 'en', 'fr' and so on).

    .. attribute:: stopwords

       This is a set of stop words of the target language.  Default `stopwords`
       is empty.  This word is used for building index and embedded in JS.

    .. attribute:: js_stemmer_code

       Return stemmer class of JavaScript version.  This class' name should be
       ``Stemmer`` and this class must have ``stemWord`` method.  This string is
       embedded as-is in searchtools.js.

       This class is used to preprocess search word which Sphinx HTML readers
       type, before searching index. Default implementation does nothing.
    s   
/**
 * Dummy stemmer for languages without stemming rules.
 */
var Stemmer = function() {
  this.stemWord = function(w) {
    return w;
  }
}
s   (?u)\w+c         C   s   | |  _  |  j |  d  S(   N(   t   optionst   init(   t   selfR   (    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyt   __init__F   s    	c         C   s   d S(   sK   
        Initialize the class with the options the user has given.
        N(    (   R   R   (    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyR   K   s    c         C   s   |  j  j |  S(   s   
        This method splits a sentence into words.  Default splitter splits input
        at white spaces, which should be enough for most languages except CJK
        languages.
        (   t   _word_ret   findall(   R   t   input(    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyt   splitQ   s    c         C   s   | S(   s  
        This method implements stemming algorithm of the Python version.

        Default implementation does nothing.  You should implement this if the
        language has any stemming rules.

        This class is used to preprocess search words before registering them in
        the search index.  The stemming of the Python version and the JS version
        (given in the js_stemmer_code attribute) must be compatible.
        (    (   R   t   word(    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyt   stemZ   s    c         C   s   t  |  d k p t  |  d k  rJ d t | d  k  oE d k  n p t | d  d k  o t  |  d k  p | |  j k p | j   S(   s   
        Return true if the target word should be registered in the search index.
        This method is called after stemming.
        i    i   iA0  i0  i   (   t   lent   ordt	   stopwordst   isdigit(   R   R#   (    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyt   word_filterh   s    8N(   t   __name__t
   __module__t   __doc__t   Nonet   langt   language_namet   setR'   t   js_stemmer_rawcodet   js_stemmer_codet   ret   compileR   R   R   R"   R$   R)   (    (    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyR      s   	
					(   t   SearchEnglishc         C   sJ   t    } x: |  j   D], } | j d  d } | j | j    q W| S(   ss   
    parse snowball style word list like this:

    * http://snowball.tartarus.org/algorithms/finnish/stop.txt
    t   |i    (   R0   t
   splitlinesR"   t   update(   t   sourcet   resultt   line(    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyt   parse_stop_wordz   s
    	s   sphinx.search.da.SearchDanisht   das   sphinx.search.de.SearchGermant   det   ens   sphinx.search.es.SearchSpanisht   ess   sphinx.search.fi.SearchFinnisht   fis   sphinx.search.fr.SearchFrencht   frs    sphinx.search.hu.SearchHungariant   hus   sphinx.search.it.SearchItaliant   its   sphinx.search.ja.SearchJapaneset   jas   sphinx.search.nl.SearchDutcht   nls    sphinx.search.no.SearchNorwegiant   nos!   sphinx.search.pt.SearchPortugueset   pts   sphinx.search.ro.SearchRomaniant   ros   sphinx.search.ru.SearchRussiant   rus   sphinx.search.sv.SearchSwedisht   svs   sphinx.search.tr.SearchTurkisht   trs   sphinx.search.zh.SearchChineset   zht   _JavaScriptIndexc           B   s>   e  Z d  Z d Z d Z d   Z d   Z d   Z d   Z RS(   s   
    The search index as javascript file that calls a function
    on the documentation search object to register the index.
    s   Search.setIndex(t   )c         C   s   |  j  t j |  |  j S(   N(   t   PREFIXR   t   dumpst   SUFFIX(   R   t   data(    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyRQ      s    c         C   si   | t  |  j  t  |  j  !} | sM | j |  j  sM | j |  j  r\ t d   n  t j |  S(   Ns   invalid data(   R%   RP   RR   t
   startswitht   endswitht
   ValueErrorR   t   loads(   R   t   sRS   (    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyRW      s
     c         C   s   | j  |  j |   d  S(   N(   t   writeRQ   (   R   RS   t   f(    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyt   dump   s    c         C   s   |  j  | j    S(   N(   RW   t   read(   R   RZ   (    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyt   load   s    (	   R*   R+   R,   RP   RR   RQ   RW   R[   R]   (    (    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyRN      s   			t   WordCollectorc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   sG   
    A special visitor that collects words for the `IndexBuilder`.
    c         C   s/   t  j |  |  g  |  _ g  |  _ | |  _ d  S(   N(   R
   R   t   found_wordst   found_title_wordsR.   (   R   t   documentR.   (    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyR      s    		c         C   sf   t  | t j j  rb | j d  d k rb | j d  } | d  k rI t S| |  j j k rb t Sn  t S(   Nt   namet   keywordsR.   (	   t
   isinstancet   sphinxt   addnodest   metat   getR-   t   TrueR.   t   False(   R   t   nodet   nodetypet	   meta_lang(    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyt   is_meta_keywords   s    *c         C   s  t  |  } t | t  r$ t  n  t | t  r d | j d d  j   k r t j d d | j	    } t j d d |  } t j d d |  } |  j
 j |  j j |   n  t  n  t | t  r |  j
 j |  j j | j	     n t | t  r&|  j j |  j j | j	     nW |  j | |  r}| d } g  | j d  D] } | j   ^ qR} |  j
 j |  n  d  S(	   Nt   htmlt   formatt    s   (?is)<style.*?</style>s   (?is)<script.*?</script>s   <[^<]+?>t   contentt   ,(   t   typet
   issubclassR   R   R   Rh   R"   R3   t   subt   astextR_   t   extendR.   R	   R   R`   Rn   t   strip(   R   Rk   Rl   t   nodetextRc   t   keyword(    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyt   dispatch_visit   s$    		%%
((   R*   R+   R,   R   Rn   R|   (    (    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyR^      s   		t   IndexBuilderc           B   s   e  Z d  Z i e d 6e d 6Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z d   Z d   Z RS(   sh   
    Helper class that creates a searchindex based on the doctrees
    passed to the `feed` method.
    R   t   picklec   	      C   sd  | |  _  i  |  _ i  |  _ i  |  _ i  |  _ i  |  _ i  |  _ i  |  _ t j	 |  } | d  k r d | k r t j	 | j d  d  } n  | d  k r t |  |  _ ni t | t  r| j d d  \ } } t t | d  d  | g  |  } | |  |  _ n | |  |  _ | rNt | d   } | j   j d  |  _ Wd  QXn	 d |  _ t |  _ d  S(   Nt   _i    t   .i   t   rbs   utf-8u    (   t   envt   _titlest
   _filenamest   _mappingt   _title_mappingt   _stem_cachet	   _objtypest	   _objnamest	   languagesRh   R-   R"   R5   R.   Rd   t   strt   rsplitt   getattrt
   __import__t   openR\   t   decodet   js_scorer_codeR   t   js_splitter_code(	   R   R   R.   R   t   scoringt
   lang_classt   modulet	   classnamet   fp(    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyR      s0    									!	c            s   t  | t  r |  j | } n  | j |  } t  | t  sY | j d  |  j j k rh t d   n  | d   t t	   | d   |  _
 t t	   | d   |  _   f d   } | | d  |  _ | | d  |  _ d	 S(
   s   Reconstruct from frozen data.t
   envversions
   old formatt   docnamest	   filenamest   titlesc            sp   i  } xc t  |   D]U \ } } t | t  rH t   | g  | | <q t   f d   | D  | | <q W| S(   Nc         3   s   |  ] }   | Vq d  S(   N(    (   t   .0t   i(   t   index2fn(    s5   lib/python2.7/site-packages/sphinx/search/__init__.pys	   <genexpr>8  s    (   R   Rd   t   intR0   (   t   mappingt   rvt   kt   v(   R   (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyt
   load_terms1  s    $t   termst
   titletermsN(   Rd   R   t   formatsR]   t   dictRh   R   t   versionRV   t   zipR   R   R   R   (   R   t   streamRp   t   frozenR   (    (   R   s5   lib/python2.7/site-packages/sphinx/search/__init__.pyR]   #  s    

c         C   s9   t  | t  r |  j | } n  | j |  j   |  d S(   s"   Dump the frozen index to a stream.N(   Rd   R   R   R[   t   freeze(   R   R   Rp   (    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyR[   ?  s    c         C   s  i  } |  j  } |  j } xt t |  j j   D]\ } } xut | j    D]a\ } } }	 }
 } } |
 | k rz qP n  | d k  r qP n  t |  } t |  } t | d  \ } } | j	 | i   } y | | |	 f } Wn} t
 k
 r^t |  } | | | |	 f <| j j |	  } | rH| |	 t | j |   f | | <q_| |	 |	 f | | <n X| | k rtd } n# | |	 d | k rd } n | } | |
 | | | f | | <qP Wq1 W| S(   Ni    R   Rq   t   -(   R   R   t   sortedR   R   t   domainst   get_objectsR   R   t
   setdefaultt   KeyErrorR%   t   object_typesRh   R   t   get_type_name(   R   t   fn2indexR   t   otypest   onamest
   domainnamet   domaint   fullnamet   dispnameRt   t   docnamet   anchort   priot   prefixRb   t   pdictt	   typeindext   otypet   shortanchor(    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyR   F  s>    		%(		"c         C   s   i  i  f } x t  | |  j |  j f  D] \ } } x t |  D]z \ } } t |  d k r | \ } | | k r | | | | <q qA t g  | D] } | | k r | | ^ q  | | <qA Wq( W| S(   Ni   (   R   R   R   R   R%   R   (   R   R   t   rvsR   R   R   R   t   fn(    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyt	   get_termsk  s    (	;c         C   s   t  t |  j j      \ } } g  | D] } |  j j |  ^ q( } t d   t |  D  } |  j |  \ } } |  j	 |  } t d   t
 |  j  D  }	 |  j }
 t d | d | d | d | d | d |	 d	 |
 d
 | d |  j j  	S(   s/   Create a usable data structure for serializing.c         s   s!   |  ] \ } } | | f Vq d  S(   N(    (   R   R   RZ   (    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pys	   <genexpr>}  s    c         s   s1   |  ]' \ } } | | d  d | d f Vq d S(   i    t   :i   N(    (   R   R   R   (    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pys	   <genexpr>  s   R   R   R   R   t   objectst   objtypest   objnamesR   R   (   R   R   R   t   itemsR   Rh   R   t	   enumerateR   R   R   R   R   R   R   (   R   R   R   R   R   R   R   t   title_termsR   R   R   (    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyR   x  s    !%		c         C   s   d |  j  j |  j  j  f S(   Ns   %s (code: %s)(   R.   R/   (   R   (    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyt   label  s    c         C   s   i  } i  } xB | D]: } | |  j  k r |  j  | | | <|  j | | | <q q W| |  _  | |  _ x$ t |  j  D] } | j |  qs Wx$ t |  j  D] } | j |  q Wd S(   s-   Remove data for all docnames not in the list.N(   R   R   R   R   t   intersection_updateR   (   R   R   t
   new_titlest   new_filenamesR   t	   wordnames(    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyt   prune  s    		c            si  |   j  | <|   j | <t |   j  } | j |    f d   }   j j } xy | j D]n } | |  }	 | |	  r   j j |	 t	    j
 |  q^ | |  r^   j j | t	    j
 |  q^ q^ Wx | j D] } | |  }	 | |	  r| |  r| }	 n  |   j j |	 t	    k }
 | |	  r |
 r   j j |	 t	    j
 |  q q Wd S(   s   Feed a doctree to the index.c            sN   y   j  |  SWn8 t k
 rI   j j |   j     j  |  <  j  |  SXd  S(   N(   R   R   R.   R$   t   lower(   R#   (   R   (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyR$     s
    N(   R   R   R^   R.   t   walkR)   R`   R   R   R0   t   addR_   Rh   R   (   R   R   t   filenameR   t   doctreet   visitorR$   t   _filterR#   t   stemmed_wordt   already_indexed(    (   R   s5   lib/python2.7/site-packages/sphinx/search/__init__.pyt   feed  s&    "&	c      	   C   s@   t  d |  j j d t j t |  j j   d |  j d |  j  S(   Nt   search_language_stemming_codet   search_language_stop_wordst   search_scorer_toolt   search_word_splitter_code(	   R   R.   R2   R   RQ   R   R'   R   R   (   R   (    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyt   context_for_searchtool  s
    	c         C   s3   |  j  j r+ t j t j d d |  j  j  Sd  Sd  S(   Nt   searchs   non-minified-js(   R.   R1   R    t   joinRe   t   package_dirR-   (   R   (    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyt   get_js_stemmer_rawcode  s    	(   R*   R+   R,   R   R~   R   R   R]   R[   R   R   R   R   R   R   R   R   (    (    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyR}      s   
	*			%					#		(3   R,   R3   t   osR    t   sixR   R   R   R   t	   six.movesR   R~   t   docutils.nodesR   R   R   R	   R
   R   Re   t   sphinx.utilR   R   t   sphinx.util.pycompatR   t   sphinx.search.jssplitterR   Rj   t   typingR   R   R   R   R   R   R   R   t   docutilsR   t   sphinx.environmentR   t   objectR   t   sphinx.search.enR5   R<   R   RN   t   js_indexR^   R}   (    (    (    s5   lib/python2.7/site-packages/sphinx/search/__init__.pyt   <module>
   sL   ".:X	
	0