nwo
stringlengths
10
28
sha
stringlengths
40
40
path
stringlengths
11
97
identifier
stringlengths
1
64
parameters
stringlengths
2
2.24k
return_statement
stringlengths
0
2.17k
docstring
stringlengths
0
5.45k
docstring_summary
stringlengths
0
3.83k
func_begin
int64
1
13.4k
func_end
int64
2
13.4k
function
stringlengths
28
56.4k
url
stringlengths
106
209
project
int64
1
48
executed_lines
list
executed_lines_pc
float64
0
153
missing_lines
list
missing_lines_pc
float64
0
100
covered
bool
2 classes
filecoverage
float64
2.53
100
function_lines
int64
2
1.46k
mccabe
int64
1
253
coverage
float64
0
100
docstring_lines
int64
0
112
function_nodoc
stringlengths
9
56.4k
id
int64
0
29.8k
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/distance.py
Distance.nm
(self)
return self.nautical
436
437
def nm(self): return self.nautical
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/distance.py#L436-L437
31
[ 0, 1 ]
100
[]
0
true
95.977011
2
1
100
0
def nm(self): return self.nautical
20,913
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/distance.py
great_circle.__init__
(self, *args, **kwargs)
459
461
def __init__(self, *args, **kwargs): self.RADIUS = kwargs.pop('radius', EARTH_RADIUS) super().__init__(*args, **kwargs)
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/distance.py#L459-L461
31
[ 0, 1, 2 ]
100
[]
0
true
95.977011
3
1
100
0
def __init__(self, *args, **kwargs): self.RADIUS = kwargs.pop('radius', EARTH_RADIUS) super().__init__(*args, **kwargs)
20,914
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/distance.py
great_circle.measure
(self, a, b)
return self.RADIUS * d
463
481
def measure(self, a, b): a, b = Point(a), Point(b) _ensure_same_altitude(a, b) lat1, lng1 = radians(degrees=a.latitude), radians(degrees=a.longitude) lat2, lng2 = radians(degrees=b.latitude), radians(degrees=b.longitude) sin_lat1, cos_lat1 = sin(lat1), cos(lat1) sin_lat2, cos_lat2 = sin(lat2), cos(lat2) delta_lng = lng2 - lng1 cos_delta_lng, sin_delta_lng = cos(delta_lng), sin(delta_lng) d = atan2(sqrt((cos_lat2 * sin_delta_lng) ** 2 + (cos_lat1 * sin_lat2 - sin_lat1 * cos_lat2 * cos_delta_lng) ** 2), sin_lat1 * sin_lat2 + cos_lat1 * cos_lat2 * cos_delta_lng) return self.RADIUS * d
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/distance.py#L463-L481
31
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 17, 18 ]
84.210526
[]
0
false
95.977011
19
1
100
0
def measure(self, a, b): a, b = Point(a), Point(b) _ensure_same_altitude(a, b) lat1, lng1 = radians(degrees=a.latitude), radians(degrees=a.longitude) lat2, lng2 = radians(degrees=b.latitude), radians(degrees=b.longitude) sin_lat1, cos_lat1 = sin(lat1), cos(lat1) sin_lat2, cos_lat2 = sin(lat2), cos(lat2) delta_lng = lng2 - lng1 cos_delta_lng, sin_delta_lng = cos(delta_lng), sin(delta_lng) d = atan2(sqrt((cos_lat2 * sin_delta_lng) ** 2 + (cos_lat1 * sin_lat2 - sin_lat1 * cos_lat2 * cos_delta_lng) ** 2), sin_lat1 * sin_lat2 + cos_lat1 * cos_lat2 * cos_delta_lng) return self.RADIUS * d
20,915
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/distance.py
great_circle.destination
(self, point, bearing, distance=None)
return Point(units.degrees(radians=lat2), units.degrees(radians=lng2))
483
506
def destination(self, point, bearing, distance=None): point = Point(point) lat1 = units.radians(degrees=point.latitude) lng1 = units.radians(degrees=point.longitude) bearing = units.radians(degrees=bearing) if distance is None: distance = self if isinstance(distance, Distance): distance = distance.kilometers d_div_r = float(distance) / self.RADIUS lat2 = asin( sin(lat1) * cos(d_div_r) + cos(lat1) * sin(d_div_r) * cos(bearing) ) lng2 = lng1 + atan2( sin(bearing) * sin(d_div_r) * cos(lat1), cos(d_div_r) - sin(lat1) * sin(lat2) ) return Point(units.degrees(radians=lat2), units.degrees(radians=lng2))
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/distance.py#L483-L506
31
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 17, 18, 22, 23 ]
75
[]
0
false
95.977011
24
3
100
0
def destination(self, point, bearing, distance=None): point = Point(point) lat1 = units.radians(degrees=point.latitude) lng1 = units.radians(degrees=point.longitude) bearing = units.radians(degrees=bearing) if distance is None: distance = self if isinstance(distance, Distance): distance = distance.kilometers d_div_r = float(distance) / self.RADIUS lat2 = asin( sin(lat1) * cos(d_div_r) + cos(lat1) * sin(d_div_r) * cos(bearing) ) lng2 = lng1 + atan2( sin(bearing) * sin(d_div_r) * cos(lat1), cos(d_div_r) - sin(lat1) * sin(lat2) ) return Point(units.degrees(radians=lat2), units.degrees(radians=lng2))
20,916
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/distance.py
geodesic.__init__
(self, *args, **kwargs)
534
540
def __init__(self, *args, **kwargs): self.ellipsoid_key = None self.ELLIPSOID = None self.geod = None self.set_ellipsoid(kwargs.pop('ellipsoid', 'WGS-84')) major, minor, f = self.ELLIPSOID super().__init__(*args, **kwargs)
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/distance.py#L534-L540
31
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
95.977011
7
1
100
0
def __init__(self, *args, **kwargs): self.ellipsoid_key = None self.ELLIPSOID = None self.geod = None self.set_ellipsoid(kwargs.pop('ellipsoid', 'WGS-84')) major, minor, f = self.ELLIPSOID super().__init__(*args, **kwargs)
20,917
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/distance.py
geodesic.set_ellipsoid
(self, ellipsoid)
542
553
def set_ellipsoid(self, ellipsoid): if isinstance(ellipsoid, str): try: self.ELLIPSOID = ELLIPSOIDS[ellipsoid] self.ellipsoid_key = ellipsoid except KeyError: raise Exception( "Invalid ellipsoid. See geopy.distance.ELLIPSOIDS" ) else: self.ELLIPSOID = ellipsoid self.ellipsoid_key = None
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/distance.py#L542-L553
31
[ 0, 1, 2, 3, 4 ]
41.666667
[ 5, 6, 10, 11 ]
33.333333
false
95.977011
12
3
66.666667
0
def set_ellipsoid(self, ellipsoid): if isinstance(ellipsoid, str): try: self.ELLIPSOID = ELLIPSOIDS[ellipsoid] self.ellipsoid_key = ellipsoid except KeyError: raise Exception( "Invalid ellipsoid. See geopy.distance.ELLIPSOIDS" ) else: self.ELLIPSOID = ellipsoid self.ellipsoid_key = None
20,918
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/distance.py
geodesic.measure
(self, a, b)
return s12
555
569
def measure(self, a, b): a, b = Point(a), Point(b) _ensure_same_altitude(a, b) lat1, lon1 = a.latitude, a.longitude lat2, lon2 = b.latitude, b.longitude if not (isinstance(self.geod, Geodesic) and self.geod.a == self.ELLIPSOID[0] and self.geod.f == self.ELLIPSOID[2]): self.geod = Geodesic(self.ELLIPSOID[0], self.ELLIPSOID[2]) s12 = self.geod.Inverse(lat1, lon1, lat2, lon2, Geodesic.DISTANCE)['s12'] return s12
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/distance.py#L555-L569
31
[ 0, 1, 2, 3, 4, 5, 6, 9, 10, 11, 13, 14 ]
80
[]
0
false
95.977011
15
4
100
0
def measure(self, a, b): a, b = Point(a), Point(b) _ensure_same_altitude(a, b) lat1, lon1 = a.latitude, a.longitude lat2, lon2 = b.latitude, b.longitude if not (isinstance(self.geod, Geodesic) and self.geod.a == self.ELLIPSOID[0] and self.geod.f == self.ELLIPSOID[2]): self.geod = Geodesic(self.ELLIPSOID[0], self.ELLIPSOID[2]) s12 = self.geod.Inverse(lat1, lon1, lat2, lon2, Geodesic.DISTANCE)['s12'] return s12
20,919
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/distance.py
geodesic.destination
(self, point, bearing, distance=None)
return Point(r['lat2'], r['lon2'])
571
590
def destination(self, point, bearing, distance=None): point = Point(point) lat1 = point.latitude lon1 = point.longitude azi1 = bearing if distance is None: distance = self if isinstance(distance, Distance): distance = distance.kilometers if not (isinstance(self.geod, Geodesic) and self.geod.a == self.ELLIPSOID[0] and self.geod.f == self.ELLIPSOID[2]): self.geod = Geodesic(self.ELLIPSOID[0], self.ELLIPSOID[2]) r = self.geod.Direct(lat1, lon1, azi1, distance, Geodesic.LATITUDE | Geodesic.LONGITUDE) return Point(r['lat2'], r['lon2'])
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/distance.py#L571-L590
31
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14, 15, 16, 18, 19 ]
85
[]
0
false
95.977011
20
6
100
0
def destination(self, point, bearing, distance=None): point = Point(point) lat1 = point.latitude lon1 = point.longitude azi1 = bearing if distance is None: distance = self if isinstance(distance, Distance): distance = distance.kilometers if not (isinstance(self.geod, Geodesic) and self.geod.a == self.ELLIPSOID[0] and self.geod.f == self.ELLIPSOID[2]): self.geod = Geodesic(self.ELLIPSOID[0], self.ELLIPSOID[2]) r = self.geod.Direct(lat1, lon1, azi1, distance, Geodesic.LATITUDE | Geodesic.LONGITUDE) return Point(r['lat2'], r['lon2'])
20,920
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/units.py
degrees
(radians=0, arcminutes=0, arcseconds=0)
return deg
Convert angle to degrees.
Convert angle to degrees.
13
24
def degrees(radians=0, arcminutes=0, arcseconds=0): """ Convert angle to degrees. """ deg = 0. if radians: deg = math.degrees(radians) if arcminutes: deg += arcminutes / arcmin(degrees=1.) if arcseconds: deg += arcseconds / arcsec(degrees=1.) return deg
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/units.py#L13-L24
31
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
100
[]
0
true
83.333333
12
4
100
1
def degrees(radians=0, arcminutes=0, arcseconds=0): deg = 0. if radians: deg = math.degrees(radians) if arcminutes: deg += arcminutes / arcmin(degrees=1.) if arcseconds: deg += arcseconds / arcsec(degrees=1.) return deg
20,921
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/units.py
radians
(degrees=0, arcminutes=0, arcseconds=0)
return math.radians(degrees)
Convert angle to radians.
Convert angle to radians.
27
35
def radians(degrees=0, arcminutes=0, arcseconds=0): """ Convert angle to radians. """ if arcminutes: degrees += arcminutes / arcmin(degrees=1.) if arcseconds: degrees += arcseconds / arcsec(degrees=1.) return math.radians(degrees)
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/units.py#L27-L35
31
[ 0, 1, 2, 3, 4, 6, 8 ]
77.777778
[ 5, 7 ]
22.222222
false
83.333333
9
3
77.777778
1
def radians(degrees=0, arcminutes=0, arcseconds=0): if arcminutes: degrees += arcminutes / arcmin(degrees=1.) if arcseconds: degrees += arcseconds / arcsec(degrees=1.) return math.radians(degrees)
20,922
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/units.py
arcminutes
(degrees=0, radians=0, arcseconds=0)
return degrees * 60.
Convert angle to arcminutes.
Convert angle to arcminutes.
38
46
def arcminutes(degrees=0, radians=0, arcseconds=0): """ Convert angle to arcminutes. """ if radians: degrees += math.degrees(radians) if arcseconds: degrees += arcseconds / arcsec(degrees=1.) return degrees * 60.
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/units.py#L38-L46
31
[ 0, 1, 2, 3, 4, 6, 8 ]
77.777778
[ 5, 7 ]
22.222222
false
83.333333
9
3
77.777778
1
def arcminutes(degrees=0, radians=0, arcseconds=0): if radians: degrees += math.degrees(radians) if arcseconds: degrees += arcseconds / arcsec(degrees=1.) return degrees * 60.
20,923
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/units.py
arcseconds
(degrees=0, radians=0, arcminutes=0)
return degrees * 3600.
Convert angle to arcseconds.
Convert angle to arcseconds.
49
57
def arcseconds(degrees=0, radians=0, arcminutes=0): """ Convert angle to arcseconds. """ if radians: degrees += math.degrees(radians) if arcminutes: degrees += arcminutes / arcmin(degrees=1.) return degrees * 3600.
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/units.py#L49-L57
31
[ 0, 1, 2, 3, 4, 6, 7, 8 ]
88.888889
[ 5 ]
11.111111
false
83.333333
9
3
88.888889
1
def arcseconds(degrees=0, radians=0, arcminutes=0): if radians: degrees += math.degrees(radians) if arcminutes: degrees += arcminutes / arcmin(degrees=1.) return degrees * 3600.
20,924
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/units.py
kilometers
(meters=0, miles=0, feet=0, nautical=0)
return ret
Convert distance to kilometers.
Convert distance to kilometers.
62
74
def kilometers(meters=0, miles=0, feet=0, nautical=0): """ Convert distance to kilometers. """ ret = 0. if meters: ret += meters / 1000. if feet: ret += feet / ft(1.) if nautical: ret += nautical / nm(1.) ret += miles * 1.609344 return ret
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/units.py#L62-L74
31
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]
100
[]
0
true
83.333333
13
4
100
1
def kilometers(meters=0, miles=0, feet=0, nautical=0): ret = 0. if meters: ret += meters / 1000. if feet: ret += feet / ft(1.) if nautical: ret += nautical / nm(1.) ret += miles * 1.609344 return ret
20,925
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/units.py
meters
(kilometers=0, miles=0, feet=0, nautical=0)
return (kilometers + km(nautical=nautical, miles=miles, feet=feet)) * 1000
Convert distance to meters.
Convert distance to meters.
77
81
def meters(kilometers=0, miles=0, feet=0, nautical=0): """ Convert distance to meters. """ return (kilometers + km(nautical=nautical, miles=miles, feet=feet)) * 1000
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/units.py#L77-L81
31
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
83.333333
5
1
100
1
def meters(kilometers=0, miles=0, feet=0, nautical=0): return (kilometers + km(nautical=nautical, miles=miles, feet=feet)) * 1000
20,926
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/units.py
miles
(kilometers=0, meters=0, feet=0, nautical=0)
return ret
Convert distance to miles.
Convert distance to miles.
84
96
def miles(kilometers=0, meters=0, feet=0, nautical=0): """ Convert distance to miles. """ ret = 0. if nautical: kilometers += nautical / nm(1.) if feet: kilometers += feet / ft(1.) if meters: kilometers += meters / 1000. ret += kilometers / 1.609344 return ret
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/units.py#L84-L96
31
[ 0, 1, 2, 3, 4, 5, 7, 9, 11, 12 ]
76.923077
[ 6, 8, 10 ]
23.076923
false
83.333333
13
4
76.923077
1
def miles(kilometers=0, meters=0, feet=0, nautical=0): ret = 0. if nautical: kilometers += nautical / nm(1.) if feet: kilometers += feet / ft(1.) if meters: kilometers += meters / 1000. ret += kilometers / 1.609344 return ret
20,927
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/units.py
feet
(kilometers=0, meters=0, miles=0, nautical=0)
return ret
Convert distance to feet.
Convert distance to feet.
99
111
def feet(kilometers=0, meters=0, miles=0, nautical=0): """ Convert distance to feet. """ ret = 0. if nautical: kilometers += nautical / nm(1.) if meters: kilometers += meters / 1000. if kilometers: miles += mi(kilometers=kilometers) ret += miles * 5280 return ret
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/units.py#L99-L111
31
[ 0, 1, 2, 3, 4, 5, 7, 9, 10, 11, 12 ]
84.615385
[ 6, 8 ]
15.384615
false
83.333333
13
4
84.615385
1
def feet(kilometers=0, meters=0, miles=0, nautical=0): ret = 0. if nautical: kilometers += nautical / nm(1.) if meters: kilometers += meters / 1000. if kilometers: miles += mi(kilometers=kilometers) ret += miles * 5280 return ret
20,928
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/units.py
nautical
(kilometers=0, meters=0, miles=0, feet=0)
return ret
Convert distance to nautical miles.
Convert distance to nautical miles.
114
126
def nautical(kilometers=0, meters=0, miles=0, feet=0): """ Convert distance to nautical miles. """ ret = 0. if feet: kilometers += feet / ft(1.) if miles: kilometers += km(miles=miles) if meters: kilometers += meters / 1000. ret += kilometers / 1.852 return ret
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/units.py#L114-L126
31
[ 0, 1, 2, 3, 4, 5, 7, 9, 11, 12 ]
76.923077
[ 6, 8, 10 ]
23.076923
false
83.333333
13
4
76.923077
1
def nautical(kilometers=0, meters=0, miles=0, feet=0): ret = 0. if feet: kilometers += feet / ft(1.) if miles: kilometers += km(miles=miles) if meters: kilometers += meters / 1000. ret += kilometers / 1.852 return ret
20,929
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/point.py
_normalize_angle
(x, limit)
return modulo
Normalize angle `x` to be within `[-limit; limit)` range.
Normalize angle `x` to be within `[-limit; limit)` range.
43
53
def _normalize_angle(x, limit): """ Normalize angle `x` to be within `[-limit; limit)` range. """ double_limit = limit * 2.0 modulo = fmod(x, double_limit) or 0.0 # `or 0` is to turn -0 to +0. if modulo < -limit: return modulo + double_limit if modulo >= limit: return modulo - double_limit return modulo
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/point.py#L43-L53
31
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
94.771242
11
4
100
1
def _normalize_angle(x, limit): double_limit = limit * 2.0 modulo = fmod(x, double_limit) or 0.0 # `or 0` is to turn -0 to +0. if modulo < -limit: return modulo + double_limit if modulo >= limit: return modulo - double_limit return modulo
20,930
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/point.py
_normalize_coordinates
(latitude, longitude, altitude)
return latitude, longitude, altitude
56
81
def _normalize_coordinates(latitude, longitude, altitude): latitude = float(latitude or 0.0) longitude = float(longitude or 0.0) altitude = float(altitude or 0.0) is_all_finite = all(isfinite(x) for x in (latitude, longitude, altitude)) if not is_all_finite: raise ValueError('Point coordinates must be finite. %r has been passed ' 'as coordinates.' % ((latitude, longitude, altitude),)) if abs(latitude) > 90: warnings.warn('Latitude normalization has been prohibited in the newer ' 'versions of geopy, because the normalized value happened ' 'to be on a different pole, which is probably not what was ' 'meant. If you pass coordinates as positional args, ' 'please make sure that the order is ' '(latitude, longitude) or (y, x) in Cartesian terms.', UserWarning, stacklevel=3) raise ValueError('Latitude must be in the [-90; 90] range.') if abs(longitude) > 180: # Longitude normalization is pretty straightforward and doesn't seem # to be error-prone, so there's nothing to complain about. longitude = _normalize_angle(longitude, 180.0) return latitude, longitude, altitude
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/point.py#L56-L81
31
[ 0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 18, 19, 20, 21, 22, 23, 24, 25 ]
73.076923
[]
0
false
94.771242
26
7
100
0
def _normalize_coordinates(latitude, longitude, altitude): latitude = float(latitude or 0.0) longitude = float(longitude or 0.0) altitude = float(altitude or 0.0) is_all_finite = all(isfinite(x) for x in (latitude, longitude, altitude)) if not is_all_finite: raise ValueError('Point coordinates must be finite. %r has been passed ' 'as coordinates.' % ((latitude, longitude, altitude),)) if abs(latitude) > 90: warnings.warn('Latitude normalization has been prohibited in the newer ' 'versions of geopy, because the normalized value happened ' 'to be on a different pole, which is probably not what was ' 'meant. If you pass coordinates as positional args, ' 'please make sure that the order is ' '(latitude, longitude) or (y, x) in Cartesian terms.', UserWarning, stacklevel=3) raise ValueError('Latitude must be in the [-90; 90] range.') if abs(longitude) > 180: # Longitude normalization is pretty straightforward and doesn't seem # to be error-prone, so there's nothing to complain about. longitude = _normalize_angle(longitude, 180.0) return latitude, longitude, altitude
20,931
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/point.py
Point.__new__
(cls, latitude=None, longitude=None, altitude=None)
return self
:param float latitude: Latitude of point. :param float longitude: Longitude of point. :param float altitude: Altitude of point.
:param float latitude: Latitude of point. :param float longitude: Longitude of point. :param float altitude: Altitude of point.
154
194
def __new__(cls, latitude=None, longitude=None, altitude=None): """ :param float latitude: Latitude of point. :param float longitude: Longitude of point. :param float altitude: Altitude of point. """ single_arg = latitude is not None and longitude is None and altitude is None if single_arg and not isinstance(latitude, util.NUMBER_TYPES): arg = latitude if isinstance(arg, Point): return cls.from_point(arg) elif isinstance(arg, str): return cls.from_string(arg) else: try: seq = iter(arg) except TypeError: raise TypeError( "Failed to create Point instance from %r." % (arg,) ) else: return cls.from_sequence(seq) if single_arg: raise ValueError( 'A single number has been passed to the Point ' 'constructor. This is probably a mistake, because ' 'constructing a Point with just a latitude ' 'seems senseless. If this is exactly what was ' 'meant, then pass the zero longitude explicitly ' 'to get rid of this error.' ) latitude, longitude, altitude = \ _normalize_coordinates(latitude, longitude, altitude) self = super().__new__(cls) self.latitude = latitude self.longitude = longitude self.altitude = altitude return self
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/point.py#L154-L194
31
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 ]
90.243902
[ 16, 17 ]
4.878049
false
94.771242
41
9
95.121951
3
def __new__(cls, latitude=None, longitude=None, altitude=None): single_arg = latitude is not None and longitude is None and altitude is None if single_arg and not isinstance(latitude, util.NUMBER_TYPES): arg = latitude if isinstance(arg, Point): return cls.from_point(arg) elif isinstance(arg, str): return cls.from_string(arg) else: try: seq = iter(arg) except TypeError: raise TypeError( "Failed to create Point instance from %r." % (arg,) ) else: return cls.from_sequence(seq) if single_arg: raise ValueError( 'A single number has been passed to the Point ' 'constructor. This is probably a mistake, because ' 'constructing a Point with just a latitude ' 'seems senseless. If this is exactly what was ' 'meant, then pass the zero longitude explicitly ' 'to get rid of this error.' ) latitude, longitude, altitude = \ _normalize_coordinates(latitude, longitude, altitude) self = super().__new__(cls) self.latitude = latitude self.longitude = longitude self.altitude = altitude return self
20,932
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/point.py
Point.__getitem__
(self, index)
return tuple(self)[index]
196
197
def __getitem__(self, index): return tuple(self)[index]
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/point.py#L196-L197
31
[ 0, 1 ]
100
[]
0
true
94.771242
2
1
100
0
def __getitem__(self, index): return tuple(self)[index]
20,933
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/point.py
Point.__setitem__
(self, index, value)
199
203
def __setitem__(self, index, value): point = list(self) point[index] = value # list handles slices self.latitude, self.longitude, self.altitude = \ _normalize_coordinates(*point)
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/point.py#L199-L203
31
[ 0, 1, 2, 3 ]
80
[]
0
false
94.771242
5
1
100
0
def __setitem__(self, index, value): point = list(self) point[index] = value # list handles slices self.latitude, self.longitude, self.altitude = \ _normalize_coordinates(*point)
20,934
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/point.py
Point.__iter__
(self)
return iter((self.latitude, self.longitude, self.altitude))
205
206
def __iter__(self): return iter((self.latitude, self.longitude, self.altitude))
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/point.py#L205-L206
31
[ 0, 1 ]
100
[]
0
true
94.771242
2
1
100
0
def __iter__(self): return iter((self.latitude, self.longitude, self.altitude))
20,935
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/point.py
Point.__getstate__
(self)
return tuple(self)
208
209
def __getstate__(self): return tuple(self)
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/point.py#L208-L209
31
[ 0, 1 ]
100
[]
0
true
94.771242
2
1
100
0
def __getstate__(self): return tuple(self)
20,936
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/point.py
Point.__setstate__
(self, state)
211
212
def __setstate__(self, state): self.latitude, self.longitude, self.altitude = state
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/point.py#L211-L212
31
[ 0, 1 ]
100
[]
0
true
94.771242
2
1
100
0
def __setstate__(self, state): self.latitude, self.longitude, self.altitude = state
20,937
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/point.py
Point.__repr__
(self)
return "Point(%r, %r, %r)" % tuple(self)
214
215
def __repr__(self): return "Point(%r, %r, %r)" % tuple(self)
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/point.py#L214-L215
31
[ 0 ]
50
[ 1 ]
50
false
94.771242
2
1
50
0
def __repr__(self): return "Point(%r, %r, %r)" % tuple(self)
20,938
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/point.py
Point.format
(self, altitude=None, deg_char='', min_char='m', sec_char='s')
return ", ".join(coordinates)
Format decimal degrees (DD) to degrees minutes seconds (DMS):: >>> p = Point(41.5, -81.0, 12.3) >>> p.format() '41 30m 0s N, 81 0m 0s W, 12.3km' >>> p = Point(41.5, 0, 0) >>> p.format() '41 30m 0s N, 0 0m 0s E' See also :meth:`.format_unicode`. :param bool altitude: Whether to include ``altitude`` value. By default it is automatically included if it is non-zero.
Format decimal degrees (DD) to degrees minutes seconds (DMS)::
217
254
def format(self, altitude=None, deg_char='', min_char='m', sec_char='s'): """ Format decimal degrees (DD) to degrees minutes seconds (DMS):: >>> p = Point(41.5, -81.0, 12.3) >>> p.format() '41 30m 0s N, 81 0m 0s W, 12.3km' >>> p = Point(41.5, 0, 0) >>> p.format() '41 30m 0s N, 0 0m 0s E' See also :meth:`.format_unicode`. :param bool altitude: Whether to include ``altitude`` value. By default it is automatically included if it is non-zero. """ latitude = "%s %s" % ( format_degrees(abs(self.latitude), symbols={ 'deg': deg_char, 'arcmin': min_char, 'arcsec': sec_char }), self.latitude >= 0 and 'N' or 'S' ) longitude = "%s %s" % ( format_degrees(abs(self.longitude), symbols={ 'deg': deg_char, 'arcmin': min_char, 'arcsec': sec_char }), self.longitude >= 0 and 'E' or 'W' ) coordinates = [latitude, longitude] if altitude is None: altitude = bool(self.altitude) if altitude: if not isinstance(altitude, str): altitude = 'km' coordinates.append(self.format_altitude(altitude)) return ", ".join(coordinates)
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/point.py#L217-L254
31
[ 0, 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 ]
100
[]
0
true
94.771242
38
8
100
13
def format(self, altitude=None, deg_char='', min_char='m', sec_char='s'): latitude = "%s %s" % ( format_degrees(abs(self.latitude), symbols={ 'deg': deg_char, 'arcmin': min_char, 'arcsec': sec_char }), self.latitude >= 0 and 'N' or 'S' ) longitude = "%s %s" % ( format_degrees(abs(self.longitude), symbols={ 'deg': deg_char, 'arcmin': min_char, 'arcsec': sec_char }), self.longitude >= 0 and 'E' or 'W' ) coordinates = [latitude, longitude] if altitude is None: altitude = bool(self.altitude) if altitude: if not isinstance(altitude, str): altitude = 'km' coordinates.append(self.format_altitude(altitude)) return ", ".join(coordinates)
20,939
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/point.py
Point.format_unicode
(self, altitude=None)
return self.format( altitude, DEGREE, PRIME, DOUBLE_PRIME )
:meth:`.format` with pretty unicode chars for degrees, minutes and seconds:: >>> p = Point(41.5, -81.0, 12.3) >>> p.format_unicode() '41° 30′ 0″ N, 81° 0′ 0″ W, 12.3km' :param bool altitude: Whether to include ``altitude`` value. By default it is automatically included if it is non-zero.
:meth:`.format` with pretty unicode chars for degrees, minutes and seconds::
256
270
def format_unicode(self, altitude=None): """ :meth:`.format` with pretty unicode chars for degrees, minutes and seconds:: >>> p = Point(41.5, -81.0, 12.3) >>> p.format_unicode() '41° 30′ 0″ N, 81° 0′ 0″ W, 12.3km' :param bool altitude: Whether to include ``altitude`` value. By default it is automatically included if it is non-zero. """ return self.format( altitude, DEGREE, PRIME, DOUBLE_PRIME )
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/point.py#L256-L270
31
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
80
[ 12 ]
6.666667
false
94.771242
15
1
93.333333
9
def format_unicode(self, altitude=None): return self.format( altitude, DEGREE, PRIME, DOUBLE_PRIME )
20,940
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/point.py
Point.format_decimal
(self, altitude=None)
return ", ".join(coordinates)
Format decimal degrees with altitude:: >>> p = Point(41.5, -81.0, 12.3) >>> p.format_decimal() '41.5, -81.0, 12.3km' >>> p = Point(41.5, 0, 0) >>> p.format_decimal() '41.5, 0.0' :param bool altitude: Whether to include ``altitude`` value. By default it is automatically included if it is non-zero.
Format decimal degrees with altitude::
272
295
def format_decimal(self, altitude=None): """ Format decimal degrees with altitude:: >>> p = Point(41.5, -81.0, 12.3) >>> p.format_decimal() '41.5, -81.0, 12.3km' >>> p = Point(41.5, 0, 0) >>> p.format_decimal() '41.5, 0.0' :param bool altitude: Whether to include ``altitude`` value. By default it is automatically included if it is non-zero. """ coordinates = [str(self.latitude), str(self.longitude)] if altitude is None: altitude = bool(self.altitude) if altitude: if not isinstance(altitude, str): altitude = 'km' coordinates.append(self.format_altitude(altitude)) return ", ".join(coordinates)
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/point.py#L272-L295
31
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 ]
100
[]
0
true
94.771242
24
4
100
11
def format_decimal(self, altitude=None): coordinates = [str(self.latitude), str(self.longitude)] if altitude is None: altitude = bool(self.altitude) if altitude: if not isinstance(altitude, str): altitude = 'km' coordinates.append(self.format_altitude(altitude)) return ", ".join(coordinates)
20,941
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/point.py
Point.format_altitude
(self, unit='km')
return format_distance(self.altitude, unit=unit)
Format altitude with unit:: >>> p = Point(41.5, -81.0, 12.3) >>> p.format_altitude() '12.3km' >>> p = Point(41.5, -81.0, 0) >>> p.format_altitude() '0.0km' :param str unit: Resulting altitude unit. Supported units are listed in :meth:`.from_string` doc.
Format altitude with unit::
297
311
def format_altitude(self, unit='km'): """ Format altitude with unit:: >>> p = Point(41.5, -81.0, 12.3) >>> p.format_altitude() '12.3km' >>> p = Point(41.5, -81.0, 0) >>> p.format_altitude() '0.0km' :param str unit: Resulting altitude unit. Supported units are listed in :meth:`.from_string` doc. """ return format_distance(self.altitude, unit=unit)
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/point.py#L297-L311
31
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ]
100
[]
0
true
94.771242
15
1
100
11
def format_altitude(self, unit='km'): return format_distance(self.altitude, unit=unit)
20,942
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/point.py
Point.__str__
(self)
return self.format()
313
314
def __str__(self): return self.format()
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/point.py#L313-L314
31
[ 0 ]
50
[ 1 ]
50
false
94.771242
2
1
50
0
def __str__(self): return self.format()
20,943
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/point.py
Point.__eq__
(self, other)
return tuple(self) == tuple(other)
316
319
def __eq__(self, other): if not isinstance(other, collections.abc.Iterable): return NotImplemented return tuple(self) == tuple(other)
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/point.py#L316-L319
31
[ 0, 1, 2, 3 ]
100
[]
0
true
94.771242
4
2
100
0
def __eq__(self, other): if not isinstance(other, collections.abc.Iterable): return NotImplemented return tuple(self) == tuple(other)
20,944
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/point.py
Point.__ne__
(self, other)
return not (self == other)
321
322
def __ne__(self, other): return not (self == other)
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/point.py#L321-L322
31
[ 0, 1 ]
100
[]
0
true
94.771242
2
1
100
0
def __ne__(self, other): return not (self == other)
20,945
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/point.py
Point.parse_degrees
(cls, degrees, arcminutes, arcseconds, direction=None)
Convert degrees, minutes, seconds and direction (N, S, E, W) to a single degrees number. :rtype: float
Convert degrees, minutes, seconds and direction (N, S, E, W) to a single degrees number.
325
349
def parse_degrees(cls, degrees, arcminutes, arcseconds, direction=None): """ Convert degrees, minutes, seconds and direction (N, S, E, W) to a single degrees number. :rtype: float """ degrees = float(degrees) negative = degrees < 0 arcminutes = float(arcminutes) arcseconds = float(arcseconds) if arcminutes or arcseconds: more = units.degrees(arcminutes=arcminutes, arcseconds=arcseconds) if negative: degrees -= more else: degrees += more if direction in [None, 'N', 'E']: return degrees elif direction in ['S', 'W']: return -degrees else: raise ValueError("Invalid direction! Should be one of [NSEW].")
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/point.py#L325-L349
31
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 ]
96
[ 24 ]
4
false
94.771242
25
6
96
4
def parse_degrees(cls, degrees, arcminutes, arcseconds, direction=None): degrees = float(degrees) negative = degrees < 0 arcminutes = float(arcminutes) arcseconds = float(arcseconds) if arcminutes or arcseconds: more = units.degrees(arcminutes=arcminutes, arcseconds=arcseconds) if negative: degrees -= more else: degrees += more if direction in [None, 'N', 'E']: return degrees elif direction in ['S', 'W']: return -degrees else: raise ValueError("Invalid direction! Should be one of [NSEW].")
20,946
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/point.py
Point.parse_altitude
(cls, distance, unit)
Parse altitude managing units conversion:: >>> Point.parse_altitude(712, 'm') 0.712 >>> Point.parse_altitude(712, 'km') 712.0 >>> Point.parse_altitude(712, 'mi') 1145.852928 :param float distance: Numeric value of altitude. :param str unit: ``distance`` unit. Supported units are listed in :meth:`.from_string` doc.
Parse altitude managing units conversion::
352
385
def parse_altitude(cls, distance, unit): """ Parse altitude managing units conversion:: >>> Point.parse_altitude(712, 'm') 0.712 >>> Point.parse_altitude(712, 'km') 712.0 >>> Point.parse_altitude(712, 'mi') 1145.852928 :param float distance: Numeric value of altitude. :param str unit: ``distance`` unit. Supported units are listed in :meth:`.from_string` doc. """ if distance is not None: distance = float(distance) CONVERTERS = { 'km': lambda d: d, 'm': lambda d: units.kilometers(meters=d), 'mi': lambda d: units.kilometers(miles=d), 'ft': lambda d: units.kilometers(feet=d), 'nm': lambda d: units.kilometers(nautical=d), 'nmi': lambda d: units.kilometers(nautical=d) } try: return CONVERTERS[unit](distance) except KeyError: raise NotImplementedError( 'Bad distance unit specified, valid are: %r' % CONVERTERS.keys() ) else: return distance
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/point.py#L352-L385
31
[ 0, 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, 32, 33 ]
85.294118
[ 27, 28 ]
5.882353
false
94.771242
34
3
94.117647
12
def parse_altitude(cls, distance, unit): if distance is not None: distance = float(distance) CONVERTERS = { 'km': lambda d: d, 'm': lambda d: units.kilometers(meters=d), 'mi': lambda d: units.kilometers(miles=d), 'ft': lambda d: units.kilometers(feet=d), 'nm': lambda d: units.kilometers(nautical=d), 'nmi': lambda d: units.kilometers(nautical=d) } try: return CONVERTERS[unit](distance) except KeyError: raise NotImplementedError( 'Bad distance unit specified, valid are: %r' % CONVERTERS.keys() ) else: return distance
20,947
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/point.py
Point.from_string
(cls, string)
Create and return a ``Point`` instance from a string containing latitude and longitude, and optionally, altitude. Latitude and longitude must be in degrees and may be in decimal form or indicate arcminutes and arcseconds (labeled with Unicode prime and double prime, ASCII quote and double quote or 'm' and 's'). The degree symbol is optional and may be included after the decimal places (in decimal form) and before the arcminutes and arcseconds otherwise. Coordinates given from south and west (indicated by S and W suffixes) will be converted to north and east by switching their signs. If no (or partial) cardinal directions are given, north and east are the assumed directions. Latitude and longitude must be separated by at least whitespace, a comma, or a semicolon (each with optional surrounding whitespace). Altitude, if supplied, must be a decimal number with given units. The following unit abbrevations (case-insensitive) are supported: - ``km`` (kilometers) - ``m`` (meters) - ``mi`` (miles) - ``ft`` (feet) - ``nm``, ``nmi`` (nautical miles) Some example strings that will work include: - ``41.5;-81.0`` - ``41.5,-81.0`` - ``41.5 -81.0`` - ``41.5 N -81.0 W`` - ``-41.5 S;81.0 E`` - ``23 26m 22s N 23 27m 30s E`` - ``23 26' 22" N 23 27' 30" E`` - ``UT: N 39°20' 0'' / W 74°35' 0''``
Create and return a ``Point`` instance from a string containing latitude and longitude, and optionally, altitude.
388
459
def from_string(cls, string): """ Create and return a ``Point`` instance from a string containing latitude and longitude, and optionally, altitude. Latitude and longitude must be in degrees and may be in decimal form or indicate arcminutes and arcseconds (labeled with Unicode prime and double prime, ASCII quote and double quote or 'm' and 's'). The degree symbol is optional and may be included after the decimal places (in decimal form) and before the arcminutes and arcseconds otherwise. Coordinates given from south and west (indicated by S and W suffixes) will be converted to north and east by switching their signs. If no (or partial) cardinal directions are given, north and east are the assumed directions. Latitude and longitude must be separated by at least whitespace, a comma, or a semicolon (each with optional surrounding whitespace). Altitude, if supplied, must be a decimal number with given units. The following unit abbrevations (case-insensitive) are supported: - ``km`` (kilometers) - ``m`` (meters) - ``mi`` (miles) - ``ft`` (feet) - ``nm``, ``nmi`` (nautical miles) Some example strings that will work include: - ``41.5;-81.0`` - ``41.5,-81.0`` - ``41.5 -81.0`` - ``41.5 N -81.0 W`` - ``-41.5 S;81.0 E`` - ``23 26m 22s N 23 27m 30s E`` - ``23 26' 22" N 23 27' 30" E`` - ``UT: N 39°20' 0'' / W 74°35' 0''`` """ match = re.match(cls.POINT_PATTERN, re.sub(r"''", r'"', string)) if match: latitude_direction = None if match.group("latitude_direction_front"): latitude_direction = match.group("latitude_direction_front") elif match.group("latitude_direction_back"): latitude_direction = match.group("latitude_direction_back") longitude_direction = None if match.group("longitude_direction_front"): longitude_direction = match.group("longitude_direction_front") elif match.group("longitude_direction_back"): longitude_direction = match.group("longitude_direction_back") latitude = cls.parse_degrees( match.group('latitude_degrees') or 0.0, match.group('latitude_arcminutes') or 0.0, match.group('latitude_arcseconds') or 0.0, latitude_direction ) longitude = cls.parse_degrees( match.group('longitude_degrees') or 0.0, match.group('longitude_arcminutes') or 0.0, match.group('longitude_arcseconds') or 0.0, longitude_direction ) altitude = cls.parse_altitude( match.group('altitude_distance'), match.group('altitude_units') ) return cls(latitude, longitude, altitude) else: raise ValueError( "Failed to create Point instance from string: unknown format." )
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/point.py#L388-L459
31
[ 0, 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 ]
100
[]
0
true
94.771242
72
12
100
34
def from_string(cls, string): match = re.match(cls.POINT_PATTERN, re.sub(r"''", r'"', string)) if match: latitude_direction = None if match.group("latitude_direction_front"): latitude_direction = match.group("latitude_direction_front") elif match.group("latitude_direction_back"): latitude_direction = match.group("latitude_direction_back") longitude_direction = None if match.group("longitude_direction_front"): longitude_direction = match.group("longitude_direction_front") elif match.group("longitude_direction_back"): longitude_direction = match.group("longitude_direction_back") latitude = cls.parse_degrees( match.group('latitude_degrees') or 0.0, match.group('latitude_arcminutes') or 0.0, match.group('latitude_arcseconds') or 0.0, latitude_direction ) longitude = cls.parse_degrees( match.group('longitude_degrees') or 0.0, match.group('longitude_arcminutes') or 0.0, match.group('longitude_arcseconds') or 0.0, longitude_direction ) altitude = cls.parse_altitude( match.group('altitude_distance'), match.group('altitude_units') ) return cls(latitude, longitude, altitude) else: raise ValueError( "Failed to create Point instance from string: unknown format." )
20,948
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/point.py
Point.from_sequence
(cls, seq)
return cls(*args)
Create and return a new ``Point`` instance from any iterable with 2 to 3 elements. The elements, if present, must be latitude, longitude, and altitude, respectively.
Create and return a new ``Point`` instance from any iterable with 2 to 3 elements. The elements, if present, must be latitude, longitude, and altitude, respectively.
462
472
def from_sequence(cls, seq): """ Create and return a new ``Point`` instance from any iterable with 2 to 3 elements. The elements, if present, must be latitude, longitude, and altitude, respectively. """ args = tuple(islice(seq, 4)) if len(args) > 3: raise ValueError('When creating a Point from sequence, it ' 'must not have more than 3 items.') return cls(*args)
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/point.py#L462-L472
31
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
94.771242
11
2
100
3
def from_sequence(cls, seq): args = tuple(islice(seq, 4)) if len(args) > 3: raise ValueError('When creating a Point from sequence, it ' 'must not have more than 3 items.') return cls(*args)
20,949
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/point.py
Point.from_point
(cls, point)
return cls(point.latitude, point.longitude, point.altitude)
Create and return a new ``Point`` instance from another ``Point`` instance.
Create and return a new ``Point`` instance from another ``Point`` instance.
475
480
def from_point(cls, point): """ Create and return a new ``Point`` instance from another ``Point`` instance. """ return cls(point.latitude, point.longitude, point.altitude)
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/point.py#L475-L480
31
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
94.771242
6
1
100
2
def from_point(cls, point): return cls(point.latitude, point.longitude, point.altitude)
20,950
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/timezone.py
ensure_pytz_is_installed
()
15
21
def ensure_pytz_is_installed(): if not pytz_available: raise ImportError( 'pytz must be installed in order to locate timezones. ' 'If geopy has been installed with `pip`, then pytz can be ' 'installed with `pip install "geopy[timezone]"`.' )
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/timezone.py#L15-L21
31
[ 0 ]
14.285714
[ 1, 2 ]
28.571429
false
47.826087
7
2
71.428571
0
def ensure_pytz_is_installed(): if not pytz_available: raise ImportError( 'pytz must be installed in order to locate timezones. ' 'If geopy has been installed with `pip`, then pytz can be ' 'installed with `pip install "geopy[timezone]"`.' )
20,951
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/timezone.py
from_timezone_name
(timezone_name, raw)
return Timezone(pytz_timezone, raw)
24
38
def from_timezone_name(timezone_name, raw): ensure_pytz_is_installed() try: pytz_timezone = pytz.timezone(timezone_name) except pytz.UnknownTimeZoneError: raise GeocoderParseError( "pytz could not parse the timezone identifier (%s) " "returned by the service." % timezone_name ) except KeyError: raise GeocoderParseError( "geopy could not find a timezone in this response: %s" % raw ) return Timezone(pytz_timezone, raw)
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/timezone.py#L24-L38
31
[ 0 ]
6.666667
[ 1, 2, 3, 4, 5, 9, 10, 14 ]
53.333333
false
47.826087
15
3
46.666667
0
def from_timezone_name(timezone_name, raw): ensure_pytz_is_installed() try: pytz_timezone = pytz.timezone(timezone_name) except pytz.UnknownTimeZoneError: raise GeocoderParseError( "pytz could not parse the timezone identifier (%s) " "returned by the service." % timezone_name ) except KeyError: raise GeocoderParseError( "geopy could not find a timezone in this response: %s" % raw ) return Timezone(pytz_timezone, raw)
20,952
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/timezone.py
from_fixed_gmt_offset
(gmt_offset_hours, raw)
return Timezone(pytz_timezone, raw)
41
44
def from_fixed_gmt_offset(gmt_offset_hours, raw): ensure_pytz_is_installed() pytz_timezone = pytz.FixedOffset(gmt_offset_hours * 60) return Timezone(pytz_timezone, raw)
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/timezone.py#L41-L44
31
[ 0 ]
25
[ 1, 2, 3 ]
75
false
47.826087
4
1
25
0
def from_fixed_gmt_offset(gmt_offset_hours, raw): ensure_pytz_is_installed() pytz_timezone = pytz.FixedOffset(gmt_offset_hours * 60) return Timezone(pytz_timezone, raw)
20,953
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/timezone.py
Timezone.__init__
(self, pytz_timezone, raw)
55
57
def __init__(self, pytz_timezone, raw): self._pytz_timezone = pytz_timezone self._raw = raw
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/timezone.py#L55-L57
31
[ 0 ]
33.333333
[ 1, 2 ]
66.666667
false
47.826087
3
1
33.333333
0
def __init__(self, pytz_timezone, raw): self._pytz_timezone = pytz_timezone self._raw = raw
20,954
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/timezone.py
Timezone.pytz_timezone
(self)
return self._pytz_timezone
pytz timezone instance. :rtype: :class:`pytz.tzinfo.BaseTzInfo`
pytz timezone instance.
60
66
def pytz_timezone(self): """ pytz timezone instance. :rtype: :class:`pytz.tzinfo.BaseTzInfo` """ return self._pytz_timezone
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/timezone.py#L60-L66
31
[ 0, 1, 2, 3, 4, 5 ]
85.714286
[ 6 ]
14.285714
false
47.826087
7
1
85.714286
3
def pytz_timezone(self): return self._pytz_timezone
20,955
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/timezone.py
Timezone.raw
(self)
return self._raw
Timezone's raw, unparsed geocoder response. For details on this, consult the service's documentation. :rtype: dict
Timezone's raw, unparsed geocoder response. For details on this, consult the service's documentation.
69
76
def raw(self): """ Timezone's raw, unparsed geocoder response. For details on this, consult the service's documentation. :rtype: dict """ return self._raw
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/timezone.py#L69-L76
31
[ 0, 1, 2, 3, 4, 5, 6 ]
87.5
[ 7 ]
12.5
false
47.826087
8
1
87.5
4
def raw(self): return self._raw
20,956
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/timezone.py
Timezone.__str__
(self)
return str(self._pytz_timezone)
78
79
def __str__(self): return str(self._pytz_timezone)
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/timezone.py#L78-L79
31
[ 0 ]
50
[ 1 ]
50
false
47.826087
2
1
50
0
def __str__(self): return str(self._pytz_timezone)
20,957
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/timezone.py
Timezone.__repr__
(self)
return "Timezone(%s)" % repr(self.pytz_timezone)
81
82
def __repr__(self): return "Timezone(%s)" % repr(self.pytz_timezone)
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/timezone.py#L81-L82
31
[ 0 ]
50
[ 1 ]
50
false
47.826087
2
1
50
0
def __repr__(self): return "Timezone(%s)" % repr(self.pytz_timezone)
20,958
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/timezone.py
Timezone.__getstate__
(self)
return self._pytz_timezone, self._raw
84
85
def __getstate__(self): return self._pytz_timezone, self._raw
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/timezone.py#L84-L85
31
[ 0 ]
50
[ 1 ]
50
false
47.826087
2
1
50
0
def __getstate__(self): return self._pytz_timezone, self._raw
20,959
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/timezone.py
Timezone.__setstate__
(self, state)
87
88
def __setstate__(self, state): self._pytz_timezone, self._raw = state
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/timezone.py#L87-L88
31
[ 0 ]
50
[ 1 ]
50
false
47.826087
2
1
50
0
def __setstate__(self, state): self._pytz_timezone, self._raw = state
20,960
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/timezone.py
Timezone.__eq__
(self, other)
return ( isinstance(other, Timezone) and self._pytz_timezone == other._pytz_timezone and self.raw == other.raw )
90
95
def __eq__(self, other): return ( isinstance(other, Timezone) and self._pytz_timezone == other._pytz_timezone and self.raw == other.raw )
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/timezone.py#L90-L95
31
[ 0 ]
16.666667
[ 1 ]
16.666667
false
47.826087
6
3
83.333333
0
def __eq__(self, other): return ( isinstance(other, Timezone) and self._pytz_timezone == other._pytz_timezone and self.raw == other.raw )
20,961
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/timezone.py
Timezone.__ne__
(self, other)
return not (self == other)
97
98
def __ne__(self, other): return not (self == other)
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/timezone.py#L97-L98
31
[ 0 ]
50
[ 1 ]
50
false
47.826087
2
1
50
0
def __ne__(self, other): return not (self == other)
20,962
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/format.py
format_degrees
(degrees, fmt=DEGREES_FORMAT, symbols=None)
return fmt % format_dict
TODO docs.
TODO docs.
60
73
def format_degrees(degrees, fmt=DEGREES_FORMAT, symbols=None): """ TODO docs. """ symbols = symbols or ASCII_SYMBOLS arcminutes = units.arcminutes(degrees=degrees - int(degrees)) arcseconds = units.arcseconds(arcminutes=arcminutes - int(arcminutes)) format_dict = dict( symbols, degrees=degrees, minutes=abs(arcminutes), seconds=abs(arcseconds) ) return fmt % format_dict
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/format.py#L60-L73
31
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]
100
[]
0
true
100
14
2
100
1
def format_degrees(degrees, fmt=DEGREES_FORMAT, symbols=None): symbols = symbols or ASCII_SYMBOLS arcminutes = units.arcminutes(degrees=degrees - int(degrees)) arcseconds = units.arcseconds(arcminutes=arcminutes - int(arcminutes)) format_dict = dict( symbols, degrees=degrees, minutes=abs(arcminutes), seconds=abs(arcseconds) ) return fmt % format_dict
20,963
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/format.py
format_distance
(kilometers, fmt=DISTANCE_FORMAT, unit='km')
return fmt % {'magnitude': magnitude, 'unit': unit}
TODO docs.
TODO docs.
87
92
def format_distance(kilometers, fmt=DISTANCE_FORMAT, unit='km'): """ TODO docs. """ magnitude = DISTANCE_UNITS[unit](kilometers) return fmt % {'magnitude': magnitude, 'unit': unit}
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/format.py#L87-L92
31
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
100
6
1
100
1
def format_distance(kilometers, fmt=DISTANCE_FORMAT, unit='km'): magnitude = DISTANCE_UNITS[unit](kilometers) return fmt % {'magnitude': magnitude, 'unit': unit}
20,964
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/exc.py
GeocoderRateLimited.__init__
(self, message, *, retry_after=None)
58
60
def __init__(self, message, *, retry_after=None): super().__init__(message) self.retry_after = retry_after
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/exc.py#L58-L60
31
[ 0, 1, 2 ]
100
[]
0
true
100
3
1
100
0
def __init__(self, message, *, retry_after=None): super().__init__(message) self.retry_after = retry_after
20,965
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/util.py
pairwise
(seq)
Pair an iterable, e.g., (1, 2, 3, 4) -> ((1, 2), (2, 3), (3, 4))
Pair an iterable, e.g., (1, 2, 3, 4) -> ((1, 2), (2, 3), (3, 4))
12
17
def pairwise(seq): """ Pair an iterable, e.g., (1, 2, 3, 4) -> ((1, 2), (2, 3), (3, 4)) """ for i in range(0, len(seq) - 1): yield (seq[i], seq[i + 1])
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/util.py#L12-L17
31
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
92.307692
6
2
100
1
def pairwise(seq): for i in range(0, len(seq) - 1): yield (seq[i], seq[i + 1])
20,966
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/util.py
join_filter
(sep, seq, pred=bool)
return sep.join([str(i) for i in seq if pred(i)])
Join with a filter.
Join with a filter.
20
24
def join_filter(sep, seq, pred=bool): """ Join with a filter. """ return sep.join([str(i) for i in seq if pred(i)])
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/util.py#L20-L24
31
[ 0, 1, 2, 3 ]
80
[ 4 ]
20
false
92.307692
5
2
80
1
def join_filter(sep, seq, pred=bool): return sep.join([str(i) for i in seq if pred(i)])
20,967
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/util.py
get_version
()
return __version__
27
28
def get_version(): return __version__
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/util.py#L27-L28
31
[ 0, 1 ]
100
[]
0
true
92.307692
2
1
100
0
def get_version(): return __version__
20,968
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
get_retry_after
(headers)
return seconds
Return Retry-After header value in seconds. .. versionadded:: 2.2
Return Retry-After header value in seconds.
90
126
def get_retry_after(headers): """Return Retry-After header value in seconds. .. versionadded:: 2.2 """ # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After # https://github.com/urllib3/urllib3/blob/1.26.4/src/urllib3/util/retry.py#L376 try: retry_after = headers['retry-after'] except KeyError: return None if not retry_after: # None, '' return None retry_after = retry_after.strip() # RFC7231 section-7.1.3: # Retry-After = HTTP-date / delay-seconds try: # Retry-After: 120 seconds = int(retry_after) except ValueError: # Retry-After: Fri, 31 Dec 1999 23:59:59 GMT retry_date_tuple = email.utils.parsedate_tz(retry_after) if retry_date_tuple is None: logger.warning('Invalid Retry-After header: %s', retry_after) return None retry_date = email.utils.mktime_tz(retry_date_tuple) seconds = retry_date - time.time() if seconds < 0: seconds = 0 return seconds
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L90-L126
31
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36 ]
97.297297
[ 14 ]
2.702703
false
34.482759
37
6
97.297297
3
def get_retry_after(headers): # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After # https://github.com/urllib3/urllib3/blob/1.26.4/src/urllib3/util/retry.py#L376 try: retry_after = headers['retry-after'] except KeyError: return None if not retry_after: # None, '' return None retry_after = retry_after.strip() # RFC7231 section-7.1.3: # Retry-After = HTTP-date / delay-seconds try: # Retry-After: 120 seconds = int(retry_after) except ValueError: # Retry-After: Fri, 31 Dec 1999 23:59:59 GMT retry_date_tuple = email.utils.parsedate_tz(retry_after) if retry_date_tuple is None: logger.warning('Invalid Retry-After header: %s', retry_after) return None retry_date = email.utils.mktime_tz(retry_date_tuple) seconds = retry_date - time.time() if seconds < 0: seconds = 0 return seconds
20,969
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
_normalize_proxies
(proxies)
return normalized
Normalize user-supplied `proxies`: - For `None` -- retrieve System proxies using :func:`urllib.request.getproxies` - Add `http://` scheme to proxy urls if missing.
Normalize user-supplied `proxies`:
230
253
def _normalize_proxies(proxies): """Normalize user-supplied `proxies`: - For `None` -- retrieve System proxies using :func:`urllib.request.getproxies` - Add `http://` scheme to proxy urls if missing. """ if proxies is None: # Use system proxy settings proxies = getproxies() if not proxies: return {} # Disable proxies normalized = {} for scheme, url in proxies.items(): if url and "://" not in url: # Without the scheme there are errors: # from aiohttp: # ValueError: Only http proxies are supported # from requests (in some envs): # urllib3.exceptions.ProxySchemeUnknown: Not supported # proxy scheme localhost url = "http://%s" % url normalized[scheme] = url return normalized
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L230-L253
31
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
50
[ 12, 13, 14, 21, 22, 23 ]
25
false
34.482759
24
6
75
5
def _normalize_proxies(proxies): if proxies is None: # Use system proxy settings proxies = getproxies() if not proxies: return {} # Disable proxies normalized = {} for scheme, url in proxies.items(): if url and "://" not in url: # Without the scheme there are errors: # from aiohttp: # ValueError: Only http proxies are supported # from requests (in some envs): # urllib3.exceptions.ProxySchemeUnknown: Not supported # proxy scheme localhost url = "http://%s" % url normalized[scheme] = url return normalized
20,970
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
AdapterHTTPError.__init__
(self, message, *, status_code, headers, text)
:param str message: Standard exception message. :param int status_code: HTTP status code. :param dict headers: HTTP response readers. A mapping object with lowercased or case-insensitive keys. .. versionadded:: 2.2 :param str text: HTTP body text.
73
87
def __init__(self, message, *, status_code, headers, text): """ :param str message: Standard exception message. :param int status_code: HTTP status code. :param dict headers: HTTP response readers. A mapping object with lowercased or case-insensitive keys. .. versionadded:: 2.2 :param str text: HTTP body text. """ self.status_code = status_code self.headers = headers self.text = text super().__init__(message)
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L73-L87
31
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
73.333333
[ 11, 12, 13, 14 ]
26.666667
false
34.482759
15
1
73.333333
7
def __init__(self, message, *, status_code, headers, text): self.status_code = status_code self.headers = headers self.text = text super().__init__(message)
20,971
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
BaseAdapter.__init__
(self, *, proxies, ssl_context)
Initialize adapter. :param dict proxies: An urllib-style proxies dict, e.g. ``{"http": "192.0.2.0:8080", "https": "192.0.2.0:8080"}``, ``{"https": "http://user:passw0rd@192.0.2.0:8080""}``. See :attr:`geopy.geocoders.options.default_proxies` (note that Adapters always receive a dict: the string proxy is transformed to dict in the base :class:`geopy.geocoders.base.Geocoder` class.). :type ssl_context: :class:`ssl.SSLContext` :param ssl_context: See :attr:`geopy.geocoders.options.default_ssl_context`.
Initialize adapter.
149
164
def __init__(self, *, proxies, ssl_context): """Initialize adapter. :param dict proxies: An urllib-style proxies dict, e.g. ``{"http": "192.0.2.0:8080", "https": "192.0.2.0:8080"}``, ``{"https": "http://user:passw0rd@192.0.2.0:8080""}``. See :attr:`geopy.geocoders.options.default_proxies` (note that Adapters always receive a dict: the string proxy is transformed to dict in the base :class:`geopy.geocoders.base.Geocoder` class.). :type ssl_context: :class:`ssl.SSLContext` :param ssl_context: See :attr:`geopy.geocoders.options.default_ssl_context`. """
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L149-L164
31
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ]
100
[]
0
true
34.482759
16
1
100
13
def __init__(self, *, proxies, ssl_context):
20,972
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
BaseAdapter.get_json
(self, url, *, timeout, headers)
Same as ``get_text`` except that the response is expected to be a valid JSON. The value returned is the parsed JSON. :class:`geopy.exc.GeocoderParseError` must be raised if the response cannot be parsed. :param str url: The target URL. :param float timeout: See :attr:`geopy.geocoders.options.default_timeout`. :param dict headers: A dict with custom HTTP request headers.
Same as ``get_text`` except that the response is expected to be a valid JSON. The value returned is the parsed JSON.
167
180
def get_json(self, url, *, timeout, headers): """Same as ``get_text`` except that the response is expected to be a valid JSON. The value returned is the parsed JSON. :class:`geopy.exc.GeocoderParseError` must be raised if the response cannot be parsed. :param str url: The target URL. :param float timeout: See :attr:`geopy.geocoders.options.default_timeout`. :param dict headers: A dict with custom HTTP request headers. """
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L167-L180
31
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]
100
[]
0
true
34.482759
14
1
100
12
def get_json(self, url, *, timeout, headers):
20,973
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
BaseAdapter.get_text
(self, url, *, timeout, headers)
Make a GET request and return the response as string. This method should not raise any exceptions other than these: - :class:`geopy.adapters.AdapterHTTPError` should be raised if the response was successfully retrieved but the status code was non-successful. - :class:`geopy.exc.GeocoderTimedOut` should be raised when the request times out. - :class:`geopy.exc.GeocoderUnavailable` should be raised when the target host is unreachable. - :class:`geopy.exc.GeocoderServiceError` is the least specific error in the exceptions hierarchy and should be raised in any other cases. :param str url: The target URL. :param float timeout: See :attr:`geopy.geocoders.options.default_timeout`. :param dict headers: A dict with custom HTTP request headers.
Make a GET request and return the response as string.
183
203
def get_text(self, url, *, timeout, headers): """Make a GET request and return the response as string. This method should not raise any exceptions other than these: - :class:`geopy.adapters.AdapterHTTPError` should be raised if the response was successfully retrieved but the status code was non-successful. - :class:`geopy.exc.GeocoderTimedOut` should be raised when the request times out. - :class:`geopy.exc.GeocoderUnavailable` should be raised when the target host is unreachable. - :class:`geopy.exc.GeocoderServiceError` is the least specific error in the exceptions hierarchy and should be raised in any other cases. :param str url: The target URL. :param float timeout: See :attr:`geopy.geocoders.options.default_timeout`. :param dict headers: A dict with custom HTTP request headers. """
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L183-L203
31
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ]
100
[]
0
true
34.482759
21
1
100
19
def get_text(self, url, *, timeout, headers):
20,974
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
BaseSyncAdapter.__enter__
(self)
return self
210
211
def __enter__(self): return self
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L210-L211
31
[ 0 ]
50
[ 1 ]
50
false
34.482759
2
1
50
0
def __enter__(self): return self
20,975
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
BaseAsyncAdapter.__aenter__
(self)
return self
223
224
async def __aenter__(self): return self
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L223-L224
31
[ 0 ]
50
[ 1 ]
50
false
34.482759
2
1
50
0
async def __aenter__(self): return self
20,976
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
URLLibAdapter.__init__
(self, *, proxies, ssl_context)
268
283
def __init__(self, *, proxies, ssl_context): proxies = _normalize_proxies(proxies) super().__init__(proxies=proxies, ssl_context=ssl_context) # `ProxyHandler` should be present even when actually there're # no proxies. `build_opener` contains it anyway. By specifying # it here explicitly we can disable system proxies (i.e. # from HTTP_PROXY env var) by setting `proxies` to `{}`. # Otherwise, if we didn't specify ProxyHandler for empty # `proxies` here, the `build_opener` would have used one internally # which could have unwillingly picked up the system proxies. opener = build_opener( HTTPSHandler(context=ssl_context), ProxyHandler(proxies), ) self.urlopen = opener.open
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L268-L283
31
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15 ]
81.25
[]
0
false
34.482759
16
1
100
0
def __init__(self, *, proxies, ssl_context): proxies = _normalize_proxies(proxies) super().__init__(proxies=proxies, ssl_context=ssl_context) # `ProxyHandler` should be present even when actually there're # no proxies. `build_opener` contains it anyway. By specifying # it here explicitly we can disable system proxies (i.e. # from HTTP_PROXY env var) by setting `proxies` to `{}`. # Otherwise, if we didn't specify ProxyHandler for empty # `proxies` here, the `build_opener` would have used one internally # which could have unwillingly picked up the system proxies. opener = build_opener( HTTPSHandler(context=ssl_context), ProxyHandler(proxies), ) self.urlopen = opener.open
20,977
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
URLLibAdapter.get_json
(self, url, *, timeout, headers)
285
292
def get_json(self, url, *, timeout, headers): text = self.get_text(url, timeout=timeout, headers=headers) try: return json.loads(text) except ValueError: raise GeocoderParseError( "Could not deserialize using deserializer:\n%s" % text )
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L285-L292
31
[ 0 ]
12.5
[ 1, 2, 3, 4, 5 ]
62.5
false
34.482759
8
2
37.5
0
def get_json(self, url, *, timeout, headers): text = self.get_text(url, timeout=timeout, headers=headers) try: return json.loads(text) except ValueError: raise GeocoderParseError( "Could not deserialize using deserializer:\n%s" % text )
20,978
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
URLLibAdapter.get_text
(self, url, *, timeout, headers)
return text
294
339
def get_text(self, url, *, timeout, headers): req = Request(url=url, headers=headers) try: page = self.urlopen(req, timeout=timeout) except Exception as error: message = str(error.args[0]) if len(error.args) else str(error) if isinstance(error, HTTPError): code = error.getcode() response_headers = { name.lower(): value for name, value in error.headers.items() } body = self._read_http_error_body(error) raise AdapterHTTPError( message, status_code=code, headers=response_headers, text=body, ) elif isinstance(error, URLError): if "timed out" in message: raise GeocoderTimedOut("Service timed out") elif "unreachable" in message: raise GeocoderUnavailable("Service not available") elif isinstance(error, SocketTimeout): raise GeocoderTimedOut("Service timed out") elif isinstance(error, SSLError): if "timed out" in message: raise GeocoderTimedOut("Service timed out") raise GeocoderServiceError(message) else: text = self._decode_page(page) status_code = page.getcode() if status_code >= 400: response_headers = { name.lower(): value for name, value in page.headers.items() } raise AdapterHTTPError( "Non-successful status code %s" % status_code, status_code=status_code, headers=response_headers, text=text, ) return text
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L294-L339
31
[ 0 ]
2.173913
[ 1, 2, 3, 4, 5, 6, 7, 8, 12, 13, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 32, 33, 34, 38, 45 ]
58.695652
false
34.482759
46
10
41.304348
0
def get_text(self, url, *, timeout, headers): req = Request(url=url, headers=headers) try: page = self.urlopen(req, timeout=timeout) except Exception as error: message = str(error.args[0]) if len(error.args) else str(error) if isinstance(error, HTTPError): code = error.getcode() response_headers = { name.lower(): value for name, value in error.headers.items() } body = self._read_http_error_body(error) raise AdapterHTTPError( message, status_code=code, headers=response_headers, text=body, ) elif isinstance(error, URLError): if "timed out" in message: raise GeocoderTimedOut("Service timed out") elif "unreachable" in message: raise GeocoderUnavailable("Service not available") elif isinstance(error, SocketTimeout): raise GeocoderTimedOut("Service timed out") elif isinstance(error, SSLError): if "timed out" in message: raise GeocoderTimedOut("Service timed out") raise GeocoderServiceError(message) else: text = self._decode_page(page) status_code = page.getcode() if status_code >= 400: response_headers = { name.lower(): value for name, value in page.headers.items() } raise AdapterHTTPError( "Non-successful status code %s" % status_code, status_code=status_code, headers=response_headers, text=text, ) return text
20,979
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
URLLibAdapter._read_http_error_body
(self, error)
341
348
def _read_http_error_body(self, error): try: return self._decode_page(error) except Exception: logger.debug( "Unable to fetch body for a non-successful HTTP response", exc_info=True ) return None
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L341-L348
31
[ 0 ]
12.5
[ 1, 2, 3, 4, 7 ]
62.5
false
34.482759
8
2
37.5
0
def _read_http_error_body(self, error): try: return self._decode_page(error) except Exception: logger.debug( "Unable to fetch body for a non-successful HTTP response", exc_info=True ) return None
20,980
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
URLLibAdapter._decode_page
(self, page)
350
360
def _decode_page(self, page): encoding = page.headers.get_content_charset() or "utf-8" try: body_bytes = page.read() except Exception: raise GeocoderServiceError("Unable to read the response") try: return str(body_bytes, encoding=encoding) except ValueError: raise GeocoderParseError("Unable to decode the response bytes")
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L350-L360
31
[ 0 ]
9.090909
[ 1, 2, 3, 4, 5, 7, 8, 9, 10 ]
81.818182
false
34.482759
11
4
18.181818
0
def _decode_page(self, page): encoding = page.headers.get_content_charset() or "utf-8" try: body_bytes = page.read() except Exception: raise GeocoderServiceError("Unable to read the response") try: return str(body_bytes, encoding=encoding) except ValueError: raise GeocoderParseError("Unable to decode the response bytes")
20,981
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
RequestsAdapter.__init__
( self, *, proxies, ssl_context, pool_connections=10, pool_maxsize=10, max_retries=2, pool_block=False )
376
418
def __init__( self, *, proxies, ssl_context, pool_connections=10, pool_maxsize=10, max_retries=2, pool_block=False ): if not requests_available: raise ImportError( "`requests` must be installed in order to use RequestsAdapter. " "If you have installed geopy via pip, you may use " "this command to install requests: " '`pip install "geopy[requests]"`.' ) proxies = _normalize_proxies(proxies) super().__init__(proxies=proxies, ssl_context=ssl_context) self.session = requests.Session() self.session.trust_env = False # don't use system proxies self.session.proxies = proxies self.session.mount( "http://", RequestsHTTPAdapter( pool_connections=pool_connections, pool_maxsize=pool_maxsize, max_retries=max_retries, pool_block=pool_block, ), ) self.session.mount( "https://", RequestsHTTPWithSSLContextAdapter( ssl_context=ssl_context, pool_connections=pool_connections, pool_maxsize=pool_maxsize, max_retries=max_retries, pool_block=pool_block, ), )
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L376-L418
31
[ 0 ]
2.325581
[ 10, 11, 17, 18, 20, 21, 22, 24, 33 ]
20.930233
false
34.482759
43
2
79.069767
0
def __init__( self, *, proxies, ssl_context, pool_connections=10, pool_maxsize=10, max_retries=2, pool_block=False ): if not requests_available: raise ImportError( "`requests` must be installed in order to use RequestsAdapter. " "If you have installed geopy via pip, you may use " "this command to install requests: " '`pip install "geopy[requests]"`.' ) proxies = _normalize_proxies(proxies) super().__init__(proxies=proxies, ssl_context=ssl_context) self.session = requests.Session() self.session.trust_env = False # don't use system proxies self.session.proxies = proxies self.session.mount( "http://", RequestsHTTPAdapter( pool_connections=pool_connections, pool_maxsize=pool_maxsize, max_retries=max_retries, pool_block=pool_block, ), ) self.session.mount( "https://", RequestsHTTPWithSSLContextAdapter( ssl_context=ssl_context, pool_connections=pool_connections, pool_maxsize=pool_maxsize, max_retries=max_retries, pool_block=pool_block, ), )
20,982
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
RequestsAdapter.__enter__
(self)
return self
420
421
def __enter__(self): return self
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L420-L421
31
[ 0 ]
50
[ 1 ]
50
false
34.482759
2
1
50
0
def __enter__(self): return self
20,983
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
RequestsAdapter.__exit__
(self, exc_type, exc_val, exc_tb)
423
424
def __exit__(self, exc_type, exc_val, exc_tb): self.session.close()
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L423-L424
31
[ 0 ]
50
[ 1 ]
50
false
34.482759
2
1
50
0
def __exit__(self, exc_type, exc_val, exc_tb): self.session.close()
20,984
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
RequestsAdapter.__del__
(self)
426
440
def __del__(self): # Cleanup keepalive connections when Geocoder (and, thus, Adapter) # instances are getting garbage-collected. session = getattr(self, "session", None) if session is not None: try: session.close() except TypeError: # It's possible for the close method to try to fetch a # non-existent old_pool in urllib3 with a misleading state # ultimately due to stdlib queue/threading behaviour. # Since the error arises from a non-existent pool # (TypeError: 'NoneType' object is not callable) # it's safe to ignore this error pass
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L426-L440
31
[ 0, 1, 2 ]
20
[ 3, 4, 5, 6, 7, 14 ]
40
false
34.482759
15
3
60
0
def __del__(self): # Cleanup keepalive connections when Geocoder (and, thus, Adapter) # instances are getting garbage-collected. session = getattr(self, "session", None) if session is not None: try: session.close() except TypeError: # It's possible for the close method to try to fetch a # non-existent old_pool in urllib3 with a misleading state # ultimately due to stdlib queue/threading behaviour. # Since the error arises from a non-existent pool # (TypeError: 'NoneType' object is not callable) # it's safe to ignore this error pass
20,985
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
RequestsAdapter.get_text
(self, url, *, timeout, headers)
return resp.text
442
444
def get_text(self, url, *, timeout, headers): resp = self._request(url, timeout=timeout, headers=headers) return resp.text
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L442-L444
31
[ 0 ]
33.333333
[ 1, 2 ]
66.666667
false
34.482759
3
1
33.333333
0
def get_text(self, url, *, timeout, headers): resp = self._request(url, timeout=timeout, headers=headers) return resp.text
20,986
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
RequestsAdapter.get_json
(self, url, *, timeout, headers)
446
453
def get_json(self, url, *, timeout, headers): resp = self._request(url, timeout=timeout, headers=headers) try: return resp.json() except ValueError: raise GeocoderParseError( "Could not deserialize using deserializer:\n%s" % resp.text )
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L446-L453
31
[ 0 ]
12.5
[ 1, 2, 3, 4, 5 ]
62.5
false
34.482759
8
2
37.5
0
def get_json(self, url, *, timeout, headers): resp = self._request(url, timeout=timeout, headers=headers) try: return resp.json() except ValueError: raise GeocoderParseError( "Could not deserialize using deserializer:\n%s" % resp.text )
20,987
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
RequestsAdapter._request
(self, url, *, timeout, headers)
return resp
455
482
def _request(self, url, *, timeout, headers): try: resp = self.session.get(url, timeout=timeout, headers=headers) except Exception as error: message = str(error) if isinstance(error, SocketTimeout): raise GeocoderTimedOut("Service timed out") elif isinstance(error, SSLError): if "timed out" in message: raise GeocoderTimedOut("Service timed out") elif isinstance(error, requests.ConnectionError): if "unauthorized" in message.lower(): raise GeocoderServiceError(message) else: raise GeocoderUnavailable(message) elif isinstance(error, requests.Timeout): raise GeocoderTimedOut("Service timed out") raise GeocoderServiceError(message) else: if resp.status_code >= 400: raise AdapterHTTPError( "Non-successful status code %s" % resp.status_code, status_code=resp.status_code, headers=resp.headers, text=resp.text, ) return resp
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L455-L482
31
[ 0 ]
3.571429
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 19, 20, 27 ]
67.857143
false
34.482759
28
9
32.142857
0
def _request(self, url, *, timeout, headers): try: resp = self.session.get(url, timeout=timeout, headers=headers) except Exception as error: message = str(error) if isinstance(error, SocketTimeout): raise GeocoderTimedOut("Service timed out") elif isinstance(error, SSLError): if "timed out" in message: raise GeocoderTimedOut("Service timed out") elif isinstance(error, requests.ConnectionError): if "unauthorized" in message.lower(): raise GeocoderServiceError(message) else: raise GeocoderUnavailable(message) elif isinstance(error, requests.Timeout): raise GeocoderTimedOut("Service timed out") raise GeocoderServiceError(message) else: if resp.status_code >= 400: raise AdapterHTTPError( "Non-successful status code %s" % resp.status_code, status_code=resp.status_code, headers=resp.headers, text=resp.text, ) return resp
20,988
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
AioHTTPAdapter.__init__
(self, *, proxies, ssl_context)
498
510
def __init__(self, *, proxies, ssl_context): if not aiohttp_available: raise ImportError( "`aiohttp` must be installed in order to use AioHTTPAdapter. " "If you have installed geopy via pip, you may use " "this command to install aiohttp: " '`pip install "geopy[aiohttp]"`.' ) proxies = _normalize_proxies(proxies) super().__init__(proxies=proxies, ssl_context=ssl_context) self.proxies = proxies self.ssl_context = ssl_context
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L498-L510
31
[ 0 ]
7.692308
[ 1, 2, 8, 9, 11, 12 ]
46.153846
false
34.482759
13
2
53.846154
0
def __init__(self, *, proxies, ssl_context): if not aiohttp_available: raise ImportError( "`aiohttp` must be installed in order to use AioHTTPAdapter. " "If you have installed geopy via pip, you may use " "this command to install aiohttp: " '`pip install "geopy[aiohttp]"`.' ) proxies = _normalize_proxies(proxies) super().__init__(proxies=proxies, ssl_context=ssl_context) self.proxies = proxies self.ssl_context = ssl_context
20,989
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
AioHTTPAdapter.session
(self)
return session
513
524
def session(self): # Lazy session creation, which allows to avoid "unclosed socket" # warnings if a Geocoder instance is created without entering # async context and making any requests. session = self.__dict__.get("session") if session is None: session = aiohttp.ClientSession( trust_env=False, # don't use system proxies raise_for_status=False ) self.__dict__["session"] = session return session
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L513-L524
31
[ 0, 1, 2, 3 ]
33.333333
[ 4, 5, 6, 10, 11 ]
41.666667
false
34.482759
12
2
58.333333
0
def session(self): # Lazy session creation, which allows to avoid "unclosed socket" # warnings if a Geocoder instance is created without entering # async context and making any requests. session = self.__dict__.get("session") if session is None: session = aiohttp.ClientSession( trust_env=False, # don't use system proxies raise_for_status=False ) self.__dict__["session"] = session return session
20,990
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
AioHTTPAdapter.__aenter__
(self)
return self
526
527
async def __aenter__(self): return self
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L526-L527
31
[ 0 ]
50
[ 1 ]
50
false
34.482759
2
1
50
0
async def __aenter__(self): return self
20,991
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
AioHTTPAdapter.__aexit__
(self, exc_type, exc_val, exc_tb)
529
534
async def __aexit__(self, exc_type, exc_val, exc_tb): # Might issue a warning if loop is immediately closed: # ResourceWarning: unclosed transport <_SelectorSocketTransport fd=10> # https://github.com/aio-libs/aiohttp/issues/1115#issuecomment-242278593 # https://github.com/python/asyncio/issues/466 await self.session.close()
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L529-L534
31
[ 0, 1, 2, 3, 4 ]
83.333333
[ 5 ]
16.666667
false
34.482759
6
1
83.333333
0
async def __aexit__(self, exc_type, exc_val, exc_tb): # Might issue a warning if loop is immediately closed: # ResourceWarning: unclosed transport <_SelectorSocketTransport fd=10> # https://github.com/aio-libs/aiohttp/issues/1115#issuecomment-242278593 # https://github.com/python/asyncio/issues/466 await self.session.close()
20,992
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
AioHTTPAdapter.get_text
(self, url, *, timeout, headers)
536
540
async def get_text(self, url, *, timeout, headers): with self._normalize_exceptions(): async with self._request(url, timeout=timeout, headers=headers) as resp: await self._raise_for_status(resp) return await resp.text()
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L536-L540
31
[ 0 ]
20
[ 1, 2, 3, 4 ]
80
false
34.482759
5
3
20
0
async def get_text(self, url, *, timeout, headers): with self._normalize_exceptions(): async with self._request(url, timeout=timeout, headers=headers) as resp: await self._raise_for_status(resp) return await resp.text()
20,993
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
AioHTTPAdapter.get_json
(self, url, *, timeout, headers)
542
557
async def get_json(self, url, *, timeout, headers): with self._normalize_exceptions(): async with self._request(url, timeout=timeout, headers=headers) as resp: await self._raise_for_status(resp) try: try: return await resp.json() except aiohttp.client_exceptions.ContentTypeError: # `Attempt to decode JSON with unexpected mimetype: # text/plain;charset=utf-8` return json.loads(await resp.text()) except ValueError: raise GeocoderParseError( "Could not deserialize using deserializer:\n%s" % (await resp.text()) )
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L542-L557
31
[ 0 ]
6.25
[ 1, 2, 3, 4, 5, 6, 7, 10, 11, 12 ]
62.5
false
34.482759
16
5
37.5
0
async def get_json(self, url, *, timeout, headers): with self._normalize_exceptions(): async with self._request(url, timeout=timeout, headers=headers) as resp: await self._raise_for_status(resp) try: try: return await resp.json() except aiohttp.client_exceptions.ContentTypeError: # `Attempt to decode JSON with unexpected mimetype: # text/plain;charset=utf-8` return json.loads(await resp.text()) except ValueError: raise GeocoderParseError( "Could not deserialize using deserializer:\n%s" % (await resp.text()) )
20,994
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
AioHTTPAdapter._raise_for_status
(self, resp)
559
566
async def _raise_for_status(self, resp): if resp.status >= 400: raise AdapterHTTPError( "Non-successful status code %s" % resp.status, status_code=resp.status, headers=resp.headers, text=await resp.text(), )
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L559-L566
31
[ 0 ]
12.5
[ 1, 2 ]
25
false
34.482759
8
2
75
0
async def _raise_for_status(self, resp): if resp.status >= 400: raise AdapterHTTPError( "Non-successful status code %s" % resp.status, status_code=resp.status, headers=resp.headers, text=await resp.text(), )
20,995
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
AioHTTPAdapter._request
(self, url, *, timeout, headers)
return self.session.get( url, timeout=timeout, headers=headers, proxy=proxy, ssl=self.ssl_context )
568
582
def _request(self, url, *, timeout, headers): if self.proxies: scheme = urlparse(url).scheme proxy = self.proxies.get(scheme.lower()) else: proxy = None # aiohttp accepts url as string or as yarl.URL. # A string url might be re-encoded by yarl, which might cause # a hashsum of params to change. Some geocoders use that # to authenticate their requests (such as Baidu SK). url = yarl.URL(url, encoded=True) # `encoded` param disables url re-encoding return self.session.get( url, timeout=timeout, headers=headers, proxy=proxy, ssl=self.ssl_context )
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L568-L582
31
[ 0 ]
6.666667
[ 1, 2, 3, 5, 11, 12 ]
40
false
34.482759
15
2
60
0
def _request(self, url, *, timeout, headers): if self.proxies: scheme = urlparse(url).scheme proxy = self.proxies.get(scheme.lower()) else: proxy = None # aiohttp accepts url as string or as yarl.URL. # A string url might be re-encoded by yarl, which might cause # a hashsum of params to change. Some geocoders use that # to authenticate their requests (such as Baidu SK). url = yarl.URL(url, encoded=True) # `encoded` param disables url re-encoding return self.session.get( url, timeout=timeout, headers=headers, proxy=proxy, ssl=self.ssl_context )
20,996
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
AioHTTPAdapter._normalize_exceptions
(self)
585
599
def _normalize_exceptions(self): try: yield except (GeopyError, AdapterHTTPError, AssertionError): raise except Exception as error: message = str(error) if isinstance(error, asyncio.TimeoutError): raise GeocoderTimedOut("Service timed out") elif isinstance(error, SSLError): if "timed out" in message: raise GeocoderTimedOut("Service timed out") elif isinstance(error, aiohttp.ClientConnectionError): raise GeocoderUnavailable(message) raise GeocoderServiceError(message)
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L585-L599
31
[ 0 ]
6.666667
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ]
93.333333
false
34.482759
15
7
6.666667
0
def _normalize_exceptions(self): try: yield except (GeopyError, AdapterHTTPError, AssertionError): raise except Exception as error: message = str(error) if isinstance(error, asyncio.TimeoutError): raise GeocoderTimedOut("Service timed out") elif isinstance(error, SSLError): if "timed out" in message: raise GeocoderTimedOut("Service timed out") elif isinstance(error, aiohttp.ClientConnectionError): raise GeocoderUnavailable(message) raise GeocoderServiceError(message)
20,997
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
RequestsHTTPWithSSLContextAdapter.__init__
(self, *, ssl_context=None, **kwargs)
604
607
def __init__(self, *, ssl_context=None, **kwargs): self.__ssl_context = ssl_context self.__urllib3_warned = False super().__init__(**kwargs)
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L604-L607
31
[ 0 ]
25
[ 1, 2, 3 ]
75
false
34.482759
4
1
25
0
def __init__(self, *, ssl_context=None, **kwargs): self.__ssl_context = ssl_context self.__urllib3_warned = False super().__init__(**kwargs)
20,998
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
RequestsHTTPWithSSLContextAdapter.init_poolmanager
(self, *args, **kwargs)
return super().init_poolmanager(*args, **kwargs)
609
615
def init_poolmanager(self, *args, **kwargs): if self.__ssl_context is not None: # This ssl context would get passed through the urllib3's # `PoolManager` up to the `HTTPSConnection` class. kwargs["ssl_context"] = self.__ssl_context self.__warn_if_old_urllib3() return super().init_poolmanager(*args, **kwargs)
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L609-L615
31
[ 0 ]
14.285714
[ 1, 4, 5, 6 ]
57.142857
false
34.482759
7
2
42.857143
0
def init_poolmanager(self, *args, **kwargs): if self.__ssl_context is not None: # This ssl context would get passed through the urllib3's # `PoolManager` up to the `HTTPSConnection` class. kwargs["ssl_context"] = self.__ssl_context self.__warn_if_old_urllib3() return super().init_poolmanager(*args, **kwargs)
20,999
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
RequestsHTTPWithSSLContextAdapter.proxy_manager_for
(self, proxy, **proxy_kwargs)
return super().proxy_manager_for(proxy, **proxy_kwargs)
617
621
def proxy_manager_for(self, proxy, **proxy_kwargs): if self.__ssl_context is not None: proxy_kwargs["ssl_context"] = self.__ssl_context self.__warn_if_old_urllib3() return super().proxy_manager_for(proxy, **proxy_kwargs)
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L617-L621
31
[ 0 ]
20
[ 1, 2, 3, 4 ]
80
false
34.482759
5
2
20
0
def proxy_manager_for(self, proxy, **proxy_kwargs): if self.__ssl_context is not None: proxy_kwargs["ssl_context"] = self.__ssl_context self.__warn_if_old_urllib3() return super().proxy_manager_for(proxy, **proxy_kwargs)
21,000
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
RequestsHTTPWithSSLContextAdapter.__warn_if_old_urllib3
(self)
623
649
def __warn_if_old_urllib3(self): if self.__urllib3_warned: return self.__urllib3_warned = True try: import requests.packages.urllib3 as urllib3 except ImportError: import urllib3 def silent_int(s): try: return int(s) except ValueError: return 0 version = tuple(silent_int(v) for v in urllib3.__version__.split(".")) if version < (1, 24, 2): warnings.warn( "urllib3 prior to 1.24.2 is known to have a bug with " "custom ssl contexts: it attempts to load system certificates " "to them. Please consider upgrading `requests` and `urllib3` " "packages. See https://github.com/urllib3/urllib3/pull/1566", UserWarning, )
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L623-L649
31
[ 0 ]
3.703704
[ 1, 2, 4, 6, 7, 8, 9, 11, 12, 13, 14, 15, 17, 19, 20 ]
55.555556
false
34.482759
27
6
44.444444
0
def __warn_if_old_urllib3(self): if self.__urllib3_warned: return self.__urllib3_warned = True try: import requests.packages.urllib3 as urllib3 except ImportError: import urllib3 def silent_int(s): try: return int(s) except ValueError: return 0 version = tuple(silent_int(v) for v in urllib3.__version__.split(".")) if version < (1, 24, 2): warnings.warn( "urllib3 prior to 1.24.2 is known to have a bug with " "custom ssl contexts: it attempts to load system certificates " "to them. Please consider upgrading `requests` and `urllib3` " "packages. See https://github.com/urllib3/urllib3/pull/1566", UserWarning, )
21,001
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/adapters.py
RequestsHTTPWithSSLContextAdapter.cert_verify
(self, conn, url, verify, cert)
651
658
def cert_verify(self, conn, url, verify, cert): super().cert_verify(conn, url, verify, cert) if self.__ssl_context is not None: # Stop requests from adding any certificates to the ssl context. conn.ca_certs = None conn.ca_cert_dir = None conn.cert_file = None conn.key_file = None
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/adapters.py#L651-L658
31
[ 0 ]
12.5
[ 1, 2, 4, 5, 6, 7 ]
75
false
34.482759
8
2
25
0
def cert_verify(self, conn, url, verify, cert): super().cert_verify(conn, url, verify, cert) if self.__ssl_context is not None: # Stop requests from adding any certificates to the ssl context. conn.ca_certs = None conn.ca_cert_dir = None conn.cert_file = None conn.key_file = None
21,002
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/location.py
_location_tuple
(location)
return location._address, (location._point[0], location._point[1])
6
7
def _location_tuple(location): return location._address, (location._point[0], location._point[1])
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/location.py#L6-L7
31
[ 0, 1 ]
100
[]
0
true
96.551724
2
1
100
0
def _location_tuple(location): return location._address, (location._point[0], location._point[1])
21,003
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/location.py
Location.__init__
(self, address, point, raw)
21
40
def __init__(self, address, point, raw): if address is None: raise TypeError("`address` must not be None") self._address = address if isinstance(point, Point): self._point = point elif isinstance(point, str): self._point = Point(point) elif isinstance(point, collections.abc.Sequence): self._point = Point(point) else: raise TypeError( "`point` is of unsupported type: %r" % type(point) ) self._tuple = _location_tuple(self) if raw is None: raise TypeError("`raw` must not be None") self._raw = raw
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/location.py#L21-L40
31
[ 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 12, 15, 16, 17, 19 ]
75
[ 2, 18 ]
10
false
96.551724
20
6
90
0
def __init__(self, address, point, raw): if address is None: raise TypeError("`address` must not be None") self._address = address if isinstance(point, Point): self._point = point elif isinstance(point, str): self._point = Point(point) elif isinstance(point, collections.abc.Sequence): self._point = Point(point) else: raise TypeError( "`point` is of unsupported type: %r" % type(point) ) self._tuple = _location_tuple(self) if raw is None: raise TypeError("`raw` must not be None") self._raw = raw
21,004
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/location.py
Location.address
(self)
return self._address
Location as a formatted string returned by the geocoder or constructed by geopy, depending on the service. :rtype: str
Location as a formatted string returned by the geocoder or constructed by geopy, depending on the service.
43
50
def address(self): """ Location as a formatted string returned by the geocoder or constructed by geopy, depending on the service. :rtype: str """ return self._address
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/location.py#L43-L50
31
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
96.551724
8
1
100
4
def address(self): return self._address
21,005
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/location.py
Location.latitude
(self)
return self._point[0]
Location's latitude. :rtype: float
Location's latitude.
53
59
def latitude(self): """ Location's latitude. :rtype: float """ return self._point[0]
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/location.py#L53-L59
31
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
96.551724
7
1
100
3
def latitude(self): return self._point[0]
21,006
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/location.py
Location.longitude
(self)
return self._point[1]
Location's longitude. :rtype: float
Location's longitude.
62
68
def longitude(self): """ Location's longitude. :rtype: float """ return self._point[1]
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/location.py#L62-L68
31
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
96.551724
7
1
100
3
def longitude(self): return self._point[1]
21,007
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/location.py
Location.altitude
(self)
return self._point[2]
Location's altitude. .. note:: Geocoding services usually don't consider altitude neither in requests nor in responses, so almost always the value of this property would be zero. :rtype: float
Location's altitude.
71
82
def altitude(self): """ Location's altitude. .. note:: Geocoding services usually don't consider altitude neither in requests nor in responses, so almost always the value of this property would be zero. :rtype: float """ return self._point[2]
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/location.py#L71-L82
31
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
100
[]
0
true
96.551724
12
1
100
8
def altitude(self): return self._point[2]
21,008
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/location.py
Location.point
(self)
return self._point
:class:`geopy.point.Point` instance representing the location's latitude, longitude, and altitude. :rtype: :class:`geopy.point.Point`
:class:`geopy.point.Point` instance representing the location's latitude, longitude, and altitude.
85
92
def point(self): """ :class:`geopy.point.Point` instance representing the location's latitude, longitude, and altitude. :rtype: :class:`geopy.point.Point` """ return self._point
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/location.py#L85-L92
31
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
96.551724
8
1
100
4
def point(self): return self._point
21,009
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/location.py
Location.raw
(self)
return self._raw
Location's raw, unparsed geocoder response. For details on this, consult the service's documentation. :rtype: dict
Location's raw, unparsed geocoder response. For details on this, consult the service's documentation.
95
102
def raw(self): """ Location's raw, unparsed geocoder response. For details on this, consult the service's documentation. :rtype: dict """ return self._raw
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/location.py#L95-L102
31
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
96.551724
8
1
100
4
def raw(self): return self._raw
21,010
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/location.py
Location.__getitem__
(self, index)
return self._tuple[index]
Backwards compatibility with geopy<0.98 tuples.
Backwards compatibility with geopy<0.98 tuples.
104
108
def __getitem__(self, index): """ Backwards compatibility with geopy<0.98 tuples. """ return self._tuple[index]
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/location.py#L104-L108
31
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
96.551724
5
1
100
1
def __getitem__(self, index): return self._tuple[index]
21,011
geopy/geopy
ef48a8cbb85f842c0820333e53e7ebde7db382a3
geopy/location.py
Location.__str__
(self)
return self._address
110
111
def __str__(self): return self._address
https://github.com/geopy/geopy/blob/ef48a8cbb85f842c0820333e53e7ebde7db382a3/project31/geopy/location.py#L110-L111
31
[ 0, 1 ]
100
[]
0
true
96.551724
2
1
100
0
def __str__(self): return self._address
21,012