GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Geolocator   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 26
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
B geocode() 0 22 6
A __init__() 0 2 1
1
# -*- coding: utf-8 -*-
2
import geopy.exc as exc
3
import geopy.geocoders as geocoders
4
5
6
class BaseError(Exception):
7
    pass
8
9
10
class GeolocationFailure(BaseError):
11
    pass
12
13
14
class GeolocationError(BaseError):
15
    pass
16
17
18
class TemporaryError(BaseError):
19
    pass
20
21
22
class Geolocator(object):
23
    def __init__(self):
24
        self._geocoder = geocoders.Nominatim(timeout=5, country_bias='fr')
25
26
    def geocode(self, address):
27
        if not isinstance(address, basestring) \
28
                and not isinstance(address, dict):
29
            err_msg = u"address should either be of type: %s, or of type %s." \
30
                      % (basestring, dict)
31
            raise TypeError(err_msg)
32
33
        try:
34
            geolocation = self._geocoder.geocode(address)
35
36
            if not geolocation:
37
                err_msg = u"Couldn't resolve the following address: '%s'" \
38
                          % address
39
                raise GeolocationFailure(err_msg)
40
        except (exc.GeocoderQuotaExceeded,
41
                exc.GeocoderUnavailable,
42
                exc.GeocoderTimedOut) as e:
43
            raise TemporaryError(u'Geolocator error: %s' % e)
44
        except exc.GeocoderServiceError as e:
45
            raise GeolocationError(u'Geolocator error: %s' % e)
46
47
        return geolocation
48