Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc3570c5

Browse files
authored
Merge pull request#13 from ipinfo/uman/fix-deps
Fix missing `six` dependency
2 parents62fef91 +d2b611f commitc3570c5

File tree

9 files changed

+72
-55
lines changed

9 files changed

+72
-55
lines changed

‎ipinfo/cache/default.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
importcachetools
6+
67
from .interfaceimportCacheInterface
78

89

‎ipinfo/details.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Details returned by the IPinfo service.
33
"""
44

5+
56
classDetails:
67
"""Encapsulates data for single IP address."""
78

@@ -14,7 +15,7 @@ def __getattr__(self, attr):
1415
ifattrinself.details:
1516
returnself.details[attr]
1617
else:
17-
raiseAttributeError('{} is not a valid attribute of Details'.format(attr))
18+
raiseAttributeError("{} is not a valid attribute of Details".format(attr))
1819

1920
@property
2021
defall(self):

‎ipinfo/exceptions.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Exceptions thrown by the IPinfo service.
33
"""
44

5+
56
classRequestQuotaExceededError(Exception):
67
"""Error indicating that users monthly request quota has been passed."""
8+
79
pass

‎ipinfo/handler.py‎

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
importipaddress
66
importjson
77
importos
8-
importrequests
98
importsys
9+
10+
importrequests
11+
1012
from .cache.defaultimportDefaultCache
1113
from .detailsimportDetails
1214
from .exceptionsimportRequestQuotaExceededError
@@ -18,45 +20,49 @@ class Handler:
1820
and maintains access to cache.
1921
"""
2022

21-
API_URL='https://ipinfo.io'
23+
API_URL="https://ipinfo.io"
2224
CACHE_MAXSIZE=4096
2325
CACHE_TTL=60*60*24
24-
COUNTRY_FILE_DEFAULT='countries.json'
26+
COUNTRY_FILE_DEFAULT="countries.json"
2527
REQUEST_TIMEOUT_DEFAULT=2
2628

2729
def__init__(self,access_token=None,**kwargs):
2830
"""Initialize the Handler object with country name list and the cache initialized."""
2931
self.access_token=access_token
30-
self.countries=self._read_country_names(kwargs.get('countries_file'))
32+
self.countries=self._read_country_names(kwargs.get("countries_file"))
3133

32-
self.request_options=kwargs.get('request_options', {})
33-
if'timeout'notinself.request_options:
34-
self.request_options['timeout']=self.REQUEST_TIMEOUT_DEFAULT
34+
self.request_options=kwargs.get("request_options", {})
35+
if"timeout"notinself.request_options:
36+
self.request_options["timeout"]=self.REQUEST_TIMEOUT_DEFAULT
3537

36-
if'cache'inkwargs:
37-
self.cache=kwargs['cache']
38+
if"cache"inkwargs:
39+
self.cache=kwargs["cache"]
3840
else:
39-
cache_options=kwargs.get('cache_options', {})
40-
maxsize=cache_options.get('maxsize',self.CACHE_MAXSIZE)
41-
ttl=cache_options.get('ttl',self.CACHE_TTL)
41+
cache_options=kwargs.get("cache_options", {})
42+
maxsize=cache_options.get("maxsize",self.CACHE_MAXSIZE)
43+
ttl=cache_options.get("ttl",self.CACHE_TTL)
4244
self.cache=DefaultCache(maxsize,ttl,**cache_options)
4345

4446
defgetDetails(self,ip_address=None):
4547
"""Get details for specified IP address as a Details object."""
4648
raw_details=self._requestDetails(ip_address)
47-
raw_details['country_name']=self.countries.get(raw_details.get('country'))
48-
raw_details['ip_address']=ipaddress.ip_address(raw_details.get('ip'))
49-
raw_details['latitude'],raw_details['longitude']=self._read_coords(raw_details.get('loc'))
49+
raw_details["country_name"]=self.countries.get(raw_details.get("country"))
50+
raw_details["ip_address"]=ipaddress.ip_address(raw_details.get("ip"))
51+
raw_details["latitude"],raw_details["longitude"]=self._read_coords(
52+
raw_details.get("loc")
53+
)
5054
returnDetails(raw_details)
5155

5256
def_requestDetails(self,ip_address=None):
5357
"""Get IP address data by sending request to IPinfo API."""
5458
ifip_addressnotinself.cache:
5559
url=self.API_URL
5660
ifip_address:
57-
url+='/'+ip_address
61+
url+="/"+ip_address
5862

59-
response=requests.get(url,headers=self._get_headers(),**self.request_options)
63+
response=requests.get(
64+
url,headers=self._get_headers(),**self.request_options
65+
)
6066
ifresponse.status_code==429:
6167
raiseRequestQuotaExceededError()
6268
response.raise_for_status()
@@ -67,26 +73,30 @@ def _requestDetails(self, ip_address=None):
6773
def_get_headers(self):
6874
"""Built headers for request to IPinfo API."""
6975
headers= {
70-
'user-agent':'IPinfoClient/Python{version}/1.0'.format(version=sys.version_info[0]),
71-
'accept':'application/json'
76+
"user-agent":"IPinfoClient/Python{version}/1.0".format(
77+
version=sys.version_info[0]
78+
),
79+
"accept":"application/json",
7280
}
7381

7482
ifself.access_token:
75-
headers['authorization']='Bearer {}'.format(self.access_token)
83+
headers["authorization"]="Bearer {}".format(self.access_token)
7684

7785
returnheaders
7886

7987
def_read_coords(self,location):
8088
lat,lon=None,None
81-
coords=tuple(location.split(','))iflocationelse''
89+
coords=tuple(location.split(","))iflocationelse""
8290
iflen(coords)==2andcoords[0]andcoords[1]:
8391
lat,lon=coords[0],coords[1]
8492
returnlat,lon
8593

8694
def_read_country_names(self,countries_file=None):
8795
"""Read list of countries from specified country file or default file."""
8896
ifnotcountries_file:
89-
countries_file=os.path.join(os.path.dirname(__file__),self.COUNTRY_FILE_DEFAULT)
97+
countries_file=os.path.join(
98+
os.path.dirname(__file__),self.COUNTRY_FILE_DEFAULT
99+
)
90100
withopen(countries_file)asf:
91101
countries_json=f.read()
92102

‎requirements.in‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
cachetools==2.1.0
2-
pip-tools==3.1.0
3-
pycodestyle==2.4.0
4-
pytest==3.8.2
5-
python-dateutil==2.6.1
6-
pytz==2017.2
1+
# For app
72
requests>=2.18.4
3+
cachetools==3.1.1
4+
pytest==4.5.0
5+
6+
# For dev
7+
pip-tools==3.7.0
8+
black==19.3b0

‎requirements.txt‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@
22
# This file is autogenerated by pip-compile
33
# To update, run:
44
#
5-
# pip-compile --no-index --output-filerequirements.txt requirements.in
5+
# pip-compile --no-index --output-file=requirements.txt requirements.in
66
#
7+
appdirs==1.4.3# via black
78
atomicwrites==1.3.0# via pytest
8-
attrs==19.1.0# via pytest
9-
cachetools==2.1.0
9+
attrs==19.1.0# via black, pytest
10+
black==19.3b0
11+
cachetools==3.1.1
1012
certifi==2019.3.9# via requests
1113
chardet==3.0.4# via requests
12-
click==7.0# via pip-tools
14+
click==7.0# viablack,pip-tools
1315
idna==2.8# via requests
1416
more-itertools==6.0.0# via pytest
15-
pip-tools==3.1.0
17+
pip-tools==3.7.0
1618
pluggy==0.9.0# via pytest
1719
py==1.8.0# via pytest
18-
pycodestyle==2.4.0
19-
pytest==3.8.2
20-
python-dateutil==2.6.1
21-
pytz==2017.2
20+
pytest==4.5.0
2221
requests==2.21.0
23-
six==1.12.0# via pip-tools, pytest, python-dateutil
22+
six==1.12.0# via pip-tools, pytest
23+
toml==0.10.0# via black
2424
urllib3==1.24.1# via requests
25+
wcwidth==0.1.7# via pytest

‎setup.py‎

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@
88
You can visit our developer docs at https://ipinfo.io/developers.
99
"""
1010

