def is_ec2_timestamp_expired(request, expires=None):
 timestamp = request.get('Timestamp')
 expiry_time = request.get('Expires')
 def parse_strtime(strtime):
  if _ms_time_regex.match(strtime):
   time_format = '%Y-%m-%dT%H:%M:%S.%fZ'
  else:
   time_format = '%Y-%m-%dT%H:%M:%SZ'
  return timeutils.parse_strtime(strtime, time_format)
 try:
  if (timestamp and expiry_time):
   msg = _('Request must include either Timestamp or Expires, but cannot contain both')
   LOG.error(msg)
   raise exception.InvalidRequest(msg)
  elif expiry_time:
   query_time = parse_strtime(expiry_time)
   return timeutils.is_older_than(query_time, (-1))
  elif timestamp:
   query_time = parse_strtime(timestamp)
   if (query_time and expires):
    return (timeutils.is_older_than(query_time, expires) or timeutils.is_newer_than(query_time, expires))
  return False
 except ValueError:
  LOG.info(_LI('Timestamp is invalid.'))
  return True

def is_ec2_timestamp_expired ( request , expires = None ) : timestamp = request . get ( 'Timestamp' ) expiry_time = request . get ( 'Expires' ) def parse_strtime ( strtime ) : if _ms_time_regex . match ( strtime ) : time_format = '%Y-%m-%dT%H:%M:%S.%fZ' else : time_format = '%Y-%m-%dT%H:%M:%SZ' return timeutils . parse_strtime ( strtime , time_format ) try : if ( timestamp and expiry_time ) : msg = _ ( 'Request must include either Timestamp or Expires, but cannot contain both' ) LOG . error ( msg ) raise exception . InvalidRequest ( msg ) elif expiry_time : query_time = parse_strtime ( expiry_time ) return timeutils . is_older_than ( query_time , ( - 1 ) ) elif timestamp : query_time = parse_strtime ( timestamp ) if ( query_time and expires ) : return ( timeutils . is_older_than ( query_time , expires ) or timeutils . is_newer_than ( query_time , expires ) ) return False except ValueError : LOG . info ( _LI ( 'Timestamp is invalid.' ) ) return True
checks the timestamp or expiry time included in an ec2 request and returns true if the request is expired .