
    ig                         d dl Z d dlZd dlZd dlmZ d dlmZmZ d dlm	Z	 e j                  rd dlmZ d dlmZ d dlmZ  G d d	e      Zy)
    N)gettext)Plugin
PluginInfo)EngineResults)SearchWithPlugins)SXNG_Request)	PluginCfgc                   D     e Zd ZdZdZg dZd fdZdddd	defd
Z xZ	S )
SXNGPluginzqPlugin converts strings to different hash digests.  The results are
    displayed in area for the "answers".
    hash_plugin)md5sha1sha224sha256sha384sha512returnc                    t         |   |       t        j                  ddj	                  | j
                         dt        j                        | _        t        | j                  t        d      t        d      dgd      | _        y )	N(|z) (.*)zHash pluginzkConverts strings to different hash digests. Available functions: md5, sha1, sha224, sha256, sha384, sha512.z2sha512 The quick brown fox jumps over the lazy dogquery)idnamedescriptionexamplespreference_section)super__init__recompilejoinkeywordsI	parser_rer   r   r   info)selfplg_cfg	__class__s     */root/searxng/searx/plugins/hash_plugin.pyr   zSXNGPlugin.__init__   so    !a(?'@$GNww'} KK&
	    requestr   searchr   c                 B   t               }|j                  j                  dkD  r|S | j                  j	                  |j                  j
                        }|s|S |j                         \  }}|j                         s|S t        j                  |j                               }|j                  |j                  d      j                                |dz   t        d      z   dz   |j                         z   }|j                  |j                   j#                  |             |S )z.Returns a result list only for the first page.   zutf-8 zhash digestz: )answer)r   search_querypagenor$   matchr   groupsstriphashlibnewlowerupdateencoder   	hexdigestaddtypesAnswer)	r&   r+   r,   resultsmfunctionstringfr0   s	            r)   post_searchzSXNGPlugin.post_search)   s    /%%)NNN  !4!4!:!:;N88:&||~N KK() 	
w'--/0C'-"884?!++-OGMM(((78r*   )r'   r	   r   N)
__name__
__module____qualname____doc__r   r"   r   r   rD   __classcell__)r(   s   @r)   r   r      s5     
BFH
> ;N S` r*   r   )typingr   r6   flask_babelr   searx.pluginsr   r   searx.result_typesr   TYPE_CHECKINGsearx.searchr   searx.extended_typesr   r	   r    r*   r)   <module>rR      s7     	   , ,	.1'0 0r*   