Ë
    U¼SfÔH  ã                   óö  — U d Z ddlmZ ddlZddlZddlZddlZddlZddl	m
Z ddlmZ ddlZddlZddlmZ ddlmZ 	 ddlZddlZej                  j.                  Zej2                  j4                  Z ej                  dd	d	ej2                  j4                  ¬
«      ZdZdZdZdZ  ejB                  dejD                  «      Z#ee$df   e%d<   	 ejL                  jO                  d«      Z(ejL                  jS                  ddd«      Z*dZ+dZ, G d„ de«      Z-d„ Z.d0d„Z/d„ Z0d„ Z1d„ Z2d„ Z3d„ Z4d „ Z5d!„ Z6d"„ Z7d1d#„Z8d2d$„Z9d%„ Z:d&„ Z;d'„ Z<d(„ Z=d)„ Z>d*„ Z?d+„ Z@d,„ ZAd3d-„ZBd3d.„ZCd0d/„ZDy# e$ r dZY �Œ#w xY w# e$ r dZ(Y Œ�w xY w)4z^Shared helpers for Google Cloud packages.

This module is not part of the public API surface.
é    )Úabsolute_importN)Úlocal)ÚUnion)Úduration_pb2)Útimestamp_pb2i²  é   ©Útzinfoz%Y-%m-%dT%H:%M:%S.%fZz%Y-%m-%dT%H:%M:%Sz%H:%M:%S.%fz%H:%M:%Sah  
    (?P<no_fraction>
        \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}  # YYYY-MM-DDTHH:MM:SS
    )
    (                                        # Optional decimal part
     \.                                      # decimal point
     (?P<nanos>\d{1,9})                      # nanoseconds, maybe truncated
    )?
    Z                                        # Zulu
Ú
_USER_ROOTú~ÚgcloudÚconfigurationsÚconfig_defaultÚcoreÚprojectc                   óD   ‡ — e Zd ZdZˆ fd„Zd„ Zd„ Zd„ Zed„ «       Z	ˆ xZ
S )Ú_LocalStackzÁManage a thread-local LIFO stack of resources.

    Intended for use in :class:`google.cloud.datastore.batch.Batch.__enter__`,
    :class:`google.cloud.storage.batch.Batch.__enter__`, etc.
    c                 ó8   •— t         t        | �  «        g | _        y ©N)Úsuperr   Ú__init__Ú_stack)ÚselfÚ	__class__s    €ú]C:\Users\user\Documents\project_loop\venv\Lib\site-packages\google/cloud/_helpers/__init__.pyr   z_LocalStack.__init__S   s   ø€ ÜŒk˜4Ñ)Ô+Øˆ�ó    c                 ó>   — t        t        | j                  «      «      S )z Iterate the stack in LIFO order.)ÚiterÚreversedr   ©r   s    r   Ú__iter__z_LocalStack.__iter__W   s   € ä”H˜TŸ[™[Ó)Ó*Ð*r   c                 ó:   — | j                   j                  |«       y)zPush a resource onto our stack.N)r   Úappend)r   Úresources     r   Úpushz_LocalStack.push[   s   € à�‰×Ñ˜8Õ$r   c                 ó6   — | j                   j                  «       S )z®Pop a resource from our stack.

        :rtype: object
        :returns: the top-most resource, after removing it.
        :raises IndexError: if the stack is empty.
        )r   Úpopr    s    r   r'   z_LocalStack.pop_   s   € ð �{‰{�‰Ó Ð r   c                 ó:   — | j                   r| j                   d   S y)z~Get the top-most resource

        :rtype: object
        :returns: the top-most item, or None if the stack is empty.
        éÿÿÿÿN)r   r    s    r   Útopz_LocalStack.toph   s   € ð �;Š;Ø—;‘;˜r‘?Ð"ð r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r!   r%   r'   Úpropertyr*   Ú__classcell__)r   s   @r   r   r   L   s0   ø„ ñôò+ò%ò!ð ñ#ó ô#r   r   c                 óf   — t        |t        t        f«      st        d| ›d|›�«      ‚t        |«      S )aé  Ensures an input is a tuple or list.

    This effectively reduces the iterable types allowed to a very short
    allowlist: list and tuple.

    :type arg_name: str
    :param arg_name: Name of argument to use in error message.

    :type tuple_or_list: sequence of str
    :param tuple_or_list: Sequence to be verified.

    :rtype: list of str
    :returns: The ``tuple_or_list`` passed in cast to a ``list``.
    :raises TypeError: if the ``tuple_or_list`` is not a tuple or list.
    z	Expected z! to be a tuple or list. Received )Ú
