a
    Kcòfk  ã                   @   st   d dl mZ d dlmZmZ G dd„ dƒZG dd„ deeƒZG dd„ deeƒZG d	d
„ d
eeƒZ	G dd„ deƒZdS )é    )ÚFeed)Ú	Atom1FeedÚRss201rev2Feedc                   @   s,   e Zd ZdZdd„ Zd
dd„Zddd„Zd	S )ÚGeoFeedMixinz…
    This mixin provides the necessary routines for SyndicationFeed subclasses
    to produce simple GeoRSS or W3C Geo elements.
    c                 C   s   d  dd„ |D ƒ¡S )z¿
        In GeoRSS coordinate pairs are ordered by lat/lon and separated by
        a single white space. Given a tuple of coordinates, return a string
        GeoRSS representation.
        ú c                 s   s"   | ]}d |d |d f V  qdS )z%f %fé   r   N© )Ú.0Zcoordr   r   úU/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/django/contrib/gis/feeds.pyÚ	<genexpr>   ó    z-GeoFeedMixin.georss_coords.<locals>.<genexpr>)Újoin)ÚselfÚcoordsr   r   r
   Úgeorss_coords   s    zGeoFeedMixin.georss_coordsFc                 C   sN   |r6|dd… \}}|  dd| ¡ |  dd| ¡ n|  d|  |f¡¡ dS )z¾
        Adds a GeoRSS point with the given coords using the given handler.
        Handles the differences between simple GeoRSS and the more popular
        W3C Geo specification.
        Né   zgeo:latz%fzgeo:lonzgeorss:point)ÚaddQuickElementr   )r   Úhandlerr   Úw3c_geoZlonZlatr   r   r
   Úadd_georss_point   s
    zGeoFeedMixin.add_georss_pointc                 C   sT  |  d¡}|du�rPt|ttfƒrÈd}t|d ttfƒrTt|ƒdkrJ|}q tdƒ‚nLt|ƒdkrr| j|||d� n.t|ƒdkr˜|dd… |dd… f}ntdƒ‚|durÆ|r´td	ƒ‚| d
|  |¡¡ nˆt	|j
ƒ ¡ }|dkrò| j||j|d� n^|rþtdƒ‚|dv �r| d|  |j¡¡ n2|dv �rB| d|  |d j¡¡ ntd|j
 ƒ‚dS )z:Add a GeoRSS XML element using the given item and handler.ÚgeometryNr   r   z'Only should be two sets of coordinates.©r   é   z'Only should be 2 or 4 numeric elements.z.Cannot use simple GeoRSS box in W3C Geo feeds.z
georss:boxÚpointz'W3C Geo only supports Point geometries.)Z
linestringZ
linearringzgeorss:line)Zpolygonzgeorss:polygonz!Geometry type "%s" not supported.)ÚgetÚ
isinstanceÚlistÚtupleÚlenÚ
ValueErrorr   r   r   ÚstrZ	geom_typeÚlowerr   )r   r   Úitemr   ZgeomZ
box_coordsÚgtyper   r   r
   Úadd_georss_element    sJ    


ÿ
ÿ
ÿ
ÿÿzGeoFeedMixin.add_georss_elementN)F)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r$   r   r   r   r
   r      s   
r   c                       s4   e Zd Z‡ fdd„Z‡ fdd„Z‡ fdd„Z‡  ZS )Ú
GeoRSSFeedc                    s   t ƒ  ¡ }d|d< |S ©Nzhttp://www.georss.org/georsszxmlns:georss©ÚsuperÚrss_attributes©r   Úattrs©Ú	__class__r   r
   r-   \   s    
zGeoRSSFeed.rss_attributesc                    s   t ƒ  ||¡ |  ||¡ d S ©N©r,   Úadd_item_elementsr$   ©r   r   r"   r0   r   r
   r4   a   s    zGeoRSSFeed.add_item_elementsc                    s   t ƒ  |¡ |  || j¡ d S r2   ©r,   Úadd_root_elementsr$   Úfeed©r   r   r0   r   r
   r7   e   s    zGeoRSSFeed.add_root_elements©r%   r&   r'   r-   r4   r7   Ú__classcell__r   r   r0   r
   r)   [   s   r)   c                       s4   e Zd Z‡ fdd„Z‡ fdd„Z‡ fdd„Z‡  ZS )ÚGeoAtom1Feedc                    s   t ƒ  ¡ }d|d< |S r*   )r,   Úroot_attributesr.   r0   r   r
   r=   k   s    
zGeoAtom1Feed.root_attributesc                    s   t ƒ  ||¡ |  ||¡ d S r2   r3   r5   r0   r   r
   r4   p   s    zGeoAtom1Feed.add_item_elementsc                    s   t ƒ  |¡ |  || j¡ d S r2   r6   r9   r0   r   r
   r7   t   s    zGeoAtom1Feed.add_root_elements)r%   r&   r'   r=   r4   r7   r;   r   r   r0   r
   r<   j   s   r<   c                       s4   e Zd Z‡ fdd„Z‡ fdd„Z‡ fdd„Z‡  ZS )Ú
W3CGeoFeedc                    s   t ƒ  ¡ }d|d< |S )Nz(http://www.w3.org/2003/01/geo/wgs84_pos#z	xmlns:geor+   r.   r0   r   r
   r-   z   s    
zW3CGeoFeed.rss_attributesc                    s"   t ƒ  ||¡ | j||dd� d S ©NTr   r3   r5   r0   r   r
   r4      s    zW3CGeoFeed.add_item_elementsc                    s"   t ƒ  |¡ | j|| jdd� d S r?   r6   r9   r0   r   r
   r7   ƒ   s    zW3CGeoFeed.add_root_elementsr:   r   r   r0   r
   r>   y   s   r>   c                   @   s$   e Zd ZdZeZdd„ Zdd„ ZdS )r   zÿ
    This is a subclass of the `Feed` from `django.contrib.syndication`.
    This allows users to define a `geometry(obj)` and/or `item_geometry(item)`
    methods on their own subclasses so that geo-referenced information may
    placed in the feed.
    c                 C   s   d|   d|¡iS )Nr   ©Z_get_dynamic_attr)r   Úobjr   r   r
   Úfeed_extra_kwargs“   s    zFeed.feed_extra_kwargsc                 C   s   d|   d|¡iS )Nr   Zitem_geometryr@   )r   r"   r   r   r
   Úitem_extra_kwargs–   s    zFeed.item_extra_kwargsN)r%   r&   r'   r(   r)   Z	feed_typerB   rC   r   r   r   r
   r   ‰   s   r   N)
Z django.contrib.syndication.viewsr   ZBaseFeedZdjango.utils.feedgeneratorr   r   r   r)   r<   r>   r   r   r   r
   Ú<module>   s   V