11-
setup(name='ipinfo',
12-
version='1.1.1',
13-
description='Official Python library for IPInfo',
14-
long_description=long_description,
15-
url='https://github.com/ipinfo/python',
16-
author='James Timmins',
17-
author_email='jameshtimmins@gmail.com',
18-
license='Apache License 2.0',
19-
packages=['ipinfo','ipinfo.cache'],
20-
install_requires=[
21-
'requests',
22-
'cachetools',
23-
],
24-
include_package_data=True,
25-
zip_safe=False)
11+
setup(
12+
name="ipinfo",
13+
version="1.1.2",
14+
description="Official Python library for IPInfo",
15+
long_description=long_description,
16+
url="https://github.com/ipinfo/python",
17+
author="James Timmins",
18+
author_email="jameshtimmins@gmail.com",
19+
license="Apache License 2.0",
20+
packages=["ipinfo","ipinfo.cache"],
21+
install_requires=["requests","cachetools","six"],
22+
include_package_data=True,
23+
zip_safe=False,
24+
)

‎tests/details_test.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
importpytest
2+
23
fromipinfo.detailsimportDetails
34

45

‎tests/handler_test.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
importipaddress
2+
13
fromipinfo.cache.defaultimportDefaultCache
24
fromipinfo.detailsimportDetails
35
fromipinfo.handlerimportHandler
4-
importipaddress
56

67

78
deftest_init():

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp