o
    [hk                     @   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   /home/ubuntu/experiments/live_experiments/Pythonexperiments/Otree/venv/lib/python3.10/site-packages/django/contrib/gis/feeds.py	<genexpr>   s   " z-GeoFeedMixin.georss_coords.<locals>.<genexpr>)join)selfcoordsr   r   r
   georss_coords   s   zGeoFeedMixin.georss_coordsFc                 C   sP   |r|dd \}}| dd|  | dd|  dS | 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   sX  | d}|durt|ttfred}t|d ttfr(t|dkr$|}n*tdt|dkr7| j|||d nt|dkrJ|dd |dd f}ntd|durc|rXtd	|d
| | dS dS t	|j
 }|dkr{| j||j|d dS |rtd|dv r|d| |j dS |dv r|d| |d j dS 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    sN   


zGeoFeedMixin.add_georss_elementN)F)__name__
__module____qualname____doc__r   r   r#   r   r   r   r
   r      s
    
r   c                       4   e Zd Z fddZ fddZ fddZ  ZS )
GeoRSSFeedc                       t   }d|d< |S Nzhttp://www.georss.org/georsszxmlns:georsssuperrss_attributesr   attrs	__class__r   r
   r.   \      
zGeoRSSFeed.rss_attributesc                       t  || | || d S Nr-   add_item_elementsr#   r   r   r!   r1   r   r
   r7   a      zGeoRSSFeed.add_item_elementsc                       t  | | || j d S r5   r-   add_root_elementsr#   feedr   r   r1   r   r
   r<   e      zGeoRSSFeed.add_root_elementsr$   r%   r&   r.   r7   r<   __classcell__r   r   r1   r
   r)   [       r)   c                       r(   )GeoAtom1Feedc                    r*   r+   )r-   root_attributesr/   r1   r   r
   rD   k   r3   zGeoAtom1Feed.root_attributesc                    r4   r5   r6   r8   r1   r   r
   r7   p   r9   zGeoAtom1Feed.add_item_elementsc                    r:   r5   r;   r>   r1   r   r
   r<   t   r?   zGeoAtom1Feed.add_root_elements)r$   r%   r&   rD   r7   r<   rA   r   r   r1   r
   rC   j   rB   rC   c                       r(   )
W3CGeoFeedc                    r*   )Nz(http://www.w3.org/2003/01/geo/wgs84_pos#z	xmlns:geor,   r/   r1   r   r
   r.   z   r3   zW3CGeoFeed.rss_attributesc                    s"   t  || | j||dd d S NTr   r6   r8   r1   r   r
   r7      s   zW3CGeoFeed.add_item_elementsc                    s"   t  | | j|| jdd d S rF   r;   r>   r1   r   r
   r<      s   zW3CGeoFeed.add_root_elementsr@   r   r   r1   r
   rE   y   rB   rE   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      zFeed.feed_extra_kwargsc                 C   s   d|  d|iS )Nr   Zitem_geometryrG   )r   r!   r   r   r
   item_extra_kwargs   rJ   zFeed.item_extra_kwargsN)r$   r%   r&   r'   r)   Z	feed_typerI   rK   r   r   r   r
   r      s
    r   N)
Z django.contrib.syndication.viewsr   ZBaseFeedZdjango.utils.feedgeneratorr   r   r   r)   rC   rE   r   r   r   r
   <module>   s    V