�
�McL} � �� � d Z ddlZddlZddlZddlZddlZddlmZ ddl Z ddl
mZmZm
Z
ddlmZ ej e� � Zdededed efd
�Zd1deded efd
�Z d2d�Zd efd�Zdedededefd�Z d3defd�Zd� Zd3d�Zd� Zd� Zd3d�Zd� Zdefd�Z d3dedefd �Z!i Z"defd!�Z#d"� Z$deded#efd$�Z%ded%efd&�Z&d'� Z'd%efd(�Z(d)� Z)defd*�Z*d%efd+�Z+defd,�Z,d%efd-�Z-d.� Z.d/� Z/d3d0�Z0dS )4a�
This module is an implementation of `section 3.4`_ of RFC 5849.
**Usage**
Steps for signing a request:
1. Collect parameters from the request using ``collect_parameters``.
2. Normalize those parameters using ``normalize_parameters``.
3. Create the *base string URI* using ``base_string_uri``.
4. Create the *signature base string* from the above three components
using ``signature_base_string``.
5. Pass the *signature base string* and the client credentials to one of the
sign-with-client functions. The HMAC-based signing functions needs
client credentials with secrets. The RSA-based signing functions needs
client credentials with an RSA private key.
To verify a request, pass the request and credentials to one of the verify
functions. The HMAC-based signing functions needs the shared secrets. The
RSA-based verify functions needs the RSA public key.
**Scope**
All of the functions in this module should be considered internal to OAuthLib,
since they are not imported into the "oauthlib.oauth1" module. Programs using
OAuthLib should not use directly invoke any of the functions in this module.
**Deprecated functions**
The "sign_" methods that are not "_with_client" have been deprecated. They may
be removed in a future release. Since they are all internal functions, this
should have no impact on properly behaving programs.
.. _`section 3.4`: https://tools.ietf.org/html/rfc5849#section-3.4
� N)�extract_params�safe_string_equals� urldecode� )�utils�http_method�base_str_uri�%normalized_encoded_request_parameters�returnc �� � t j | � � � � � }|dz
}|t j |� � z
}|dz
}|t j |� � z
}|S )a�
Construct the signature base string.
The *signature base string* is the value that is calculated and signed by
the client. It is also independently calculated by the server to verify
the signature, and therefore must produce the exact same value at both
ends or the signature won't verify.
The rules for calculating the *signature base string* are defined in
section 3.4.1.1`_ of RFC 5849.
.. _`section 3.4.1.1`: https://tools.ietf.org/html/rfc5849#section-3.4.1.1
�&)r �escape�upper)r r r
�base_strings �C/usr/lib/python3/dist-packages/oauthlib/oauth1/rfc5849/signature.py�signature_base_stringr 6 sj � �4 �,�{�0�0�2�2�3�3�K� �3��K� �5�<��-�-�-�K� �3��K� �5�<� E�F�F�F�K��� �uri�hostc �h � t | t � � st d� � �t j | � � }|j }|j }|j }|j }|j }|st d� � �|sd}|� � � }|�|� � � }|�=|� � � }|� d|� �}t j |� � }|j }|j }|�t d� � � t j |� � }n# t $ r Y nw xY wt |t j � � rd|� d�}nt |t j
� � r|� }|�d |cxk rd
k sn t d� � �||fdv r|}n|r|� d
|� �}n|}t j ||||ddf� � } | � dd� � S )a�
Calculates the _base string URI_.
The *base string URI* is one of the components that make up the
*signature base string*.
The ``host`` is optional. If provided, it is used to override any host and
port values in the ``uri``. The value for ``host`` is usually extracted from
the "Host" request header from the HTTP request. Its value may be just the
hostname, or the hostname followed by a colon and a TCP/IP port number
(hostname:port). If a value for the``host`` is provided but it does not
contain a port number, the default port number is used (i.e. if the ``uri``
contained a port number, it will be discarded).
The rules for calculating the *base string URI* are defined in
section 3.4.1.2`_ of RFC 5849.
.. _`section 3.4.1.2`: https://tools.ietf.org/html/rfc5849#section-3.4.1.2
:param uri: URI
:param host: hostname with optional port number, separated by a colon
:return: base string URI
zuri must be a string.zmissing scheme�/Nz://zmissing host�[�]r i�� zport out of range))�http�P )�httpsi� �:� � z%20)�
isinstance�str�
ValueError�urlparse�scheme�hostname�port�path�params�lower� ipaddress�
ip_address�IPv6Address�IPv4Address�
urlunparse�replace)
r r �outputr$ r% r& |