
    x                     H    S r SSKrSSKrSSKrS rS rS	S jrS rS rS r	g)
z-Helper functions for commonly used utilities.    Nc                 :    U R                  S5      nUS:w  a  XS $ g)aV  Identify and extract PEM keys.

Determines whether the given key is in the format of PEM key, and extracts
the relevant part of the key if it is.

Args:
    raw_key_input: The contents of a private key file (either PEM or
                   PKCS12).

Returns:
    string, The actual key if the contents are from a PEM file, or
    else None.
s   -----BEGIN N)find)raw_key_inputoffsets     (lib/third_party/oauth2client/_helpers.py_parse_pem_keyr	      s+     /F|W%%     c                 ,    [         R                  " U SS9$ )N),:)
separators)jsondumps)datas    r   _json_encoder   )   s    ::dz22r
   c                     [        U [        R                  5      (       a  U R                  U5      OU n[        U[        R                  5      (       a  U$ [        SR                  U 5      5      e)a  Converts a string value to bytes, if necessary.

Unfortunately, ``six.b`` is insufficient for this task since in
Python2 it does not modify ``unicode`` objects.

Args:
    value: The string/bytes value to be converted.
    encoding: The encoding to use to convert unicode to bytes. Defaults
              to "ascii", which will not allow any characters from ordinals
              larger than 127. Other useful values are "latin-1", which
              which will only allows byte ordinals (up to 255) and "utf-8",
              which will encode any unicode that needs to be.

Returns:
    The original value converted to bytes (if unicode) or as passed in
    if it started out as bytes.

Raises:
    ValueError if the value could not be converted to bytes.
z%{0!r} could not be converted to bytes)
isinstancesix	text_typeencodebinary_type
ValueErrorformat)valueencodingresults      r   	_to_bytesr   -   sX    , E3==11 ll8$7< &#//**@GGNOOr
   c                     [        U [        R                  5      (       a  U R                  S5      OU n[        U[        R                  5      (       a  U$ [        SR                  U 5      5      e)a%  Converts bytes to a string value, if necessary.

Args:
    value: The string/bytes value to be converted.

Returns:
    The original value converted to unicode (if bytes) or as passed in
    if it started out as unicode.

Raises:
    ValueError if the value could not be converted to unicode.
utf-8z'{0!r} could not be converted to unicode)r   r   r   decoder   r   r   )r   r   s     r   _from_bytesr"   J   s^     E3??33 ll7#9> &#--((5<<UCE 	Er
   c                 `    [        U SS9n [        R                  " U 5      R                  S5      $ )Nr    )r      =)r   base64urlsafe_b64encoderstrip)	raw_bytess    r   _urlsafe_b64encoder)   `   s*    )g6I##I.55d;;r
   c                 r    [        U 5      n U SS[        U 5      S-  -
  -  -   n[        R                  " U5      $ )Nr$      )r   lenr%   urlsafe_b64decode)	b64stringpaddeds     r   _urlsafe_b64decoder0   e   s:    )$IS^a%7!788F##F++r
   )ascii)
__doc__r%   r   r   r	   r   r   r"   r)   r0    r
   r   <module>r4      s3    4   
&&3P:E,<
,r
   