Skip to content

Commit 604c1f3

Browse files
committed
Some changes needed for Python 2.{6,7}. Works in Python 2.7, but there may still be some issues in 2.6.
1 parent 74472b7 commit 604c1f3

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

geoip2/errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ class GeoIP2Error(RuntimeError):
55
class GeoIP2HTTPError(GeoIP2Error):
66
"""There was an error when making your HTTP request."""
77
def __init__(self, message, http_status=None, uri=None):
8-
super().__init__(message)
8+
super(GeoIP2HTTPError, self).__init__(message)
99
self.http_status = http_status
1010
self.uri = uri
1111

1212

1313
class GeoIP2WebServiceError(GeoIP2HTTPError):
1414
"""The GeoIP2 web service returned an error."""
1515
def __init__(self, message, code=None, http_status=None, uri=None):
16-
super().__init__(message, http_status, uri)
16+
super(GeoIP2WebServiceError, self).__init__(message, http_status, uri)
1717
self.code = code

geoip2/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self, raw_response, languages=None):
2121

2222
class City(Country):
2323
def __init__(self, raw_response, languages=None):
24-
super().__init__(raw_response, languages)
24+
super(City, self).__init__(raw_response, languages)
2525
self.city = \
2626
geoip2.records.City(languages, **raw_response.get('city', {}))
2727
self.location = \

geoip2/records.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ class Record(object):
55
__metaclass__ = ABCMeta
66

77
def __init__(self, **args):
8-
self.__dict__.update({k: args.get(k) for k in self._valid_attributes})
8+
valid_args = dict((k, args.get(k)) for k in self._valid_attributes)
9+
self.__dict__.update(valid_args)
910

1011
def __setattr__(self, name, value):
1112
raise NotImplementedError(name + ' is read-only.')
@@ -20,7 +21,7 @@ def __init__(self, languages=None, **args):
2021
languages = []
2122
object.__setattr__(self, 'languages', languages)
2223
args['names'] = args.pop('name', [])
23-
super().__init__(**args)
24+
super(PlaceRecord, self).__init__(**args)
2425

2526
@property
2627
def name(self):
@@ -29,42 +30,43 @@ def name(self):
2930

3031

3132
class City(PlaceRecord):
32-
_valid_attributes = {'confidence', 'geoname_id', 'names'}
33+
_valid_attributes = set(['confidence', 'geoname_id', 'names'])
3334

3435

3536
class Continent(PlaceRecord):
36-
_valid_attributes = {'continent_code', 'geoname_id', 'names'}
37+
_valid_attributes = set(['continent_code', 'geoname_id', 'names'])
3738

3839

3940
class Country(PlaceRecord):
40-
_valid_attributes = {'confidence', 'geoname_id', 'iso_3166_1_alpha_2',
41-
'iso_3166_1_alpha_3', 'names'}
41+
_valid_attributes = set(['confidence', 'geoname_id', 'iso_3166_1_alpha_2',
42+
'iso_3166_1_alpha_3', 'names'])
4243

4344

4445
class Location(Record):
45-
_valid_attributes = {'accuracy_radius', 'latitude', 'longitude'
46-
'metro_code', 'postal_code', 'postal_confidence',
47-
'time_zone'}
46+
_valid_attributes = set(['accuracy_radius', 'latitude', 'longitude'
47+
'metro_code', 'postal_code', 'postal_confidence',
48+
'time_zone'])
4849

4950

5051
class Region(PlaceRecord):
51-
_valid_attributes = {'confidence', 'geoname_id', 'iso_3166_2', 'names'}
52+
_valid_attributes = set(['confidence', 'geoname_id', 'iso_3166_2',
53+
'names'])
5254

5355

5456
class Traits(Record):
55-
_valid_attributes = {'autonomous_system_number',
56-
'autonomous_system_organization',
57-
'domain',
58-
'is_anonymous_proxy',
59-
'is_satellite_provider',
60-
'is_transparent_proxy',
61-
'isp',
62-
'ip_address',
63-
'organization',
64-
'user_type'}
57+
_valid_attributes = set(['autonomous_system_number',
58+
'autonomous_system_organization',
59+
'domain',
60+
'is_anonymous_proxy',
61+
'is_satellite_provider',
62+
'is_transparent_proxy',
63+
'isp',
64+
'ip_address',
65+
'organization',
66+
'user_type'])
6567

6668
def __init__(self, languages=None, **args):
6769
for k in ['is_anonymous_proxy', 'is_satellite_provider',
6870
'is_transparent_proxy']:
6971
args[k] = bool(args.get(k, False))
70-
super().__init__(**args)
72+
super(Traits, self).__init__(**args)

0 commit comments

Comments
 (0)