2121
2222import calendar
2323import datetime
24+ import http .client
2425import os
2526import re
2627from threading import local as Local
2728
28- import six
29- from six .moves import http_client
30-
3129import google .auth
3230import google .auth .transport .requests
3331from google .protobuf import duration_pb2
4139
4240
4341_NOW = datetime .datetime .utcnow # To be replaced by tests.
42+ UTC = datetime .timezone .utc # Singleton instance to be used throughout.
43+ _EPOCH = datetime .datetime (1970 , 1 , 1 , tzinfo = datetime .timezone .utc )
44+
4445_RFC3339_MICROS = "%Y-%m-%dT%H:%M:%S.%fZ"
4546_RFC3339_NO_FRACTION = "%Y-%m-%dT%H:%M:%S"
4647_TIMEONLY_W_MICROS = "%H:%M:%S.%f"
@@ -111,41 +112,6 @@ def top(self):
111112 return self ._stack [- 1 ]
112113
113114
114- class _UTC (datetime .tzinfo ):
115- """Basic UTC implementation.
116-
117- Implementing a small surface area to avoid depending on ``pytz``.
118- """
119-
120- _dst = datetime .timedelta (0 )
121- _tzname = "UTC"
122- _utcoffset = _dst
123-
124- def dst (self , dt ): # pylint: disable=unused-argument
125- """Daylight savings time offset."""
126- return self ._dst
127-
128- def fromutc (self , dt ):
129- """Convert a timestamp from (naive) UTC to this timezone."""
130- if dt .tzinfo is None :
131- return dt .replace (tzinfo = self )
132- return super (_UTC , self ).fromutc (dt )
133-
134- def tzname (self , dt ): # pylint: disable=unused-argument
135- """Get the name of this timezone."""
136- return self ._tzname
137-
138- def utcoffset (self , dt ): # pylint: disable=unused-argument
139- """UTC offset of this timezone."""
140- return self ._utcoffset
141-
142- def __repr__ (self ):
143- return "<%s>" % (self ._tzname ,)
144-
145- def __str__ (self ):
146- return self ._tzname
147-
148-
149115def _ensure_tuple_or_list (arg_name , tuple_or_list ):
150116 """Ensures an input is a tuple or list.
151117
@@ -344,9 +310,6 @@ def _datetime_to_rfc3339(value, ignore_zone=True):
344310def _to_bytes (value , encoding = "ascii" ):
345311 """Converts a string value to bytes, if necessary.
346312
347- Unfortunately, ``six.b`` is insufficient for this task since in
348- Python2 it does not modify ``unicode`` objects.
349-
350313 :type value: str / bytes or unicode
351314 :param value: The string/bytes value to be converted.
352315
@@ -363,8 +326,8 @@ def _to_bytes(value, encoding="ascii"):
363326 in if it started out as bytes.
364327 :raises TypeError: if the value could not be converted to bytes.
365328 """
366- result = value .encode (encoding ) if isinstance (value , six . text_type ) else value
367- if isinstance (result , six . binary_type ):
329+ result = value .encode (encoding ) if isinstance (value , str ) else value
330+ if isinstance (result , bytes ):
368331 return result
369332 else :
370333 raise TypeError ("%r could not be converted to bytes" % (value ,))
@@ -382,8 +345,8 @@ def _bytes_to_unicode(value):
382345
383346 :raises ValueError: if the value could not be converted to unicode.
384347 """
385- result = value .decode ("utf-8" ) if isinstance (value , six . binary_type ) else value
386- if isinstance (result , six . text_type ):
348+ result = value .decode ("utf-8" ) if isinstance (value , bytes ) else value
349+ if isinstance (result , str ):
387350 return result
388351 else :
389352 raise ValueError ("%r could not be converted to unicode" % (value ,))
@@ -559,7 +522,7 @@ def make_secure_channel(credentials, user_agent, host, extra_options=()):
559522 :rtype: :class:`grpc._channel.Channel`
560523 :returns: gRPC secure channel with credentials attached.
561524 """
562- target = "%s:%d" % (host , http_client .HTTPS_PORT )
525+ target = "%s:%d" % (host , http . client .HTTPS_PORT )
563526 http_request = google .auth .transport .requests .Request ()
564527
565528 user_agent_option = ("grpc.primary_user_agent" , user_agent )
@@ -621,16 +584,7 @@ def make_insecure_stub(stub_class, host, port=None):
621584 if port is None :
622585 target = host
623586 else :
624- # NOTE: This assumes port != http_client .HTTPS_PORT:
587+ # NOTE: This assumes port != http.client .HTTPS_PORT:
625588 target = "%s:%d" % (host , port )
626589 channel = grpc .insecure_channel (target )
627590 return stub_class (channel )
628-
629-
630- try :
631- from pytz import UTC # pylint: disable=unused-import,wrong-import-order
632- except ImportError : # pragma: NO COVER
633- UTC = _UTC () # Singleton instance to be used throughout.
634-
635- # Need to define _EPOCH at the end of module since it relies on UTC.
636- _EPOCH = datetime .datetime .utcfromtimestamp (0 ).replace (tzinfo = UTC )
0 commit comments