isinstanceÚtupleÚlistÚ	TypeError)Úarg_nameÚtuple_or_lists     r   Ú_ensure_tuple_or_listr8   s   s6   € ô  �m¤e¬T ]Ô3Ýâ%¡}ð6ó
ð 	
ô �ÓÐr   c                 óL   — | €!t         j                  j                  «       \  }} | S )aY  Determine default project ID explicitly or implicitly as fall-back.

    See :func:`google.auth.default` for details on how the default project
    is determined.

    :type project: str
    :param project: Optional. The project name to use as default.

    :rtype: str or ``NoneType``
    :returns: Default project if it can be determined.
    )ÚgoogleÚauthÚdefault)r   Ú_s     r   Ú_determine_default_projectr>   ‹   s$   € ð €Ü—[‘[×(Ñ(Ó*‰
ˆˆ7Ø€Nr   c                 ó"   — t        | «      }|dz  S )zÕConvert a zone-aware datetime to integer milliseconds.

    :type when: :class:`datetime.datetime`
    :param when: the datetime to convert

    :rtype: int
    :returns: milliseconds since epoch for ``when``
    éè  )Ú_microseconds_from_datetime)ÚwhenÚmicross     r   Ú_millisrD   œ   s   € ô )¨Ó.€FØ�T‰>Ðr   c                 ó<   — t         t        j                  | ¬«      z   S )zÖConvert timestamp to datetime, assuming UTC.

    :type value: float
    :param value: The timestamp to convert

    :rtype: :class:`datetime.datetime`
    :returns: The datetime object created from the value.
    )Úmicroseconds)Ú_EPOCHÚdatetimeÚ	timedelta©Úvalues    r   Ú_datetime_from_microsecondsrL   ©   s   € ô ”H×&Ñ&°EÔ:Ñ:Ð:r   c                 óè   — | j                   s| j                  t        ¬«      } | j                  t        «      } t	        t        j                  | j                  «       «      dz  «      | j                  z   S )zÇConvert non-none datetime to microseconds.

    :type value: :class:`datetime.datetime`
    :param value: The timestamp to convert.

    :rtype: int
    :returns: The timestamp, in microseconds.
    r	   g    €„.A)	r
   ÚreplaceÚUTCÚ
astimezoneÚintÚcalendarÚtimegmÚ	timetupleÚmicrosecondrJ   s    r   rA   rA   µ   sV   € ð �<Š<Ø—‘¤S�Ó)ˆà×ÑœSÓ!€EäŒx�‰˜uŸ™Ó0Ó1°CÑ7Ó8¸5×;LÑ;LÑLÐLr   c                 ó   — | �t        | «      S y)zêConvert non-none datetime to timestamp, assuming UTC.

    :type value: :class:`datetime.datetime`
    :param value: (Optional) the timestamp

    :rtype: int, or ``NoneType``
    :returns: the timestamp, in milliseconds, or None
    N)rD   rJ   s    r   Ú_millis_from_datetimerW   Æ   s   € ð ÐÜ�u‹~Ðð r   c                 ó^   — t         j                   j                  | d«      j                  «       S )zßConvert a ISO8601 date string to native datetime date

    :type value: str
    :param value: The date string to convert

    :rtype: :class:`datetime.date`
    :returns: A datetime date object created from the string

    z%Y-%m-%d)rH   ÚstrptimeÚdaterJ   s    r   Ú_date_from_iso8601_dater[   Ó   s&   € ô ×Ñ×%Ñ% e¨ZÓ8×=Ñ=Ó?Ð?r   c                 óæ   — t        | «      dk(  rt        }n/t        | «      dk(  rt        }nt        dj	                  | «      «      ‚t
        j
                  j                  | |«      j                  «       S )a*  Convert a zoneless ISO8601 time string to naive datetime time

    :type value: str
    :param value: The time string to convert

    :rtype: :class:`datetime.time`
    :returns: A datetime time object created from the string
    :raises ValueError: if the value does not match a known format.
    é   é   zUnknown time format: {})ÚlenÚ_TIMEONLY_NO_FRACTIONÚ_TIMEONLY_W_MICROSÚ
