diff --git a/ipinfo/details.py b/ipinfo/details.py index fc36bf6..3712d71 100644 --- a/ipinfo/details.py +++ b/ipinfo/details.py @@ -14,7 +14,7 @@ def __getattr__(self, attr): if attr in self.details: return self.details[attr] else: - raise AttributeError('{attr} is not a valid attribute of Details'.format(attr)) + raise AttributeError('{} is not a valid attribute of Details'.format(attr)) @property def all(self): diff --git a/ipinfo/handler.py b/ipinfo/handler.py index edc7a0e..0473f58 100644 --- a/ipinfo/handler.py +++ b/ipinfo/handler.py @@ -46,13 +46,7 @@ def getDetails(self, ip_address=None): raw_details = self._requestDetails(ip_address) raw_details['country_name'] = self.countries.get(raw_details.get('country')) raw_details['ip_address'] = ipaddress.ip_address(raw_details.get('ip')) - - lat, lon = None, None - coords = tuple(raw_details.get('loc', '').split(',')) - if coords: - lat, lon = coords[0], coords[1] - raw_details['latitude'], raw_details['longitude'] = lat, lon - + raw_details['latitude'], raw_details['longitude'] = self._read_coords(raw_details.get('loc')) return Details(raw_details) def _requestDetails(self, ip_address=None): @@ -75,13 +69,20 @@ def _get_headers(self): headers = { 'user-agent': 'IPinfoClient/Python{version}/1.0'.format(version=sys.version_info[0]), 'accept': 'application/json' - } + } if self.access_token: headers['authorization'] = 'Bearer {}'.format(self.access_token) return headers + def _read_coords(self, location): + lat, lon = None, None + coords = tuple(location.split(',')) if location else '' + if len(coords) == 2 and coords[0] and coords[1]: + lat, lon = coords[0], coords[1] + return lat, lon + def _read_country_names(self, countries_file=None): """Read list of countries from specified country file or default file.""" if not countries_file: diff --git a/setup.py b/setup.py index a434229..83be578 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ """ setup(name='ipinfo', - version='1.1.0', + version='1.1.1', description='Official Python library for IPInfo', long_description=long_description, url='https://github.com/ipinfo/python',