def user_agent():
 data = {'installer': {'name': 'pip', 'version': pip.__version__}, 'python': platform.python_version(), 'implementation': {'name': platform.python_implementation()}}
 if (data['implementation']['name'] == 'CPython'):
  data['implementation']['version'] = platform.python_version()
 elif (data['implementation']['name'] == 'PyPy'):
  if (sys.pypy_version_info.releaselevel == 'final'):
   pypy_version_info = sys.pypy_version_info[:3]
  else:
   pypy_version_info = sys.pypy_version_info
  data['implementation']['version'] = '.'.join([str(x) for x in pypy_version_info])
 elif (data['implementation']['name'] == 'Jython'):
  data['implementation']['version'] = platform.python_version()
 elif (data['implementation']['name'] == 'IronPython'):
  data['implementation']['version'] = platform.python_version()
 if sys.platform.startswith('linux'):
  from pip._vendor import distro
  distro_infos = dict(filter((lambda x: x[1]), zip(['name', 'version', 'id'], distro.linux_distribution())))
  libc = dict(filter((lambda x: x[1]), zip(['lib', 'version'], libc_ver())))
  if libc:
   distro_infos['libc'] = libc
  if distro_infos:
   data['distro'] = distro_infos
 if (sys.platform.startswith('darwin') and platform.mac_ver()[0]):
  data['distro'] = {'name': 'macOS', 'version': platform.mac_ver()[0]}
 if platform.system():
  data.setdefault('system', {})['name'] = platform.system()
 if platform.release():
  data.setdefault('system', {})['release'] = platform.release()
 if platform.machine():
  data['cpu'] = platform.machine()
 if (HAS_TLS and (sys.version_info[:2] > (2, 6))):
  data['openssl_version'] = ssl.OPENSSL_VERSION
 return '{data[installer][name]}/{data[installer][version]} {json}'.format(data=data, json=json.dumps(data, separators=(',', ':'), sort_keys=True))

def user_agent ( ) : data = { 'installer' : { 'name' : 'pip' , 'version' : pip . __version__ } , 'python' : platform . python_version ( ) , 'implementation' : { 'name' : platform . python_implementation ( ) } } if ( data [ 'implementation' ] [ 'name' ] == 'CPython' ) : data [ 'implementation' ] [ 'version' ] = platform . python_version ( ) elif ( data [ 'implementation' ] [ 'name' ] == 'PyPy' ) : if ( sys . pypy_version_info . releaselevel == 'final' ) : pypy_version_info = sys . pypy_version_info [ : 3 ] else : pypy_version_info = sys . pypy_version_info data [ 'implementation' ] [ 'version' ] = '.' . join ( [ str ( x ) for x in pypy_version_info ] ) elif ( data [ 'implementation' ] [ 'name' ] == 'Jython' ) : data [ 'implementation' ] [ 'version' ] = platform . python_version ( ) elif ( data [ 'implementation' ] [ 'name' ] == 'IronPython' ) : data [ 'implementation' ] [ 'version' ] = platform . python_version ( ) if sys . platform . startswith ( 'linux' ) : from pip . _vendor import distro distro_infos = dict ( filter ( ( lambda x : x [ 1 ] ) , zip ( [ 'name' , 'version' , 'id' ] , distro . linux_distribution ( ) ) ) ) libc = dict ( filter ( ( lambda x : x [ 1 ] ) , zip ( [ 'lib' , 'version' ] , libc_ver ( ) ) ) ) if libc : distro_infos [ 'libc' ] = libc if distro_infos : data [ 'distro' ] = distro_infos if ( sys . platform . startswith ( 'darwin' ) and platform . mac_ver ( ) [ 0 ] ) : data [ 'distro' ] = { 'name' : 'macOS' , 'version' : platform . mac_ver ( ) [ 0 ] } if platform . system ( ) : data . setdefault ( 'system' , { } ) [ 'name' ] = platform . system ( ) if platform . release ( ) : data . setdefault ( 'system' , { } ) [ 'release' ] = platform . release ( ) if platform . machine ( ) : data [ 'cpu' ] = platform . machine ( ) if ( HAS_TLS and ( sys . version_info [ : 2 ] > ( 2 , 6 ) ) ) : data [ 'openssl_version' ] = ssl . OPENSSL_VERSION return '{data[installer][name]}/{data[installer][version]} {json}' . format ( data = data , json = json . dumps ( data , separators = ( ',' , ':' ) , sort_keys = True ) )
builds a simple user-agent string to send in requests .