ValueErrorÚformatrH   rY   Útime)rK   Úfmts     r   Ú_time_from_iso8601_time_naiverf   à   s^   € ô ˆ5ƒz�Q‚Ü#‰Ü	ˆU‹�rÒ	Ü ‰äÐ2×9Ñ9¸%Ó@ÓAÐAÜ×Ñ×%Ñ% e¨SÓ1×6Ñ6Ó8Ð8r   c                 ór   — t         j                   j                  | t        «      j                  t        ¬«      S )zèConvert a microsecond-precision timestamp to a native datetime.

    :type dt_str: str
    :param dt_str: The string to convert.

    :rtype: :class:`datetime.datetime`
    :returns: The datetime object created from the string.
    r	   )rH   rY   Ú_RFC3339_MICROSrN   rO   )Údt_strs    r   Ú_rfc3339_to_datetimerj   ó   s+   € ô ×Ñ×%Ñ% f¬oÓ>×FÑFÌcÐFÓRÐRr   c                 óv  — t         j                  | «      }|€t        d| ›dt         j                  ›�«      ‚t        j                  j                  |j                  d«      t        «      }|j                  d«      }|€d}n$dt        |«      z
  }t        |«      d|z  z  }|dz  }|j                  |t        ¬	«      S )
aì  Convert a nanosecond-precision timestamp to a native datetime.

    .. note::

       Python datetimes do not support nanosecond precision;  this function
       therefore truncates such values to microseconds.

    :type dt_str: str
    :param dt_str: The string to convert.

    :rtype: :class:`datetime.datetime`
    :returns: The datetime object created from the string.
    :raises ValueError: If the timestamp does not match the RFC 3339
                        regular expression.
    zTimestamp: z, does not match pattern: Úno_fractionÚnanosr   é	   é
   r@   )rU   r
   )Ú_RFC3339_NANOSÚmatchrb   ÚpatternrH   rY   ÚgroupÚ_RFC3339_NO_FRACTIONr_   rQ   rN   rO   )ri   Ú
with_nanosÚbare_secondsÚfractionrC   Úscalerm   s          r   Ú_rfc3339_nanos_to_datetimery   ÿ   s¼   € ô   ×%Ñ% fÓ-€JØÐÝâ”~×-Ò-ð/ó
ð 	
ô ×$Ñ$×-Ñ-Ø×Ñ˜Ó'Ô)=ó€Lð ×Ñ Ó(€HØÐØ‰à”C˜“MÑ!ˆÜ�H“  U¡Ñ+ˆØ˜$‘ˆØ×Ñ¨F¼3ÐÓ?Ð?r   c                 óŽ   — |s/| j                   �#| j                  d¬«      | j                  «       z
  } | j                  t        «      S )at  Convert a timestamp to a string.

    :type value: :class:`datetime.datetime`
    :param value: The datetime object to be converted to a string.

    :type ignore_zone: bool
    :param ignore_zone: If True, then the timezone (if any) of the datetime
                        object is ignored.

    :rtype: str
    :returns: The string representing the datetime stamp.
    Nr	   )r
   rN   Ú	utcoffsetÚstrftimerh   )rK   Úignore_zones     r   Ú_datetime_to_rfc3339r~   "  s;   € ñ ˜5Ÿ<™<Ð3à—‘ T�Ó*¨U¯_©_Ó->Ñ>ˆà�>‰>œ/Ó*Ð*r   c                 óˆ   — t        | t        «      r| j                  |«      n| }t        |t        «      r|S t	        | ›d�«      ‚)a'  Converts a string value to bytes, if necessary.

    :type value: str / bytes or unicode
    :param value: The string/bytes value to be converted.

    :type encoding: str
    :param 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.

    :rtype: str / bytes
    :returns: The original value converted to bytes (if unicode) or as passed
              in if it started out as bytes.
    :raises TypeError: if the value could not be converted to bytes.
    z  could not be converted to bytes)r2   ÚstrÚencodeÚbytesr5   )rK   ÚencodingÚresults      r   Ú	_to_bytesr…   6  s:   € ô& (2°%¼Ô'=ˆU�\‰\˜(Ô#À5€FÜ�&œ%Ô ØˆäÂÐGÓHÐHr   c                 óˆ   — t        | t        «      r| j                  d«      n| }t        |t        «      r|S t	        | ›d�«      ‚)ac  Converts bytes to a unicode value, if necessary.

    :type value: bytes
    :param value: bytes value to attempt string conversion on.

    :rtype: str
    :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.
    zutf-8z" could not be converted to unicode)r2   r‚   Údecoder€   rb   )rK   r„   s     r   Ú_bytes_to_unicoderˆ   P  s:   € ô '1°¼Ô&>ˆU�\‰\˜'Ô"ÀE€FÜ�&œ#ÔØˆäÂ5ÐJÓKÐKr   c                 ó¨   —  | «       }|j                  |«      s9t        dj                  |j                  j                  | j                  «      «      ‚|S )ay  Converts an Any protobuf to the specified message type

    Args:
        pb_type (type): the type of the message that any_pb stores an instance
            of.
        any_pb (google.protobuf.any_pb2.Any): the object to be converted.

    Returns:
        pb_type: An instance of the pb_type message.

    Raises:
        TypeError: if the message could not be converted.
    zCould not convert {} to {})ÚUnpackr5   rc   r   r+   )Úpb_typeÚany_pbÚmsgs      r   Ú_from_any_pbrŽ   c  sP   € ñ ‹)€CØ�=‰=˜ÔÜØ(×/Ñ/Ø× Ñ ×)Ñ)¨7×+;Ñ+;óó
