测试gitnore
This commit is contained in:
@@ -14,7 +14,7 @@ class GeoFeedMixin:
|
||||
a single white space. Given a tuple of coordinates, return a string
|
||||
GeoRSS representation.
|
||||
"""
|
||||
return " ".join("%f %f" % (coord[1], coord[0]) for coord in coords)
|
||||
return ' '.join('%f %f' % (coord[1], coord[0]) for coord in coords)
|
||||
|
||||
def add_georss_point(self, handler, coords, w3c_geo=False):
|
||||
"""
|
||||
@@ -24,15 +24,15 @@ class GeoFeedMixin:
|
||||
"""
|
||||
if w3c_geo:
|
||||
lon, lat = coords[:2]
|
||||
handler.addQuickElement("geo:lat", "%f" % lat)
|
||||
handler.addQuickElement("geo:lon", "%f" % lon)
|
||||
handler.addQuickElement('geo:lat', '%f' % lat)
|
||||
handler.addQuickElement('geo:lon', '%f' % lon)
|
||||
else:
|
||||
handler.addQuickElement("georss:point", self.georss_coords((coords,)))
|
||||
handler.addQuickElement('georss:point', self.georss_coords((coords,)))
|
||||
|
||||
def add_georss_element(self, handler, item, w3c_geo=False):
|
||||
"""Add a GeoRSS XML element using the given item and handler."""
|
||||
# Getting the Geometry object.
|
||||
geom = item.get("geometry")
|
||||
geom = item.get('geometry')
|
||||
if geom is not None:
|
||||
if isinstance(geom, (list, tuple)):
|
||||
# Special case if a tuple/list was passed in. The tuple may be
|
||||
@@ -43,7 +43,7 @@ class GeoFeedMixin:
|
||||
if len(geom) == 2:
|
||||
box_coords = geom
|
||||
else:
|
||||
raise ValueError("Only should be two sets of coordinates.")
|
||||
raise ValueError('Only should be two sets of coordinates.')
|
||||
else:
|
||||
if len(geom) == 2:
|
||||
# Point: (X, Y)
|
||||
@@ -52,46 +52,36 @@ class GeoFeedMixin:
|
||||
# Box: (X0, Y0, X1, Y1)
|
||||
box_coords = (geom[:2], geom[2:])
|
||||
else:
|
||||
raise ValueError("Only should be 2 or 4 numeric elements.")
|
||||
raise ValueError('Only should be 2 or 4 numeric elements.')
|
||||
# If a GeoRSS box was given via tuple.
|
||||
if box_coords is not None:
|
||||
if w3c_geo:
|
||||
raise ValueError(
|
||||
"Cannot use simple GeoRSS box in W3C Geo feeds."
|
||||
)
|
||||
handler.addQuickElement(
|
||||
"georss:box", self.georss_coords(box_coords)
|
||||
)
|
||||
raise ValueError('Cannot use simple GeoRSS box in W3C Geo feeds.')
|
||||
handler.addQuickElement('georss:box', self.georss_coords(box_coords))
|
||||
else:
|
||||
# Getting the lowercase geometry type.
|
||||
gtype = str(geom.geom_type).lower()
|
||||
if gtype == "point":
|
||||
if gtype == 'point':
|
||||
self.add_georss_point(handler, geom.coords, w3c_geo=w3c_geo)
|
||||
else:
|
||||
if w3c_geo:
|
||||
raise ValueError("W3C Geo only supports Point geometries.")
|
||||
raise ValueError('W3C Geo only supports Point geometries.')
|
||||
# For formatting consistent w/the GeoRSS simple standard:
|
||||
# http://georss.org/1.0#simple
|
||||
if gtype in ("linestring", "linearring"):
|
||||
handler.addQuickElement(
|
||||
"georss:line", self.georss_coords(geom.coords)
|
||||
)
|
||||
elif gtype in ("polygon",):
|
||||
if gtype in ('linestring', 'linearring'):
|
||||
handler.addQuickElement('georss:line', self.georss_coords(geom.coords))
|
||||
elif gtype in ('polygon',):
|
||||
# Only support the exterior ring.
|
||||
handler.addQuickElement(
|
||||
"georss:polygon", self.georss_coords(geom[0].coords)
|
||||
)
|
||||
handler.addQuickElement('georss:polygon', self.georss_coords(geom[0].coords))
|
||||
else:
|
||||
raise ValueError(
|
||||
'Geometry type "%s" not supported.' % geom.geom_type
|
||||
)
|
||||
raise ValueError('Geometry type "%s" not supported.' % geom.geom_type)
|
||||
|
||||
|
||||
# ### SyndicationFeed subclasses ###
|
||||
class GeoRSSFeed(Rss201rev2Feed, GeoFeedMixin):
|
||||
def rss_attributes(self):
|
||||
attrs = super().rss_attributes()
|
||||
attrs["xmlns:georss"] = "http://www.georss.org/georss"
|
||||
attrs['xmlns:georss'] = 'http://www.georss.org/georss'
|
||||
return attrs
|
||||
|
||||
def add_item_elements(self, handler, item):
|
||||
@@ -106,7 +96,7 @@ class GeoRSSFeed(Rss201rev2Feed, GeoFeedMixin):
|
||||
class GeoAtom1Feed(Atom1Feed, GeoFeedMixin):
|
||||
def root_attributes(self):
|
||||
attrs = super().root_attributes()
|
||||
attrs["xmlns:georss"] = "http://www.georss.org/georss"
|
||||
attrs['xmlns:georss'] = 'http://www.georss.org/georss'
|
||||
return attrs
|
||||
|
||||
def add_item_elements(self, handler, item):
|
||||
@@ -121,7 +111,7 @@ class GeoAtom1Feed(Atom1Feed, GeoFeedMixin):
|
||||
class W3CGeoFeed(Rss201rev2Feed, GeoFeedMixin):
|
||||
def rss_attributes(self):
|
||||
attrs = super().rss_attributes()
|
||||
attrs["xmlns:geo"] = "http://www.w3.org/2003/01/geo/wgs84_pos#"
|
||||
attrs['xmlns:geo'] = 'http://www.w3.org/2003/01/geo/wgs84_pos#'
|
||||
return attrs
|
||||
|
||||
def add_item_elements(self, handler, item):
|
||||
@@ -141,11 +131,10 @@ class Feed(BaseFeed):
|
||||
methods on their own subclasses so that geo-referenced information may
|
||||
placed in the feed.
|
||||
"""
|
||||
|
||||
feed_type = GeoRSSFeed
|
||||
|
||||
def feed_extra_kwargs(self, obj):
|
||||
return {"geometry": self._get_dynamic_attr("geometry", obj)}
|
||||
return {'geometry': self._get_dynamic_attr('geometry', obj)}
|
||||
|
||||
def item_extra_kwargs(self, item):
|
||||
return {"geometry": self._get_dynamic_attr("item_geometry", item)}
|
||||
return {'geometry': self._get_dynamic_attr('item_geometry', item)}
|
||||
|
||||
Reference in New Issue
Block a user