
    iX                         d Z g dZddlmZ ddlZddlmZ ddlmZ  G d d	ed
      Z	 G d d      Z
 G d de	d
      Z G d de	d
      Z G d de	d
      Zy)a  
Typification of the *answer* results.  Results of this type are rendered in
the :origin:`answers.html <searx/templates/simple/elements/answers.html>`
template.

----

.. autoclass:: BaseAnswer
   :members:
   :show-inheritance:

.. autoclass:: Answer
   :members:
   :show-inheritance:

.. autoclass:: Translations
   :members:
   :show-inheritance:

.. autoclass:: WeatherAnswer
   :members:
   :show-inheritance:

.. autoclass:: AnswerSet
   :members:
   :show-inheritance:
)	AnswerSetAnswerTranslationsWeatherAnswer    )gettextN)weather   )Resultc                       e Zd ZdZy)
BaseAnswerzjBase class of all answer types.  It is not intended to build instances of
    this class (aka *abstract*).N)__name__
__module____qualname____doc__     */root/searxng/searx/result_types/answer.pyr   r   )   s    $r   r   Tkw_onlyc                   H    e Zd ZdZd Zd Zd ZdeddfdZd	 Z	dede
fd
Zy)r   z@Aggregator for :py:obj:`BaseAnswer` items in a result container.c                     g | _         y N)_answerlistselfs    r   __init__zAnswerSet.__init__1   s
    r   c                 ,    t        | j                        S r   )lenr   r   s    r   __len__zAnswerSet.__len__4   s    4##$$r   c                 ,    t        | j                        S r   )boolr   r   s    r   __bool__zAnswerSet.__bool__7   s    D$$%%r   answerreturnNc                     t        |      }| j                  D ]  }t        |      |k(  s y  | j                  j                  |       y r   )hashr   appendr   r#   a_hashis       r   addzAnswerSet.add:   sE    f!! 	AAw& 	 	'r   c              #   r   K   | j                   j                  d        | j                   E d{    y7 w)z2Sort items in this set and iterate over the items.c                     | j                   S r   )template)r#   s    r   <lambda>z$AnswerSet.__iter__.<locals>.<lambda>C   s
     r   )keyN)r   sortr   s    r   __iter__zAnswerSet.__iter__A   s-     "@A####s   -757c                 \    t        |      }| j                  D ]  }t        |      |k(  s y y)NTF)r&   r   r(   s       r   __contains__zAnswerSet.__contains__F   s4    f!! 	AAw& 	 r   )r   r   r   r   r   r   r"   r   r+   r2   r!   r4   r   r   r   r   r   .   s?    J%&(* ( ($
: $ r   r   c                   2    e Zd ZU dZdZeed<   eed<   	 d Zy)r   zSimple answer type where the *answer* is a simple string with an optional
    :py:obj:`url field <Result.url>` field to link a resource (article, map, ..)
    related to the answer.zanswer/legacy.htmlr.   r#   c                 ,    t        | j                        S )zThe hash value of field *answer* is the hash value of the
        :py:obj:`Answer` object.  :py:obj:`Answer <Result.__eq__>` objects are
        equal, when the hash values of both objects are equal.)r&   r#   r   s    r   __hash__zAnswer.__hash__X   s     DKK  r   N)r   r   r   r   r.   str__annotations__r7   r   r   r   r   r   N   s      )Hc(K!r   r   c                   b    e Zd ZU dZdZeed<   	 ded<   	 d Z G d dej                  d	
      Z
y)r   aE  Answer type with a list of translations.

    The items in the list of :py:obj:`Translations.translations` are of type
    :py:obj:`Translations.Item`:

    .. code:: python

       def response(resp):
           results = []
           ...
           foo_1 = Translations.Item(
               text="foobar",
               synonyms=["bar", "foo"],
               examples=["foo and bar are placeholders"],
           )
           foo_url="https://www.deepl.com/de/translator#en/de/foo"
           ...
           Translations(results=results, translations=[foo], url=foo_url)

    zanswer/translations.htmlr.   zlist[Translations.Item]translationsc                 2    | j                   st        d      y )Nz:Translation does not have an item in the list translations)r;   
ValueErrorr   s    r   __post_init__zTranslations.__post_init__|   s      YZZ !r   c                   n    e Zd ZU dZeed<   	 dZeed<   	 g Zee   ed<   	 g Z	ee   ed<   	 g Z
ee   ed<   y)	Translations.ItemzA single element of the translations / a translation.  A translation
        consists of at least a mandatory ``text`` property (the translation) ,
        optional properties such as *definitions*, *synonyms* and *examples* are
        possible.text transliterationexamplesdefinitionssynonymsN)r   r   r   r   r8   r9   rC   rD   listrE   rF   r   r   r   Itemr@      sU    	
 	!!	
 !$s) =!#T#Y#@ $s) =r   rH   Tr   N)r   r   r   r   r.   r8   r9   r>   msgspecStructrH   r   r   r   r   r   _   s;    * /Hc.: ,+[>w~~t >r   r   c                   |    e Zd ZU dZdZeed<   	 ded<   	 g Zded<   	 dZeed	<   	  G d
 de	j                  d      Zy)r   zAnswer type for weather data.zanswer/weather.htmlr.   WeatherAnswer.Itemcurrentzlist[WeatherAnswer.Item]	forecastsrB   servicec                      e Zd ZU dZej
                  ed<   	 ej                  ed<   	 ej                  ed<   	 dZ	ej                  dz  ed<   	 dZedz  ed<   	 dZej                  dz  ed<   	 dZej                  dz  ed	<   	 dZej"                  dz  ed
<   	 ej$                  ed<   	 dZej(                  dz  ed<   	 dZedz  ed<   	 d Zededz  fd       Zy)rL   z6Weather parameters valid for a specific point in time.locationtemperature	conditionNdatetimesummary
feels_likepressurehumidity	wind_from
wind_speedcloud_coverc                     | j                   sXt        d      j                  | j                  | j                  t        | j
                  j                                     | _         y y )Nz&{location}: {temperature}, {condition})rQ   rR   rS   )rU   r   formatrQ   rR   rS   
capitalizer   s    r   r>   z WeatherAnswer.Item.__post_init__   sQ    <<&'OPWW!]] $ 0 0%dnn&?&?&AB  X    r   r$   c                 @    t        j                  | j                        S )a  Determines a `data URL`_ with a symbol for the weather
            conditions.  If no symbol can be assigned, ``None`` is returned.

            .. _data URL:
               https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Schemes/data
            )r   
symbol_urlrS   r   s    r   urlzWeatherAnswer.Item.url   s     %%dnn55r   )r   r   r   r   r   GeoLocationr9   TemperatureWeatherConditionTyperT   DateTimerU   r8   rV   rW   PressurerX   RelativeHumidityCompassrZ   	WindSpeedr[   intr>   propertyra   r   r   r   rH   zWeatherAnswer.Item   s   D%%%Q(((5///	7
 -1'""T)0H"t"	
 26
G''$.5	 -1'""T)0848'**T18	 ??"S/3
G%%,3R"&S4Z&	!	 
	6t 	6 
	6r   rH   Tr   N)r   r   r   r   r.   r8   r9   rN   rO   rI   rJ   rH   r   r   r   r   r      sN    ')Hc)5 "!*,.I).-GSCD6w~~t D6r   r   )r   __all__flask_babelr   rI   searxr   _baser
   r   r   r   r   r   r   r   r   <module>rp      sd   < C    $ $
 @!Z !"7>:t 7>tT6J T6r   