o
    e                     @   sd   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
 d dlmZ dZG dd	 d	eZd
S )    )partial)	urlencode)GeocoderQueryError)DEFAULT_SENTINELGeocoderLocation)logger)DataBCc                       s\   e Zd ZdZdZdeededdd fdd
Zdd	d
dedddZdd Zdd Z	  Z
S )r
   zGeocoder using the Physical Address Geocoder from DataBC.

    Documentation at:
        https://github.com/bcgov/ols-geocoder/blob/gh-pages/geocoder-developer-guide.md
    z/addresses.geojsonNzgeocoder.api.gov.bc.ca)schemetimeoutproxies
user_agentssl_contextadapter_factorydomainc                   s0   t  j||||||d d| j|| jf | _dS )a   

        :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`.

            .. versionadded:: 2.0

        :param str domain: base api domain

            .. versionadded:: 2.4
        )r   r   r   r   r   r   z	%s://%s%sN)super__init__r   geocode_pathapi)selfr   r   r   r   r   r   r   	__class__ I/var/www/html/venv/lib/python3.10/site-packages/geopy/geocoders/databc.pyr      s   &zDataBC.__init__   r   anyT)max_resultsset_backlocation_descriptorexactly_oner   c          
      C   s   d|i}|dkr||d< |dvrt d||d< |rd}||d< d	| jt|f}td
| jj| t| j	|d}	| j
||	|dS )a~  
        Return a location point by address.

        :param str query: The address or query you wish to geocode.

        :param int max_results: The maximum number of resutls to request.

        :param float set_back: The distance to move the accessPoint away
            from the curb (in meters) and towards the interior of the parcel.
            location_descriptor must be set to accessPoint for set_back to
            take effect.

        :param str location_descriptor: The type of point requested. It
            can be any, accessPoint, frontDoorPoint, parcelPoint,
            rooftopPoint and routingPoint.

        :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``.
        addressStringr   setBack)r   accessPointfrontDoorPointparcelPointrooftopPointroutingPointzYou did not provided a location_descriptor the webservice can consume. It should be any, accessPoint, frontDoorPoint, parcelPoint, rooftopPoint or routingPoint.locationDescriptor   
maxResults?z%s.geocode: %s)r    )r   )r   joinr   r   r	   debugr   __name__r   _parse_json_call_geocoder)
r   queryr   r   r   r    r   paramsurlcallbackr   r   r   geocodeE   s   %zDataBC.geocodec                 C   sB   t |d sd S g }|d D ]
}|| | q|r|d S |S )Nfeaturesr   )lenappend_parse_feature)r   responser    geocodedfeaturer   r   r   r/      s   zDataBC._parse_jsonc                 C   s0   |d }|d d }t |d |d |d f|S )N
propertiesgeometrycoordinatesfullAddressr)   r   r   )r   r<   r=   r?   r   r   r   r9      s   zDataBC._parse_feature)r.   
__module____qualname____doc__r   r   r   r5   r/   r9   __classcell__r   r   r   r   r
      s&    4=r
   N)	functoolsr   urllib.parser   	geopy.excr   geopy.geocoders.baser   r   geopy.locationr   
geopy.utilr	   __all__r
   r   r   r   r   <module>   s    