3
(hX                 @   s   d dl mZ d dlmZ d dlmZmZ G dd de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 )    )unicode_literals)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j 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, this will return
        a unicode GeoRSS representation.
         c             s   s"   | ]}d |d |d f V  qdS )z%f %f   r   N ).0Zcoordr	   r	   </tmp/pip-install-q3hcpn_q/Django/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   sN   |r6|dd \}}|j dd|  |j dd|  n|j d| j|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  |j d}|dk	rPt|ttfrd}t|d ttfrTt|dkrJ|}qtdnLt|dkrr| j|||d n.t|dkr|dd |dd f}ntd|dk	r|rtd	|jd
| j| nt	|j
j }|dkr| j||j|d n^|rtd|dkr|jd| j|j n2|dkrB|jd| j|d j ntd|j
 dS )zZ
        This routine adds 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:boxZpointz'W3C Geo only supports Point geometries.
linestring
linearringzgeorss:linepolygonzgeorss:polygonz!Geometry type "%s" not supported.)r   r   )r   )get
isinstancelisttuplelen
ValueErrorr   r   r   strZ	geom_typelowerr   )r   r   itemr   ZgeomZ
box_coordsZgtyper	   r	   r   add_georss_element"   s6    




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 t| j }d|d< |S )Nzhttp://www.georss.org/georsszxmlns:georss)superr)   rss_attributes)r   attrs)	__class__r	   r   r+   V   s    zGeoRSSFeed.rss_attributesc                s"   t t| j|| | j|| d S )N)r*   r)   add_item_elementsr$   )r   r   r#   )r-   r	   r   r.   [   s    zGeoRSSFeed.add_item_elementsc                s"   t t| j| | j|| j d S )N)r*   r)   add_root_elementsr$   feed)r   r   )r-   r	   r   r/   _   s    zGeoRSSFeed.add_root_elements)r%   r&   r'   r+   r.   r/   __classcell__r	   r	   )r-   r   r)   U   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 t| j }d|d< |S )Nzhttp://www.georss.org/georsszxmlns:georss)r*   r2   root_attributes)r   r,   )r-   r	   r   r3   e   s    zGeoAtom1Feed.root_attributesc                s"   t t| j|| | j|| d S )N)r*   r2   r.   r$   )r   r   r#   )r-   r	   r   r.   j   s    zGeoAtom1Feed.add_item_elementsc                s"   t t| j| | j|| j d S )N)r*   r2   r/   r$   r0   )r   r   )r-   r	   r   r/   n   s    zGeoAtom1Feed.add_root_elements)r%   r&   r'   r3   r.   r/   r1   r	   r	   )r-   r   r2   d   s   r2   c                   s4   e Zd Z fddZ fddZ fddZ  ZS )
W3CGeoFeedc                s   t t| j }d|d< |S )Nz(http://www.w3.org/2003/01/geo/wgs84_pos#z	xmlns:geo)r*   r4   r+   )r   r,   )r-   r	   r   r+   t   s    zW3CGeoFeed.rss_attributesc                s&   t t| j|| | j||dd d S )NT)r   )r*   r4   r.   r$   )r   r   r#   )r-   r	   r   r.   y   s    zW3CGeoFeed.add_item_elementsc                s&   t t| j| | j|| jdd d S )NT)r   )r*   r4   r/   r$   r0   )r   r   )r-   r	   r   r/   }   s    zW3CGeoFeed.add_root_elements)r%   r&   r'   r+   r.   r/   r1   r	   r	   )r-   r   r4   s   s   r4   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| j d|iS )Nr   )_get_dynamic_attr)r   objr	   r	   r   feed_extra_kwargs   s    zFeed.feed_extra_kwargsc             C   s   d| j d|iS )Nr   Zitem_geometry)r5   )r   r#   r	   r	   r   item_extra_kwargs   s    zFeed.item_extra_kwargsN)r%   r&   r'   r(   r)   Z	feed_typer7   r8   r	   r	   r	   r   r      s   r   N)
__future__r   Z django.contrib.syndication.viewsr   ZBaseFeedZdjango.utils.feedgeneratorr   r   objectr   r)   r2   r4   r	   r	   r	   r   <module>   s   N