Ë
    Ï.f‡  ã                   óŽ   — d dl Zd dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
mZ d dlmZmZmZ d dlmZ d dlmZ d	Z G d
„ de«      Zy)é    N)Úpartial)Ú	urlencode)ÚAdapterHTTPError)ÚGeocoderQueryErrorÚGeocoderQuotaExceeded)ÚDEFAULT_SENTINELÚNONE_RESULTÚGeocoder)ÚLocation)Úlogger)ÚGeocodioc                   ó|   ‡ — e Zd ZdZh d£ZdZdZdZdeededddœˆ fd„
Z	dd	ed
œd„Z
d	eddœd„Zdd„Zd„ Zd„ Zˆ xZS )r   z¹Geocoder using the Geocod.io API.

    Documentation at:
        https://www.geocod.io/docs/

    Pricing details:
        https://www.geocod.io/pricing/

    .. versionadded:: 2.2
    >   ÚcityÚstateÚstreetÚcountryÚpostal_codezapi.geocod.ioz/v1.6/geocodez/v1.6/reverseN)ÚschemeÚtimeoutÚproxiesÚ
user_agentÚssl_contextÚadapter_factoryÚdomainc                óR   •— t         ‰	| �  ||||||¬«       || _        |r|| _        yy)aG  
        :param str api_key:
            A valid Geocod.io API key. (https://dash.geocod.io/apikey/create)

        :param str scheme:
            See :attr:`geopy.geocoders.options.default_scheme`.

        :param int timeout:
            See :attr:`geopy.geocoders.options.default_timeout`.

        :param dict proxies:
            See :attr:`geopy.geocoders.options.default_proxies`.

        :param str user_agent:
            See :attr:`geopy.geocoders.options.default_user_agent`.

        :type ssl_context: :class:`ssl.SSLContext`
        :param ssl_context:
            See :attr:`geopy.geocoders.options.default_ssl_context`.

        :param callable adapter_factory:
            See :attr:`geopy.geocoders.options.default_adapter_factory`.

        :param str domain: base api domain

            .. versionadded:: 2.4
        )r   r   r   r   r   r   N)ÚsuperÚ__init__Úapi_keyr   )
Úselfr   r   r   r   r   r   r   r   Ú	__class__s
            €úWC:\Users\user\Documents\project_loop\venv\Lib\site-packages\geopy/geocoders/geocodio.pyr   zGeocodio.__init__'   sB   ø€ ôN 	‰ÑØØØØ!Ø#Ø+ð 	ô 	
ð ˆŒÙØ ˆD�Kð ó    T)ÚlimitÚexactly_oner   c                ó.  — t        |t        j                  j                  «      r2|j	                  «       D ��ci c]  \  }}|| j
                  v r||“Œ }}}nd|i}| j                  |d<   |r||d<   |rd|d<   | j                  ›d| j                  ›| j                  ›�}dj                  |t        |«      f«      }	t        j                  d| j                  j                  |	«       t!        | j"                  |¬«      }
