o
    "`^hG                     @   s   d Z ddlZddlZddlmZ ddlmZmZ ddlmZm	Z	 ddl
mZ ddlmZ ee d Zd	Zd
diZdZdd ZG dd deZG dd dZzddlmZ W n eyb   dd ZY nw G dd dZdd ZdS )a  
NOTE: All classes and functions in this module are considered private and are
subject to abrupt breaking changes. Please do not use them directly.

To modify the User-Agent header sent by botocore, use one of these
configuration options:
* The ``AWS_SDK_UA_APP_ID`` environment variable.
* The ``sdk_ua_app_id`` setting in the shared AWS config file.
* The ``user_agent_appid`` field in the :py:class:`botocore.config.Config`.
* The ``user_agent_extra`` field in the :py:class:`botocore.config.Config`.

    N)copy)ascii_lettersdigits)
NamedTupleOptional)__version__)HAS_CRTz!$%&'*+-.^_`|~)windowslinuxmacosandroidioswatchostvosotherdarwinr   Botocorec                    s   d  fdd| D S )a}  Replaces all not allowed characters in the string with a dash ("-").

    Allowed characters are ASCII alphanumerics and ``!$%&'*+-.^_`|~``. If
    ``allow_hash`` is ``True``, "#"``" is also allowed.

    :type raw_str: str
    :param raw_str: The input string to be sanitized.

    :type allow_hash: bool
    :param allow_hash: Whether "#" is considered an allowed character.
     c                 3   s,    | ]}|t v s r|d kr|ndV  qdS )#-N)_USERAGENT_ALLOWED_CHARACTERS).0c
allow_hash P/home/air/shanriGPT/back/venv/lib/python3.10/site-packages/botocore/useragent.py	<genexpr>B   s    
z7sanitize_user_agent_string_component.<locals>.<genexpr>)join)raw_strr   r   r   r   $sanitize_user_agent_string_component6   s   r    c                   @   s:   e Zd ZU dZeed< eed< dZee ed< dd ZdS )UserAgentComponenta;  
    Component of a Botocore User-Agent header string in the standard format.

    Each component consists of a prefix, a name, and a value. In the string
    representation these are combined in the format ``prefix/name#value``.

    This class is considered private and is subject to abrupt breaking changes.
    prefixnameNvaluec                 C   s`   t | jdd}t | jdd}| jdu s| jdkr| d| S t | jdd}| d| d| S )zACreate string like 'prefix/name#value' from a UserAgentComponent.Tr   FNr   /r   )r    r"   r#   r$   )selfclean_prefix
clean_nameclean_valuer   r   r   	to_stringX   s   zUserAgentComponent.to_string)	__name__
__module____qualname____doc__str__annotations__r$   r   r*   r   r   r   r   r!   J   s   
 	r!   c                   @   s    e Zd ZdZdd Zdd ZdS )RawStringUserAgentComponentz
    UserAgentComponent interface wrapper around ``str``.

    Use for User-Agent header components that are not constructed from
    prefix+name+value but instead are provided as strings. No sanitization is
    performed.
    c                 C   s
   || _ d S N_value)r&   r$   r   r   r   __init__q   s   
z$RawStringUserAgentComponent.__init__c                 C   s   | j S r2   r3   r&   r   r   r   r*   t   s   z%RawStringUserAgentComponent.to_stringN)r+   r,   r-   r.   r5   r*   r   r   r   r   r1   h   s    r1   )modify_componentsc                 C   s   | S r2   r   )
componentsr   r   r   r7   ~   s   r7   c                   @   s   e Zd ZdZ	d!ddZedd Zdd Zd	d
 Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  ZdS )"UserAgentStringaU  
    Generator for AWS SDK User-Agent header strings.

    The User-Agent header format contains information from session, client, and
    request context. ``UserAgentString`` provides methods for collecting the
    information and ``to_string`` for assembling it into the standardized
    string format.

    Example usage:

        ua_session = UserAgentString.from_environment()
        ua_session.set_session_config(...)
        ua_client = ua_session.with_client_config(Config(...))
        ua_string = ua_request.to_string()

    For testing or when information from all sources is available at the same
    time, the methods can be chained:

        ua_string = (
            UserAgentString
            .from_environment()
            .set_session_config(...)
            .with_client_config(Config(...))
            .to_string()
        )

    Nc                 C   sX   || _ || _|| _|| _|| _|| _|| _d| _d| _d| _	d| _
d| _d| _d| _dS )a  
        :type platform_name: str
        :param platform_name: Name of the operating system or equivalent
            platform name. Should be sourced from :py:meth:`platform.system`.
        :type platform_version: str
        :param platform_version: Version of the operating system or equivalent
            platform name. Should be sourced from :py:meth:`platform.version`.
        :type platform_machine: str
        :param platform_version: Processor architecture or machine type. For
        example "x86_64". Should be sourced from :py:meth:`platform.machine`.
        :type python_version: str
        :param python_version: Version of the python implementation as str.
            Should be sourced from :py:meth:`platform.python_version`.
        :type python_implementation: str
        :param python_implementation: Name of the python implementation.
            Should be sourced from :py:meth:`platform.python_implementation`.
        :type execution_env: str
        :param execution_env: The value of the AWS execution environment.
            Should be sourced from the ``AWS_EXECUTION_ENV` environment
            variable.
        :type crt_version: str
        :param crt_version: Version string of awscrt package, if installed.
        N)_platform_name_platform_version_platform_machine_python_version_python_implementation_execution_env_crt_version_session_user_agent_name_session_user_agent_version_session_user_agent_extra_client_config_uses_paginator_uses_waiter_uses_resource)r&   platform_nameplatform_versionplatform_machinepython_versionpython_implementationexecution_envcrt_versionr   r   r   r5      s   !