ð 	
ð €Jr   c                 ól   — t         t        j                  | j                  | j                  dz  ¬«      z   S )a1  Convert a Timestamp protobuf to a datetime object.

    :type timestamp_pb: :class:`google.protobuf.timestamp_pb2.Timestamp`
    :param timestamp_pb: A Google returned timestamp protobuf.

    :rtype: :class:`datetime.datetime`
    :returns: A UTC datetime object converted from a protobuf timestamp.
    ç     @�@©ÚsecondsrF   )rG   rH   rI   r’   rm   )Útimestamp_pbs    r   Ú_pb_timestamp_to_datetimer”   |  s4   € ô ”H×&Ñ&Ø×$Ñ$°L×4FÑ4FÈÑ4Oôñ ð r   c                 ó.   — t        | «      }t        |«      S )a  Convert a Timestamp protobuf to an RFC 3339 string.

    :type timestamp_pb: :class:`google.protobuf.timestamp_pb2.Timestamp`
    :param timestamp_pb: A Google returned timestamp protobuf.

    :rtype: str
    :returns: An RFC 3339 formatted timestamp string.
    )r”   r~   )r“   Ú	timestamps     r   Ú_pb_timestamp_to_rfc3339r—   Š  s   € ô *¨,Ó7€IÜ 	Ó*Ð*r   c                 ón   — t        | «      }t        |d«      \  }}|dz  }t        j                  ||¬«      S )a
  Convert a datetime object to a Timestamp protobuf.

    :type when: :class:`datetime.datetime`
    :param when: the datetime to convert

    :rtype: :class:`google.protobuf.timestamp_pb2.Timestamp`
    :returns: A timestamp protobuf corresponding to the object.
    i@B r@   )r’   rm   )rA   Údivmodr   Ú	Timestamp)rB   Úms_valuer’   rC   rm   s        r   Ú_datetime_to_pb_timestamprœ   —  s:   € ô +¨4Ó0€HÜ˜X uÓ-�O€GˆVØ�U‰N€EÜ×"Ñ"¨7¸%Ô@Ð@r   c                 óP   — t        j                  «       }|j                  | «       |S )a³  Convert a Python timedelta object to a duration protobuf.

    .. note::

        The Python timedelta has a granularity of microseconds while
        the protobuf duration type has a duration of nanoseconds.

    :type timedelta_val: :class:`datetime.timedelta`
    :param timedelta_val: A timedelta object.

    :rtype: :class:`google.protobuf.duration_pb2.Duration`
    :returns: A duration object equivalent to the time delta.
    )r   ÚDurationÚFromTimedelta)Útimedelta_valÚduration_pbs     r   Ú_timedelta_to_duration_pbr¢   ¦  s&   € ô ×'Ñ'Ó)€KØ×Ñ˜mÔ,ØÐr   c                 ó^   — t        j                  | j                  | j                  dz  ¬«      S )a§  Convert a duration protobuf to a Python timedelta object.

    .. note::

        The Python timedelta has a granularity of microseconds while
        the protobuf duration type has a duration of nanoseconds.

    :type duration_pb: :class:`google.protobuf.duration_pb2.Duration`
    :param duration_pb: A protobuf duration object.

    :rtype: :class:`datetime.timedelta`
    :returns: The converted timedelta object.
    r�   r‘   )rH   rI   r’   rm   )r¡   s    r   Ú_duration_pb_to_timedeltar¤   ¹  s-   € ô ×ÑØ×#Ñ#°;×3DÑ3DÀvÑ3Môð r   c                 ó   — t        |t        «      rt        j                  |«      }|j	                  | «      }|st        d| ›d|j                  ›d�«      ‚|�(|j                  d«      }||k7  rt        d|›d|›d�«      ‚|j                  d«      S )	a  Validate a URI path and get the leaf object's name.

    :type path: str
    :param path: URI path containing the name.

    :type project: str
    :param project: (Optional) The project associated with the request. It is
                    included for validation purposes.  If passed as None,
                    disables validation.

    :type template: str
    :param template: Template regex describing the expected form of the path.
                     The regex must have two named groups, 'project' and
                     'name'.

    :rtype: str
    :returns: Name parsed from ``path``.
    :raises ValueError: if the ``path`` is ill-formed or if the project from
                        the ``path`` does not agree with the ``project``
                        passed in.
    zpath "z"" did not match expected pattern "ú"r   zProject from client (z*) should agree with project from resource(z).Úname)r2   r€   ÚreÚcompilerq   rb   rr   rs   )Úpathr   Útemplaterq   Úfound_projects        r   Ú_name_from_project_pathr­   Ì  s�   € ô, �(œCÔ Ü—:‘:˜hÓ'ˆà�N‰N˜4Ó €EáÝÚ?CÀX×EUÓEUÐVó
ð 	
ð ÐØŸ™ IÓ.ˆØ˜GÒ#Ýâ07ºðHóð ð
 �;‰;�vÓÐr   c                 ó&  — d|t         j                  j                  fz  }t        j                  j
                  j                  j                  «       }d|f}|f|z   }t        j                  j
                  j                  j                  | |||¬«      S )a•  Makes a secure channel for an RPC service.

    Uses / depends on gRPC.

    :type credentials: :class:`google.auth.credentials.Credentials`
    :param credentials: The OAuth2 Credentials to use for creating
                        access tokens.

    :type user_agent: str
    :param user_agent: The user agent to be used with API requests.

    :type host: str
    :param host: The host for the service.

    :type extra_options: tuple
    :param extra_options: (Optional) Extra gRPC options used when creating the
                          channel.

    :rtype: :class:`grpc._channel.Channel`
    :returns: gRPC secure channel with credentials attached.
    ú%s:%dzgrpc.primary_user_agent)Úoptions)
