Skip to content

Commit 984be21

Browse files
committed
Add examples/docker-info-alt2.py
Example of using customizable `urlparse` function
1 parent cef606f commit 984be21

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

examples/docker-info-alt2.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python
2+
3+
import json
4+
from requests.compat import urlparse
5+
6+
from requests_unixsocket import Session, UnixAdapter
7+
8+
9+
def custom_urlparse(url):
10+
parsed_url = urlparse(url)
11+
return UnixAdapter.Settings.ParseResult(
12+
sockpath=parsed_url.path,
13+
reqpath=parsed_url.fragment,
14+
)
15+
16+
17+
session = Session(settings=UnixAdapter.Settings(urlparse=custom_urlparse))
18+
19+
r = session.get('http+unix://sock.localhost/var/run/docker.sock#/info')
20+
registry_config = r.json()['RegistryConfig']
21+
print(json.dumps(registry_config, indent=4))

0 commit comments

Comments
 (0)