Skip to content

Commit 612495f

Browse files
committed
allow properly deleting from the cache via del keyword.
1 parent 95fc85f commit 612495f

File tree

6 files changed

+96
-35
lines changed

6 files changed

+96
-35
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# IPInfo Changelog
22

3+
## 4.2.1
4+
5+
- Allow deleting from the cache via the `del` keyword, e.g.
6+
`del handler.cache[ip_key]`.
7+
38
## 4.2.0
49

510
- Cache keys are now versioned.

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,25 +189,29 @@ handler = ipinfo.getHandler(cache=MyCustomCache())
189189

190190
#### Accessing the cache directly
191191

192-
You can access/update the cache directly via a dictionary-like notation with a cache_key and the handler.
192+
You can access/update the cache directly via dictionary-like notation.
193193

194194
```python
195195
>>> import ipinfo
196196
>>> from ipinfo.handler_utils import cache_key
197+
>>>
197198
>>> access_token = '123456789abc'
198199
>>> handler = ipinfo.getHandler(access_token)
199200
>>> ip_cache_key = cache_key('1.1.1.1')
200201

201-
# Check if the ip address is in the cache
202+
# Check if IP is in the cache.
202203
>>> ip_cache_key in handler.cache
203204
True
204205

205-
# Get the ip address's details from cache
206+
# Get the IP's details from cache.
206207
>>> handler.cache[ip_cache_key]
207208
{'ip': '1.1.1.1', 'hostname': 'one.one.one.one', 'anycast': True, 'city': 'Miami', 'region': 'Florida', 'country': 'US', 'loc': '25.7867,-80.1800', 'org': 'AS13335 Cloudflare, Inc.', 'postal': '33132', 'timezone': 'America/New_York', 'country_name': 'United States', 'latitude': '25.7867', 'longitude': '-80.1800'}
208209

209-
# Remove the ip address from the cache
210+
# Set the IP's details to something else in the cache.
210211
>>> handler.cache[ip_cache_key] = None
212+
213+
# Delete the IP from the cache.
214+
>>> del handler.cache[ip_cache_key]
211215
```
212216

213217
### Modifying request options

ipinfo/cache/default.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ def __setitem__(self, key, value):
2121

2222
def __getitem__(self, key):
2323
return self.cache.__getitem__(key)
24+
25+
def __delitem__(self, key):
26+
return self.cache.__delitem__(key)

ipinfo/cache/interface.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ def __setitem__(self, key, value):
1919
@abc.abstractmethod
2020
def __getitem__(self, key):
2121
pass
22+
23+
@abc.abstractmethod
24+
def __delitem__(self, key):
25+
pass

ipinfo/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
SDK_VERSION = "4.2.0"
1+
SDK_VERSION = "4.2.1"

requirements.txt

Lines changed: 75 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,83 @@
11
#
2-
# This file is autogenerated by pip-compile
2+
# This file is autogenerated by pip-compile with python 3.9
33
# To update, run:
44
#
55
# pip-compile --no-emit-index-url --no-emit-trusted-host
66
#
7-
aiohttp==3.7.4.post0 # via -r requirements.in
8-
appdirs==1.4.4 # via black
9-
async-timeout==3.0.1 # via aiohttp
10-
attrs==20.3.0 # via aiohttp, pytest
11-
black==20.8b1 # via -r requirements.in
12-
cachetools==4.2.0 # via -r requirements.in
13-
certifi==2020.12.5 # via requests
14-
chardet==4.0.0 # via aiohttp, requests
15-
click==7.1.2 # via black, pip-tools
16-
idna==2.10 # via requests, yarl
17-
iniconfig==1.1.1 # via pytest
18-
multidict==5.1.0 # via aiohttp, yarl
19-
mypy-extensions==0.4.3 # via black
20-
packaging==20.9 # via pytest
21-
pathspec==0.8.1 # via black
22-
pip-tools==5.4.0 # via -r requirements.in
23-
pluggy==0.13.1 # via pytest
24-
py==1.10.0 # via pytest
25-
pyparsing==2.4.7 # via packaging
26-
pytest-asyncio==0.14.0 # via -r requirements.in
27-
pytest==6.2.1 # via -r requirements.in, pytest-asyncio
28-
regex==2021.4.4 # via black
29-
requests==2.25.1 # via -r requirements.in
30-
six==1.15.0 # via pip-tools
31-
toml==0.10.2 # via black, pytest
32-
typed-ast==1.4.3 # via black
33-
typing-extensions==3.7.4.3 # via aiohttp, black
34-
urllib3==1.26.4 # via requests
35-
yarl==1.6.3 # via aiohttp
7+
aiohttp==3.7.4.post0
8+
# via -r requirements.in
9+
appdirs==1.4.4
10+
# via black
11+
async-timeout==3.0.1
12+
# via aiohttp
13+
attrs==21.2.0
14+
# via
15+
# aiohttp
16+
# pytest
17+
black==20.8b1
18+
# via -r requirements.in
19+
cachetools==4.2.0
20+
# via -r requirements.in
21+
certifi==2021.5.30
22+
# via requests
23+
chardet==4.0.0
24+
# via
25+
# aiohttp
26+
# requests
27+
click==8.0.1
28+
# via
29+
# black
30+
# pip-tools
31+
idna==2.10
32+
# via
33+
# requests
34+
# yarl
35+
iniconfig==1.1.1
36+
# via pytest
37+
multidict==5.1.0
38+
# via
39+
# aiohttp
40+
# yarl
41+
mypy-extensions==0.4.3
42+
# via black
43+
packaging==21.0
44+
# via pytest
45+
pathspec==0.8.1
46+
# via black
47+
pip-tools==5.4.0
48+
# via -r requirements.in
49+
pluggy==0.13.1
50+
# via pytest
51+
py==1.10.0
52+
# via pytest
53+
pyparsing==2.4.7
54+
# via packaging
55+
pytest==6.2.1
56+
# via
57+
# -r requirements.in
58+
# pytest-asyncio
59+
pytest-asyncio==0.14.0
60+
# via -r requirements.in
61+
regex==2021.7.6
62+
# via black
63+
requests==2.25.1
64+
# via -r requirements.in
65+
six==1.16.0
66+
# via pip-tools
67+
toml==0.10.2
68+
# via
69+
# black
70+
# pytest
71+
typed-ast==1.4.3
72+
# via black
73+
typing-extensions==3.10.0.0
74+
# via
75+
# aiohttp
76+
# black
77+
urllib3==1.26.6
78+
# via requests
79+
yarl==1.6.3
80+
# via aiohttp
3681

3782
# The following packages are considered to be unsafe in a requirements file:
3883
# pip

0 commit comments

Comments
 (0)