3 ÅýP\¬ã@sNddlZddlZddlZd dd„ZGdd„deƒZdd„Zdd „Zd d „ZdS) éNcCs(|dkr g}t||ƒj|ƒjƒjƒjƒS)a¿Return an internet-friendly user_agent string. The majority of this code has been wilfully stolen from the equivalent function in Requests. :param name: The intended name of the user-agent, e.g. "python-requests". :param version: The version of the user-agent, e.g. "0.0.1". :param extras: List of two-item tuples that are added to the user-agent string. :returns: Formatted user-agent string :rtype: str N)ÚUserAgentBuilderÚinclude_extrasÚinclude_implementationÚinclude_systemÚbuild)ÚnameÚversionÚextras©r ú /usr/lib/python3.6/user_agent.pyÚ user_agents r c@s<eZdZdZdZdd„Zdd„Zdd„Zd d „Zd d „Z d S)raïClass to provide a greater level of control than :func:`user_agent`. This is used by :func:`user_agent` to build its User-Agent string. .. code-block:: python user_agent_str = UserAgentBuilder( name='requests-toolbelt', version='17.4.0', ).include_implementation( ).include_system( ).include_extras([ ('requests', '2.14.2'), ('urllib3', '1.21.2'), ]).build() z%s/%scCstj||fgƒ|_dS)zÕInitialize our builder with the name and version of our user agent. :param str name: Name of our user-agent. :param str version: The version string for user-agent. N)Ú collectionsÚdequeÚ_pieces)Úselfrrr r r Ú__init__4szUserAgentBuilder.__init__csdj‡fdd„ˆjDƒƒS)z„Finalize the User-Agent string. :returns: Formatted User-Agent string. :rtype: str ú csg|]}ˆj|‘qSr )Ú format_string)Ú.0Zpiece)rr r ú Fsz*UserAgentBuilder.build..)Újoinr)rr )rr r>szUserAgentBuilder.buildcCs*tdd„|Dƒƒrtdƒ‚|jj|ƒ|S)zŠInclude extra portions of the User-Agent. :param list extras: list of tuples of extra-name and extra-version css|]}t|ƒdkVqdS)éN)Úlen)rZextrar r r ú Nsz2UserAgentBuilder.include_extras..z/Extras should be a sequence of two item tuples.)ÚanyÚ ValueErrorrÚextend)rr r r r rHs zUserAgentBuilder.include_extrascCs|jjtƒƒ|S)z¦Append the implementation string to the user-agent string. This adds the the information that you're using CPython 2.7.13 to the User-Agent. )rÚappendÚ_implementation_tuple)rr r r rTsz'UserAgentBuilder.include_implementationcCs|jjtƒƒ|S)z2Append the information about the Operating System.)rrÚ_platform_tuple)rr r r r]szUserAgentBuilder.include_systemN) Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrrrr r r r rs    rcCsŒtjƒ}|dkrtjƒ}nj|dkr\dtjjtjjtjjf}tjjdkr„dj |tjjgƒ}n(|dkrntjƒ}n|dkr€tjƒ}nd}||fS) aÎReturn the tuple of interpreter name and version. Returns a string that provides both the name and the version of the Python implementation currently running. For example, on CPython 2.7.5 it will return "CPython/2.7.5". This function works best on CPython and PyPy: in particular, it probably doesn't work for Jython or IronPython. Future investigation should be done to work out the correct shape of the code for those platforms. ZCPythonZPyPyz%s.%s.%sÚfinalÚZJythonZ IronPythonÚUnknown) ÚplatformZpython_implementationZpython_versionÚsysZpypy_version_infoÚmajorÚminorÚmicroÚ releaselevelr)ÚimplementationZimplementation_versionr r r rcs      rcCs dtƒS)Nz%s/%s)rr r r r Ú_implementation_string„sr.c Cs:ytjƒ}tjƒ}Wntk r0d}d}YnX||fS)Nr&)r'ÚsystemÚreleaseÚIOError)Zp_systemZ p_releaser r r rˆs  r)N) r r'r(r Úobjectrrr.rr r r r Ús D!