
                             d Z ddlZddlZddlZddlZddlmZ ddgZg dZ ej                  e
      ZdZdZd	Z eeeeg      ZeZd
 Zd Zd Zd Zy)zCommon utility library.    N)urllibzrafek@google.com (Rafe Kaplan)z#guido@google.com (Guido van Rossum))
positionalPOSITIONAL_WARNINGPOSITIONAL_EXCEPTIONPOSITIONAL_IGNOREWARNING	EXCEPTIONIGNOREc                       fd}t         t        j                        r|S t        j                         \  }}}} t        t        |      t        |      z
               S )a  A decorator to declare that only the first N arguments my be positional.

    This decorator makes it easy to support Python 3 style keyword-only
    parameters. For example, in Python 3 it is possible to write::

        def fn(pos1, *, kwonly1=None, kwonly1=None):
            ...

    All named parameters after ``*`` must be a keyword::

        fn(10, 'kw1', 'kw2')  # Raises exception.
        fn(10, kwonly1='kw1')  # Ok.

    Example
    ^^^^^^^

    To define a function like above, do::

        @positional(1)
        def fn(pos1, kwonly1=None, kwonly2=None):
            ...

    If no default value is provided to a keyword argument, it becomes a
    required keyword argument::

        @positional(0)
        def fn(required_kw):
            ...

    This must be called with the keyword parameter::

        fn()  # Raises exception.
        fn(10)  # Raises exception.
        fn(required_kw=10)  # Ok.

    When defining instance or class methods always remember to account for
    ``self`` and ``cls``::

        class MyClass(object):

            @positional(2)
            def my_method(self, pos1, kwonly1=None):
                ...

            @classmethod
            @positional(2)
            def my_method(cls, pos1, kwonly1=None):
                ...

    The positional decorator behavior is controlled by
    ``util.positional_parameters_enforcement``, which may be set to
    ``POSITIONAL_EXCEPTION``, ``POSITIONAL_WARNING`` or
    ``POSITIONAL_IGNORE`` to raise an exception, log a warning, or do
    nothing, respectively, if a declaration is violated.

    Args:
        max_positional_arguments: Maximum number of positional arguments. All
                                  parameters after the this index must be
                                  keyword only.

    Returns:
        A decorator that prevents using arguments after max_positional_args
        from being used as positional parameters.

    Raises:
        TypeError: if a key-word only argument is provided as a positional
                   parameter, but only if
                   util.positional_parameters_enforcement is set to
                   POSITIONAL_EXCEPTION.
    c                 F     t        j                          fd       }|S )Nc                     t        |       kD  rkd}dk7  rd}dj                  j                  t        |       |      }t        t        k(  rt        |      t        t        k(  rt        j                  |        | i |S )N    szV{function}() takes at most {args_max} positional argument{plural} ({args_given} given))functionargs_max
args_givenplural)	lenformat__name__!positional_parameters_enforcementr   	TypeErrorr   loggerwarning)argskwargsplural_smessagemax_positional_argswrappeds       $lib/third_party/oauth2client/util.pypositional_wrapperzDpositional.<locals>.positional_decorator.<locals>.positional_wrappery   s    4y..&!+"HCCI6(/(8(8(;*-d)&.	 DJ D0  58LL#G,,6:LLNN7+D+F++    )	functoolswraps)r!   r#   r    s   ` r"   positional_decoratorz(positional.<locals>.positional_decoratorx   s&    		!	, 
"	,  "!r$   )
isinstancesixinteger_typesinspect
getargspecr   r   )r    r'   r   _defaultss   `    r"   r   r   0   s\    P"( %s'8'89##&112EFaH4z#d)c(m345HIIr$   c                 \    t        | t        j                        r| S dj                  |       S )a_  Converts scope value to a string.

    If scopes is a string then it is simply passed through. If scopes is an
    iterable then a string is returned that is all the individual scopes
    concatenated with spaces.

    Args:
        scopes: string or iterable of strings, the scopes.

    Returns:
        The scopes formatted as a single string.
     )r(   r)   string_typesjoinscopess    r"   scopes_to_stringr5      s(     &#**+xxr$   c                 d    | sg S t        | t        j                        r| j                  d      S | S )a+  Converts stringifed scope value to a list.

    If scopes is a list then it is simply passed through. If scopes is an
    string then a list of each individual scope is returned.

    Args:
        scopes: a string or iterable of strings, the scopes.

    Returns:
        The scopes in a list.
    r0   )r(   r)   r1   splitr3   s    r"   string_to_scopesr8      s0     	&#**+||C  r$   c                 <   || S t        t        j                  j                  |             }t	        t        j                  j                  |d               }|||<   t        j                  j                  |      |d<   t        j                  j                  |      S )a\  Adds a query parameter to a url.

    Replaces the current value if it already exists in the URL.

    Args:
        url: string, url to add the query parameter to.
        name: string, query parameter name.
        value: string, query parameter value.

    Returns:
        Updated query parameter. Does not update the url if value is None.
       )listr   parseurlparsedict	parse_qsl	urlencode
urlunparse)urlnamevalueparsedqs        r"   _add_query_parameterrG      sz     }
fll++C01''q	23$LL**1-q	||&&v..r$   )__doc__r%   r+   loggingr)   	six.movesr   
__author____all__	getLoggerr   r   r   r   r   	frozensetPOSITIONAL_SETr   r   r5   r8   rG    r$   r"   <module>rQ      s        
  %)

 
		8	$ "  .0D-/ 0 %7 !`JF &(/r$   