Debian Codegraph @

third_party/python/requests_unixsocket/requests_unixsocket-0.2.0.dist-info/METADATA

raw
1 Metadata-Version: 2.1
2 Name: requests-unixsocket
3 Version: 0.2.0
4 Summary: Use requests to talk HTTP via a UNIX domain socket
5 Home-page: https://github.com/msabramo/requests-unixsocket
6 Author: Marc Abramowitz
7 Author-email: [email protected]
8 License: Apache-2
9 Platform: UNKNOWN
10 Classifier: Development Status :: 3 - Alpha
11 Classifier: Intended Audience :: Developers
12 Classifier: Intended Audience :: Information Technology
13 Classifier: License :: OSI Approved :: Apache Software License
14 Classifier: Operating System :: OS Independent
15 Classifier: Programming Language :: Python
16 Classifier: Programming Language :: Python :: 2
17 Classifier: Programming Language :: Python :: 2.7
18 Classifier: Programming Language :: Python :: 3
19 Classifier: Programming Language :: Python :: 3.3
20 Classifier: Programming Language :: Python :: 3.4
21 Classifier: Programming Language :: Python :: 3.5
22 Classifier: Programming Language :: Python :: 3.6
23 Requires-Dist: requests (>=1.1)
24 Requires-Dist: urllib3 (>=1.8)
25
26 requests-unixsocket
27 ===================
28
29 .. image:: https://badge.fury.io/py/requests-unixsocket.svg
30 :target: https://badge.fury.io/py/requests-unixsocket
31 :alt: Latest Version on PyPI
32
33 .. image:: https://travis-ci.org/msabramo/requests-unixsocket.svg?branch=master
34 :target: https://travis-ci.org/msabramo/requests-unixsocket
35
36 Use `requests <http://docs.python-requests.org/>`_ to talk HTTP via a UNIX domain socket
37
38 Usage
39 -----
40
41 Explicit
42 ++++++++
43
44 You can use it by instantiating a special ``Session`` object:
45
46 .. code-block:: python
47
48 import json
49
50 import requests_unixsocket
51
52 session = requests_unixsocket.Session()
53
54 r = session.get('http+unix://%2Fvar%2Frun%2Fdocker.sock/info')
55 registry_config = r.json()['RegistryConfig']
56 print(json.dumps(registry_config, indent=4))
57
58
59 Implicit (monkeypatching)
60 +++++++++++++++++++++++++
61
62 Monkeypatching allows you to use the functionality in this module, while making
63 minimal changes to your code. Note that in the above example we had to
64 instantiate a special ``requests_unixsocket.Session`` object and call the
65 ``get`` method on that object. Calling ``requests.get(url)`` (the easiest way
66 to use requests and probably very common), would not work. But we can make it
67 work by doing monkeypatching.
68
69 You can monkeypatch globally:
70
71 .. code-block:: python
72
73 import requests_unixsocket
74
75 requests_unixsocket.monkeypatch()
76
77 r = requests.get('http+unix://%2Fvar%2Frun%2Fdocker.sock/info')
78 assert r.status_code == 200
79
80 or you can do it temporarily using a context manager:
81
82 .. code-block:: python
83
84 import requests_unixsocket
85
86 with requests_unixsocket.monkeypatch():
87 r = requests.get('http+unix://%2Fvar%2Frun%2Fdocker.sock/info')
88 assert r.status_code == 200
89
90
91 Abstract namespace sockets
92 ++++++++++++++++++++++++++
93
94 To connect to an `abstract namespace
95 socket <https://utcc.utoronto.ca/~cks/space/blog/python/AbstractUnixSocketsAndPeercred>`_
96 (Linux only), prefix the name with a NULL byte (i.e.: `\0`) - e.g.:
97
98 .. code-block:: python
99
100 import requests_unixsocket
101
102 session = requests_unixsocket.Session()
103 res = session.get('http+unix://\0test_socket/get')
104 print(res.text)
105
106 For an example program that illustrates this, see
107 ``examples/abstract_namespace.py`` in the git repo. Since abstract namespace
108 sockets are specific to Linux, the program will only work on Linux.
109
110
111 See also
112 --------
113
114 - https://github.com/httpie/httpie-unixsocket - a plugin for `HTTPie <https://httpie.org/>`_ that allows you to interact with UNIX domain sockets
115
116
117