zUserAgentString.__init__c              	   C   sD   d }t r	t pd}| t t t t t tj	
d|dS )NUnknownAWS_EXECUTION_ENV)rH   rI   rJ   rK   rL   rM   rN   )r   _get_crt_versionplatformsystemreleasemachinerK   rL   osenvironget)clsrN   r   r   r   from_environment   s   

z UserAgentString.from_environmentc                 C   s   || _ || _|| _| S )ax  
        Set the user agent configuration values that apply at session level.

        :param user_agent_name: The user agent name configured in the
            :py:class:`botocore.session.Session` object. For backwards
            compatibility, this will always be at the beginning of the
            User-Agent string, together with ``user_agent_version``.
        :param user_agent_version: The user agent version configured in the
            :py:class:`botocore.session.Session` object.
        :param user_agent_extra: The user agent "extra" configured in the
            :py:class:`botocore.session.Session` object.
        )rA   rB   rC   )r&   session_user_agent_namesession_user_agent_versionsession_user_agent_extrar   r   r   set_session_config   s   z"UserAgentString.set_session_configc                 C   s   t | }||_|S )z
        Create a copy with all original values and client-specific values.

        :type client_config: botocore.config.Config
        :param client_config: The client configuration object.
        )r   rD   )r&   client_configcpr   r   r   with_client_config   s   z"UserAgentString.with_client_configc                 C   s   d}| j rt| j dr| j j}n| j j}|dur| |S g |  td|  |  | 	 | 
 |  |  |  |  }t|}ddd |D S )zN
        Build User-Agent header string from the object's properties.
        N_supplied_user_agentzua/2.0 c                 S   s   g | ]}|  qS r   )r*   )r   compr   r   r   
<listcomp>   s    z-UserAgentString.to_string.<locals>.<listcomp>)rD   hasattrrb   
user_agent_build_legacy_ua_string_build_sdk_metadatar1   _build_os_metadata_build_architecture_metadata_build_language_metadata_build_execution_env_metadata_build_feature_metadata_build_config_metadata_build_app_id_build_extrar7   r   r&   config_ua_overrider8   r   r   r   r*     s<   

	
zUserAgentString.to_stringc                 C   sx   g }| j r#| jr#| j tks| jtkr#|t| j | jtdttg n|ttt | jdur:|tdd| j |S )at  
        Build the SDK name and version component of the User-Agent header.

        For backwards-compatibility both session-level and client-level config
        of custom tool names are honored. If this removes the Botocore
        information from the start of the string, Botocore's name and version
        are included as a separate field with "md" prefix.
        mdNawscrt)rA   rB   _USERAGENT_SDK_NAMEbotocore_versionextendr!   appendr@   )r&   sdk_mdr   r   r   ri   "  s2   	


z#UserAgentString._build_sdk_metadatac                 C   sv   | j du rtddgS | j  }|tv r|}n|tv r t| }nd}|dur.td|| jgS tddtd| j | jgS )a"  
        Build the OS/platform components of the User-Agent header string.

        For recognized platform names that match or map to an entry in the list
        of standardized OS names, a single component with prefix "os" is
        returned. Otherwise, one component "os/other" is returned and a second
        with prefix "md" and the raw platform name.

        String representations of example return values:
         * ``os/macos#10.13.6``
         * ``os/linux``
         * ``os/other``
         * ``os/other md/foobar#1.2.3``
        NrV   r   rt   )r:   r!   lower_USERAGENT_ALLOWED_OS_NAMES!_USERAGENT_PLATFORM_NAME_MAPPINGSr;   )r&   plt_name_lower	os_familyr   r   r   rj   K  s    



