U
    bek                     @   sp   d Z ddlZddlZddlZeeZdddddgZdZ	d	d
 Z
dd ZdddZdddZdd Zdd ZdS )z(Helper functions for documentation, etc.    NZs3Zs3nZs3uZs3agsz0///smart_open.utils.QUESTION_MARK_PLACEHOLDER///c                 C   s   zt | }W nt tk
r   zt | \}}}}W n tk
rP   i  Y  Y S X |s^i  Y S |t| d  }tt|| Y S X dd |j	 D S d S )Nc                 S   s&   i | ]\}}|j tjjkr||j qS  )defaultinspect	Parameterempty).0nameparamr   r   R/var/www/html/services/stratfitenv/lib/python3.8/site-packages/smart_open/utils.py
<dictcomp>,   s    z"inspect_kwargs.<locals>.<dictcomp>)
r   	signatureAttributeError
getargspec	TypeErrorlendictzip
parametersitems)kallabler   argsvarargskeywordsdefaultssupported_keywordsr   r   r   inspect_kwargs   s    r   c                    sL   t t|   fddt |D } fdd| D }|rHtd| |S )a  Check which keyword arguments the callable supports.

    Parameters
    ----------
    kallable: callable
        A function or method to test
    kwargs: dict
        The keyword arguments to check.  If the callable doesn't support any
        of these, a warning message will get printed.

    Returns
    -------
    dict
        A dictionary of argument names and values supported by the callable.
    c                    s   g | ]}| kr|qS r   r   )r   kr   r   r   
<listcomp>D   s      z check_kwargs.<locals>.<listcomp>c                    s   i | ]\}}| kr||qS r   r   )r   r   vr   r   r   r   E   s       z check_kwargs.<locals>.<dictcomp>z*ignoring unsupported keyword arguments: %r)sortedr   r   loggerwarning)r   kwargsZunsupported_keywordsZsupported_kwargsr   r   r   check_kwargs3   s    r%   c                 C   s    |dk	rt | |} t| |} | S )aI  Clamp a numeric value to a specific range.

    Parameters
    ----------
    value: numeric
        The value to clamp.

    minval: numeric
        The lower bound.

    maxval: numeric
        The upper bound.

    Returns
    -------
    numeric
        The clamped value.  It will be in the range ``[minval, maxval]``.

    N)minmax)valueminvalmaxvalr   r   r   clampM   s    

r+   c                 C   sL   | dkr|dkrt d| dkr$dnt| }|dkr8dnt|}d||f S )ak  Create a byte range specifier in accordance with RFC-2616.

    Parameters
    ----------
    start: int, optional
        The start of the byte range.  If unspecified, stop indicated offset from EOF.

    stop: int, optional
        The end of the byte range.  If unspecified, indicates EOF.

    Returns
    -------
    str
        A byte range specifier.

    Nz7make_range_string requires either a stop or start value zbytes=%s-%s)
ValueErrorstr)startstopZ	start_strZstop_strr   r   r   make_range_stringg   s
    r1   c                 C   sH   |  dd\}}| dd\}}| dd\}}|t|t|t|fS )a  Extract units, start, stop, and length from a content range header like "bytes 0-846981/846982".

    Assumes a properly formatted content-range header from S3.
    See werkzeug.http.parse_content_range_header for a more robust version.

    Parameters
    ----------
    content_range: str
        The content-range header to parse.

    Returns
    -------
    tuple (units: str, start: int, stop: int, length: int)
        The units and three integers from the content-range header.

        /-)splitint)Zcontent_rangeZunitsnumbersrangelengthr/   r0   r   r   r   parse_content_range   s    r;   c                 C   s   t jj| dd}d}|jtkrNd| krNt| krNt}| d|} t jj| dd}|dkrZ|S |j|d}t j|j|j	|ddS )a  This is a hack to prevent the regular urlsplit from splitting around question marks.

    A question mark (?) in a URL typically indicates the start of a
    querystring, and the standard library's urlparse function handles the
    querystring separately.  Unfortunately, question marks can also appear
    _inside_ the actual URL for some schemas like S3, GS.

    Replaces question marks with a special placeholder substring prior to
    splitting.  This work-around behavior is disabled in the unlikely event the
    placeholder is already part of the URL.  If this affects you, consider
    changing the value of QUESTION_MARK_PLACEHOLDER to something more suitable.

    See Also
    --------
    https://bugs.python.org/issue43882
    https://github.com/python/cpython/blob/3.7/Lib/urllib/parse.py
    https://github.com/RaRe-Technologies/smart_open/issues/285
    https://github.com/RaRe-Technologies/smart_open/issues/458
    smart_open/utils.py:QUESTION_MARK_PLACEHOLDER
    F)allow_fragmentsN?r,   )
urllibparseurlsplitschemeWORKAROUND_SCHEMESQUESTION_MARK_PLACEHOLDERreplacepathSplitResultnetloc)urlsrplaceholderrE   r   r   r   safe_urlsplit   s    rK   )r   N)NN)__doc__r   loggingurllib.parser>   	getLogger__name__r"   rB   rC   r   r%   r+   r1   r;   rK   r   r   r   r   <module>	   s   


