/usr/share/pyshared/geopy/parsers/rdf.py is in python-geopy 0.95.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | try:
import xml.etree
except ImportError:
import ElementTree
else:
from xml.etree import ElementTree
from geopy import Point, Location
from geopy.parsers import Parser
from geopy.util import reversed
class GeoVocabulary(Parser):
GEO_NS = "http://www.w3.org/2003/01/geo/wgs84_pos#"
POINT_CLASS = 'Point'
LATITUDE_PROPERTY = 'lat'
LONGITUDE_PROPERTY = 'long'
ALTITUDE_PROPERTY = 'alt'
def __init__(self, ignore_invalid=True, point_class=False):
self.ignore_invalid = ignore_invalid
self.point_class = point_class
def find(self, document):
if isinstance(document, basestring):
document = ElementTree.fromstring(document)
elif not ElementTree.iselement(document):
document = ElementTree.parse(document)
point_qname = self._get_qname(self.POINT_CLASS)
lat_qname = self._get_qname(self.LATITUDE_PROPERTY)
long_qname = self._get_qname(self.LONGITUDE_PROPERTY)
alt_qname = self._get_qname(self.ALTITUDE_PROPERTY)
queue = [document]
while queue:
element = queue.pop()
if not self.point_class or element.tag == point_qname:
lat_el = element.find(lat_qname)
long_el = element.find(long_qname)
alt_el = element.find(alt_qname)
if lat_el is not None and long_el is not None:
latitude = lat_el.text
longitude = long_el.text
altitude = alt_el and alt_el.text
try:
point = Point((latitude, longitude, altitude))
except (TypeError, ValueError):
if not self.ignore_invalid:
raise
else:
yield Location(None, point)
queue.extend(reversed(element))
def _get_qname(self, name):
return "{%s}%s" % (self.GEO_NS, name)
|