ÚhttpÚclientÚ
HTTPS_PORTr:   r;   Ú	transportÚrequestsÚRequestÚgrpcÚsecure_authorized_channel)ÚcredentialsÚ
user_agentÚhostÚextra_optionsÚtargetÚhttp_requestÚuser_agent_optionr°   s           r   Úmake_secure_channelrÀ   ÷  s…   € ð, ˜œdŸk™k×4Ñ4Ð5Ñ5€FÜ—;‘;×(Ñ(×1Ñ1×9Ñ9Ó;€Là2°JÐ?ÐØ Ð" ]Ñ2€GÜ�;‰;× Ñ ×%Ñ%×?Ñ?Ø�\ 6°7ð @ó ð r   c                 ó0   — t        | |||¬«      } ||«      S )aý  Makes a secure stub for an RPC service.

    Uses / depends on gRPC.

    :type credentials: :class:`google.auth.credentials.Credentials`
    :param credentials: The OAuth2 Credentials to use for creating
                        access tokens.

    :type user_agent: str
    :param user_agent: The user agent to be used with API requests.

    :type stub_class: type
    :param stub_class: A gRPC stub type for a given service.

    :type host: str
    :param host: The host for the service.

    :type extra_options: tuple
    :param extra_options: (Optional) Extra gRPC options passed when creating
                          the channel.

    :rtype: object, instance of ``stub_class``
    :returns: The stub object used to make gRPC requests to a given API.
    )r¼   )rÀ   )r¹   rº   Ú
stub_classr»   r¼   Úchannels         r   Úmake_secure_stubrÄ     s$   € ô2 "Ø�Z °]ô€Gñ �gÓÐr   c                 óT   — |€|}nd||fz  }t        j                  |«      } | |«      S )að  Makes an insecure stub for an RPC service.

    Uses / depends on gRPC.

    :type stub_class: type
    :param stub_class: A gRPC stub type for a given service.

    :type host: str
    :param host: The host for the service. May also include the port
                 if ``port`` is unspecified.

    :type port: int
    :param port: (Optional) The port for the service.

    :rtype: object, instance of ``stub_class``
    :returns: The stub object used to make gRPC requests to a given API.
    r¯   )r·   Úinsecure_channel)rÂ   r»   Úportr½   rÃ   s        r   Úmake_insecure_stubrÈ   6  s9   € ð$ €|Ø‰ð ˜D $˜<Ñ'ˆÜ×#Ñ# FÓ+€GÙ�gÓÐr   r   )T)Úascii)© )Er.   Ú
__future__r   rR   rH   Úhttp.clientr±   Úosr¨   Ú	threadingr   ÚLocalÚtypingr   Úgoogle.authr:   Úgoogle.auth.transport.requestsÚgoogle.protobufr   r   r·   Úgoogle.auth.transport.grpcÚImportErrorÚutcnowÚ_NOWÚtimezoneÚutcrO   rG   rh   rt   ra   r`   r©   ÚVERBOSErp   r€   Ú__annotations__rª   Ú
expanduserr   ÚjoinÚ_GCLOUD_CONFIG_FILEÚ_GCLOUD_CONFIG_SECTIONÚ_GCLOUD_CONFIG_KEYr   r8   r>   rD   rL   rA   rW   r[   rf   rj   ry   r~   r…   rˆ   rŽ   r”   r—   rœ   r¢   r¤   r­   rÀ   rÄ   rÈ   rÊ   r   r   ú<module>rá      s¿  ðòõ
 'ã Û Û Û 	Û 	Ý $Ý ã Û %Ý (Ý )ðÛÛ%ð
 ×Ñ×Ñ€Ø×Ñ×Ñ€Ø	ˆ×	Ñ	˜4  A¨h×.?Ñ.?×.CÑ.CÔ	D€à)€Ø*Ð Ø"Ð Ø"Ð à�—‘ð	ð ‡J�Jó€ð �#�t�)ÑÓ ðØ—‘×#Ñ# CÓ(€Jð —g‘g—l‘l 8Ð-=Ð?OÓPÐ ØÐ ØÐ ô$#�%ô $#òNó0ò"
ò	;òMò"
ò
@ò9ò&	Sò @óF+ó(Iò4Lò&ò2ò
+òAòò&ò&(óVó@ô>øða ò ØƒDðûð> ò Ø‚Jðús#   ¿E  ÃE. Å E+Å*E+Å.E8Å7E8