| j%                  |	|
|¬	«      S c c}}w )
aÚ  
        Return a location point by address.

        :param query: The address, query or a structured query
            you wish to geocode.

            For a structured query, provide a dictionary whose keys
            are one of: `street`, `city`, `state`, `postal_code` or `country`.
        :type query: dict or str

        :param int limit: The maximum number of matches to return. This will be reset
            to 1 if ``exactly_one`` is ``True``.

        :param bool exactly_one: Return one result or a list of results, if
            available.

        :param int timeout: Time, in seconds, to wait for the geocoding service
            to respond before raising a :class:`geopy.exc.GeocoderTimedOut`
            exception. Set this only if you wish to override, on this call
            only, the value set during the geocoder's initialization.

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        Úqr   r#   é   ú://ú?z%s.geocode: %s©r$   ©r   )Ú
isinstanceÚcollectionsÚabcÚMappingÚitemsÚstructured_query_paramsr   r   r   Úgeocode_pathÚjoinr   r   Údebugr    Ú__name__r   Ú_parse_jsonÚ_call_geocoder)r   Úqueryr#   r$   r   ÚkeyÚvalÚparamsÚapiÚurlÚcallbacks              r!   ÚgeocodezGeocodio.geocodeZ   s  € ôB �eœ[Ÿ_™_×4Ñ4Ô5ð —;‘;“=÷á�C˜à˜$×6Ñ6Ñ6ð �S‘ðˆFò ð ˜5�\ˆFà ŸL™LˆˆyÑáØ#ˆF�7‰OÙØˆF�7‰Oà!Ÿ[›[¨$¯+ª+°t×7HÒ7HÐIˆØ�h‰h˜œY vÓ.Ð/Ó0ˆä�‰Ð% t§~¡~×'>Ñ'>ÀÔDÜ˜4×+Ñ+¸ÔEˆØ×"Ñ" 3¨¸'Ð"ÓBÐBùó+s   ¸D)r$   r   r#   c                ó†  — | j                  |«      | j                  dœ}|rd}|�||d<   | j                  ›d| j                  ›| j                  ›�}dj                  |t        |«      f«      }t        j                  d| j                  j                  |«       t        | j                  |¬«      }| j                  |||¬«      S )	a5  Return an address by location point.

        :param str query: The coordinates for which you wish to obtain the
            closest human-readable addresses

        :param bool exactly_one: Return one result or a list of results, if
            available.

        :param int timeout: Time, in seconds, to wait for the geocoding service
            to respond before raising a :class:`geopy.exc.GeocoderTimedOut`
            exception. Set this only if you wish to override, on this call
            only, the value set during the geocoder's initialization.

        :param int limit: The maximum number of matches to return. This will be reset
            to 1 if ``exactly_one`` is ``True``.

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        )r&   r   r'   r#   r(   r)   z%s.reverse: %sr*   r+   )Ú_coerce_point_to_stringr   r   r   Úreverse_pathr3   r   r   r4   r    r5   r   r6   r7   )	r   r8   r$   r   r#   r;   r<   r=   r>   s	            r!   ÚreversezGeocodio.reverse“   s°   € ð8 ×-Ñ-¨eÓ4Ø—|‘|ñ
ˆñ ØˆEØÐØ#ˆF�7‰Oà!Ÿ[›[¨$¯+ª+°t×7HÒ7HÐIˆØ�h‰h˜œY vÓ.Ð/Ó0ˆä�‰Ð% t§~¡~×'>Ñ'>ÀÔDÜ˜4×+Ñ+¸ÔEˆØ×"Ñ" 3¨¸'Ð"ÓBÐBr"   c                 ó‚   — |j                  dg «      }|syd„ }|r ||d   «      S |D �cg c]
  } ||«      ‘Œ c}S c c}w )z7Returns location, (latitude, longitude) from json feed.ÚresultsNc                 ób   — | j                  d«      }| d   d   }| d   d   }t        |||f| «      S )z4Get the location, lat, lng from a single json place.Úformatted_addressÚlocationÚlatÚlng)Úgetr   )ÚplacerH   ÚlatitudeÚ	longitudes       r!   Úparse_placez)Geocodio._parse_json.<locals>.parse_placeÅ   sC   € à—y‘yÐ!4Ó5ˆHØ˜ZÑ(¨Ñ/ˆHØ˜jÑ)¨%Ñ0ˆIÜ˜H x°Ð&;¸UÓCÐCr"   r   )rK   )r   Úpager$   ÚplacesrO   rL   s         r!   r6   zGeocodio._parse_json¾   sM   € ð —‘˜) RÓ(ˆÙØò	Dñ Ù˜v a™yÓ)Ð)à4:Ö;¨5‘K Õ&Ò;Ð;ùÒ;s   ª<c                 ój  — t        |t        «      sy|j                  �|j                  €y|j                  dk(  rG| j	                  |«      }d|j                  «       v rd|j                  «       v rt        S t        |«      |‚|j                  dk(  r$| j	                  |«      }d}||v rt        |«      |‚yy)a†  Custom exception handling for invalid queries and exceeded quotas.

        Geocod.io returns a ``422`` status code for invalid queries, which is not mapped
        in :const:`~geopy.geocoders.base.ERROR_CODE_MAP`. The service also returns a
        ``403`` status code for exceeded quotas instead of the ``429`` code mapped in
        :const:`~geopy.geocoders.base.ERROR_CODE_MAP`
        Ni¦  zcould not geocode addresszpostal code or city requiredi“  z>You can't make this request as it is above your daily maximum.)	r,   r   Ústatus_codeÚtextÚ_get_error_messageÚlowerr	   r   r   )r   ÚerrorÚerror_messageÚquota_exceeded_snippets       r!   Ú_geocoder_exception_handlerz$Geocodio._geocoder_exception_handlerÑ   sÃ   € ô ˜%Ô!1Ô2ØØ×ÑÐ$¨¯
©
Ð(:ØØ×Ñ Ò#Ø ×3Ñ3°EÓ:ˆMà+¨}×/BÑ/BÓ/DÑDØ2°m×6IÑ6IÓ6KÑKä"Ð"Ü$ ]Ó3¸Ð>Ø×Ñ Ò#Ø ×3Ñ3°EÓ:ˆMð&AÐ"à%¨Ñ6Ü+¨MÓ:ÀÐEð 7ð	 $r"   c                 ó¢   — 	 t        j                  |j                  «      j                  d«      }|xs |j                  S # t        $ r d}Y Œw xY w)zVTry to extract an error message from the 'error' property of a JSON response.
        rW   N)ÚjsonÚloadsrT   rK   Ú
ValueError)r   rW   rX   s      r!   rU   zGeocodio._get_error_messageì   sK   € ð	!Ü ŸJ™J u§z¡zÓ2×6Ñ6°wÓ?ˆMð Ò* §
¡
Ð*øô ò 	!Ø ŠMð	!ús   ‚.A  Á AÁA)T)r5   Ú
__module__Ú__qualname__Ú__doc__r1   r   r2   rB   r   r   r?   rC   r6   rZ   rU   Ú__classcell__)r    s   @r!   r   r      sr   ø„ ñ	òÐð €FØ"€LØ"€Lð Ø Ø ØØ$ØØö1!ðn ØØ ô7Cðz Ø Øô)CóV<ò&Fö6+r"   r   )Úcollections.abcr-   r\   Ú	functoolsr   Úurllib.parser   Úgeopy.adaptersr   Ú	geopy.excr   r   Úgeopy.geocoders.baser   r	   r
   Úgeopy.locationr   Ú
geopy.utilr   Ú__all__r   © r"   r!   ú<module>rm      s6   ðÛ Û Ý Ý "å +ß ?ß HÑ HÝ #Ý à
€ôd+ˆxõ d+r"   