î
ªÍ XX  ã               @   s±   d  d l  m Z d  d l m Z d  d l m Z m Z Gd d „  d e ƒ Z	 Gd d „  d e e	 ƒ Z
 Gd d	 „  d	 e e	 ƒ Z Gd
 d „  d e e	 ƒ Z Gd 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	   úF/home/ubuntu/projects/ifolica/build/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   sg   | rG | 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   së  | j  d ƒ } | d k	 rçt | t t f ƒ r%d } t | d t t f ƒ ry t | ƒ d k rj | } qå t d ƒ ‚ nl t | ƒ d k r¤ |  j | | d | ƒnA t | ƒ d k rÙ | d d … | d d … f } n t d ƒ ‚ | d k	 rä| rt d	 ƒ ‚ n  | j d
 |  j | ƒ ƒ qäqçt	 | j
 ƒ j ƒ  } | d k rb|  j | | j d | ƒqç| rwt d ƒ ‚ n  | d k r¢| j d |  j | j ƒ ƒ qç| d k rÑ| j d |  j | d j ƒ ƒ qçt d | j
 ƒ ‚ n  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)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r$   r	   r	   r	   r   r      s   r   c                   sF   e  Z d  Z ‡  f d d †  Z ‡  f d d †  Z ‡  f d d †  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/   r	   r	   )r-   r   r)   U   s   r)   c                   sF   e  Z d  Z ‡  f d d †  Z ‡  f d d †  Z ‡  f d d †  Z ‡  S)ÚGeoAtom1Feedc                s#   t  t |  ƒ j ƒ  } d | d <| S)Nzhttp://www.georss.org/georsszxmlns:georss)r*   r1   Úroot_attributes)r   r,   )r-   r	   r   r2   e   s    
zGeoAtom1Feed.root_attributesc                s-   t  t |  ƒ j | | ƒ |  j | | ƒ d  S)N)r*   r1   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*   r1   r/   r$   r0   )r   r   )r-   r	   r   r/   n   s    zGeoAtom1Feed.add_root_elements)r%   r&   r'   r2   r.   r/   r	   r	   )r-   r   r1   d   s   r1   c                   sF   e  Z d  Z ‡  f d d †  Z ‡  f d d †  Z ‡  f d d †  Z ‡  S)Ú
W3CGeoFeedc                s#   t  t |  ƒ j ƒ  } d | d <| S)Nz(http://www.w3.org/2003/01/geo/wgs84_pos#z	xmlns:geo)r*   r3   r+   )r   r,   )r-   r	   r   r+   t   s    
zW3CGeoFeed.rss_attributesc                s3   t  t |  ƒ j | | ƒ |  j | | d d ƒd  S)Nr   T)r*   r3   r.   r$   )r   r   r#   )r-   r	   r   r.   y   s    zW3CGeoFeed.add_item_elementsc                s3   t  t |  ƒ j | ƒ |  j | |  j d d ƒd  S)Nr   T)r*   r3   r/   r$   r0   )r   r   )r-   r	   r   r/   }   s    zW3CGeoFeed.add_root_elements)r%   r&   r'   r+   r.   r/   r	   r	   )r-   r   r3   s   s   r3   c               @   s4   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   i |  j  d | ƒ d 6S)Nr   )Ú_get_dynamic_attr)r   Úobjr	   r	   r   Úfeed_extra_kwargsŒ   s    zFeed.feed_extra_kwargsc             C   s   i |  j  d | ƒ d 6S)NZitem_geometryr   )r4   )r   r#   r	   r	   r   Úitem_extra_kwargs   s    zFeed.item_extra_kwargsN)r%   r&   r'   r(   r)   Z	feed_typer6   r7   r	   r	   r	   r   r   ƒ   s   r   N)Ú
__future__r   Z django.contrib.syndication.viewsr   ZBaseFeedZdjango.utils.feedgeneratorr   r   Úobjectr   r)   r1   r3   r	   r	   r	   r   Ú<module>   s   N