def _rfc3339_nanos_to_datetime(dt_str):
 with_nanos = _RFC3339_NANOS.match(dt_str)
 if (with_nanos is None):
  raise ValueError(('Timestamp: %r, does not match pattern: %r' % (dt_str, _RFC3339_NANOS.pattern)))
 bare_seconds = datetime.datetime.strptime(with_nanos.group('no_fraction'), _RFC3339_NO_FRACTION)
 fraction = with_nanos.group('nanos')
 if (fraction is None):
  micros = 0
 else:
  scale = (9 - len(fraction))
  nanos = (int(fraction) * (10 ** scale))
  micros = (nanos // 1000)
 return bare_seconds.replace(microsecond=micros, tzinfo=UTC)

def _rfc3339_nanos_to_datetime ( dt_str ) : with_nanos = _RFC3339_NANOS . match ( dt_str ) if ( with_nanos is None ) : raise ValueError ( ( 'Timestamp: %r, does not match pattern: %r' % ( dt_str , _RFC3339_NANOS . pattern ) ) ) bare_seconds = datetime . datetime . strptime ( with_nanos . group ( 'no_fraction' ) , _RFC3339_NO_FRACTION ) fraction = with_nanos . group ( 'nanos' ) if ( fraction is None ) : micros = 0 else : scale = ( 9 - len ( fraction ) ) nanos = ( int ( fraction ) * ( 10 ** scale ) ) micros = ( nanos // 1000 ) return bare_seconds . replace ( microsecond = micros , tzinfo = UTC )
convert a nanosecond-precision timestamp to a native datetime .