|
12 | 12 | from ..config import * |
13 | 13 | from ..exceptions import * |
14 | 14 | from ..__init__ import __version__ |
15 | | - |
16 | | - |
17 | | -def user_agent_extended(be_geo_id, caller): |
18 | | - # Generate extended portion of the User-Agent |
19 | | - user_agent_extended = be_geo_id |
20 | | - user_agent_extended = {} |
21 | | - |
22 | | - # Mimic pip system data collection per https://github.com/pypa/pip/blob/master/src/pip/_internal/network/session.py |
23 | | - user_agent_extended['implementation'] = { |
24 | | - "name": platform.python_implementation(), |
25 | | - } |
26 | | - |
27 | | - if user_agent_extended["implementation"]["name"] in ('CPython','Jython','IronPython'): |
28 | | - user_agent_extended["implementation"]["version"] = platform.python_version() |
29 | | - elif user_agent_extended["implementation"]["name"] == 'PyPy': |
30 | | - if sys.pypy_version_info.releaselevel == 'final': |
31 | | - pypy_version_info = sys.pypy_version_info[:3] |
32 | | - else: |
33 | | - pypy_version_info = sys.pypy_version_info |
34 | | - user_agent_extended["implementation"]["version"] = ".".join( |
35 | | - [str(x) for x in pypy_version_info] |
36 | | - ) |
37 | | - |
38 | | - if sys.platform.startswith("darwin") and platform.mac_ver()[0]: |
39 | | - user_agent_extended["distro"] = {"name": "macOS", "version": platform.mac_ver()[0]} |
40 | | - |
41 | | - if platform.system(): |
42 | | - user_agent_extended.setdefault("system", {})["name"] = platform.system() |
43 | | - |
44 | | - if platform.release(): |
45 | | - user_agent_extended.setdefault("system", {})["release"] = platform.release() |
46 | | - |
47 | | - if platform.machine(): |
48 | | - user_agent_extended["cpu"] = platform.machine() |
49 | | - |
50 | | - if be_geo_id: |
51 | | - user_agent_extended["be_geo_id"] = be_geo_id |
52 | | - |
53 | | - if caller: |
54 | | - user_agent_extended["caller"] = caller |
55 | | - |
56 | | - return urllib.parse.quote(json.dumps(user_agent_extended)) |
57 | | - |
| 15 | +from ..rest_session import user_agent_extended |
58 | 16 |
|
59 | 17 | # Main module interface |
60 | 18 | class AsyncRestSession: |
|
0 commit comments