/usr/lib/python2.7/dist-packages/geopy/location.py is in python-geopy 1.11.0+ds1-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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | """
:class:`.Location` returns geocoder results.
"""
from geopy.point import Point
from geopy.compat import string_compare, py3k
class Location(object): # pylint: disable=R0903,R0921
"""
Contains a parsed geocoder response. Can be iterated over as
(location<String>, (latitude<float>, longitude<Float)). Or one can access
the properties `address`, `latitude`, `longitude`, or `raw`. The last
is a dictionary of the geocoder's response for this item.
.. versionadded:: 0.98
"""
__slots__ = ("_address", "_point", "_tuple", "_raw")
def __init__(self, address="", point=None, raw=None):
self._address = address
if point is None:
self._point = (None, None, None)
elif isinstance(point, Point):
self._point = point
elif isinstance(point, string_compare):
self._point = Point(point)
elif isinstance(point, (tuple, list)):
self._point = Point(point)
else:
raise TypeError(
"point an unsupported type: %r; use %r or Point",
type(point), type(string_compare)
)
self._tuple = (self._address, (self._point[0], self._point[1]))
self._raw = raw
@property
def address(self):
"""
Location as a formatted string returned by the geocoder or constructed
by geopy, depending on the service.
:rtype: unicode
"""
return self._address
@property
def latitude(self):
"""
Location's latitude.
:rtype: float or None
"""
return self._point[0]
@property
def longitude(self):
"""
Location's longitude.
:rtype: float or None
"""
return self._point[1]
@property
def altitude(self):
"""
Location's altitude.
:rtype: float or None
"""
return self._point[2]
@property
def point(self):
"""
:class:`geopy.point.Point` instance representing the location's
latitude, longitude, and altitude.
:rtype: :class:`geopy.point.Point` or None
"""
return self._point if self._point != (None, None, None) else None
@property
def raw(self):
"""
Location's raw, unparsed geocoder response. For details on this,
consult the service's documentation.
:rtype: dict or None
"""
return self._raw
def __getitem__(self, index):
"""
Backwards compatibility with geopy<0.98 tuples.
"""
return self._tuple[index]
def __unicode__(self):
return self._address
__str__ = __unicode__
def __repr__(self):
if py3k:
return "Location(%s, (%s, %s, %s))" % (
self._address, self.latitude, self.longitude, self.altitude
)
else:
# Python 2 should not return unicode in __repr__:
# http://bugs.python.org/issue5876
return "Location((%s, %s, %s))" % (
self.latitude, self.longitude, self.altitude
)
def __iter__(self):
return iter(self._tuple)
def __eq__(self, other):
return (
isinstance(other, Location) and
self._address == other._address and # pylint: disable=W0212
self._point == other._point and # pylint: disable=W0212
self.raw == other.raw
)
def __ne__(self, other):
return not self.__eq__(other)
def __len__(self): # pragma: no cover
return len(self._tuple)
|