z"UserAgentString._build_os_metadatac                 C   s   | j rtdd| j  gS g S )z
        Build architecture component of the User-Agent header string.

        Returns the machine type with prefix "md" and name "arch", if one is
        available. Common values include "x86_64", "arm64", "i386".
        rt   arch)r<   r!   r{   r6   r   r   r   rk   q  s   z,UserAgentString._build_architecture_metadatac                 C   s.   t dd| jg}| jr|t dd| j |S )a  
        Build the language components of the User-Agent header string.

        Returns the Python version in a component with prefix "lang" and name
        "python". The Python implementation (e.g. CPython, PyPy) is returned as
        separate metadata component with prefix "md" and name "pyimpl".

        String representation of an example return value:
        ``lang/python#3.10.4 md/pyimpl#CPython``
        langpythonrt   pyimpl)r!   r=   r>   ry   )r&   lang_mdr   r   r   rl     s   z(UserAgentString._build_language_metadatac                 C   s   | j r
td| j gS g S )z
        Build the execution environment component of the User-Agent header.

        Returns a single component prefixed with "exec-env", usually sourced
        from the environment variable AWS_EXECUTION_ENV.
        zexec-env)r?   r!   r6   r   r   r   rm     s   z-UserAgentString._build_execution_env_metadatac                 C   s   g S )z
        Build the features components of the User-Agent header string.

        Botocore currently does not report any features. This may change in a
        future version.
        r   r6   r   r   r   rn     s   z'UserAgentString._build_feature_metadatac                 C   sJ   | j r| j js	g S | j jd}tdd|g}| j jr#|tdd |S )a  
        Build the configuration components of the User-Agent header string.

        Returns a list of components with prefix "cfg" followed by the config
        setting name and its value. Tracked configuration settings may be
        added or removed in future versions.
        modecfgz
retry-modezendpoint-discovery)rD   retriesrX   r!   endpoint_discovery_enabledry   )r&   
retry_modecfg_mdr   r   r   ro     s   z&UserAgentString._build_config_metadatac                 C   s"   | j r| j jrtd| j jgS g S )a  
        Build app component of the User-Agent header string.

        Returns a single component with prefix "app" and value sourced from the
        ``user_agent_appid`` field in :py:class:`botocore.config.Config` or
        the ``sdk_ua_app_id`` setting in the shared configuration file, or the
        ``AWS_SDK_UA_APP_ID`` environment variable. These are the recommended
        ways for apps built with Botocore to insert their identifer into the
        User-Agent header.
        app)rD   user_agent_appidr!   r6   r   r   r   rp     s   zUserAgentString._build_app_idc                 C   s>   g }| j r|t| j  | jr| jjr|t| jj |S )a  User agent string components based on legacy "extra" settings.

        Creates components from the session-level and client-level
        ``user_agent_extra`` setting, if present. Both are passed through
        verbatim and should be appended at the end of the string.

        Preferred ways to inject application-specific information into
        botocore's User-Agent header string are the ``user_agent_appid` field
        in :py:class:`botocore.config.Config`. The ``AWS_SDK_UA_APP_ID``
        environment variable and the ``sdk_ua_app_id`` configuration file
        setting are alternative ways to set the ``user_agent_appid`` config.
        )rC   ry   r1   rD   user_agent_extra)r&   extrar   r   r   rq     s   zUserAgentString._build_extrac                 C   s8   |g}| j r|| j  | jjr|| jj d|S )Nrc   )rC   ry   rD   r   r   rr   r   r   r   rh     s   
z'UserAgentString._build_legacy_ua_stringr2   )r+   r,   r-   r.   r5   classmethodrZ   r^   ra   r*   ri   rj   rk   rl   rm   rn   ro   rp   rq   rh   r   r   r   r   r9      s&    $
3
)&	r9   c                  C   s&   zddl } | jW S  ty   Y dS w )z\
    This function is considered private and is subject to abrupt breaking
    changes.
    r   N)ru   r   AttributeError)ru   r   r   r   rQ     s   rQ   )r.   rV   rR   r   stringr   r   typingr   r   botocorer   rw   botocore.compatr   r   r|   r}   rv   r    r!   r1   !botocore.customizations.useragentr7   ImportErrorr9   rQ   r   r   r   r   <module>   s0   
  n