return rows[-lines:]
-def FormatTimestampWithTZ(secs):
- """Formats a Unix timestamp with the local timezone.
-
- @type secs: number
- @param secs: Seconds since the Epoch (1970-01-01 00:00:00 UTC)
-
- """
- return time.strftime("%F %T %Z", time.localtime(secs))
-
-
def _ParseAsn1Generalizedtime(value):
"""Parses an ASN1 GENERALIZEDTIME timestamp as used by pyOpenSSL.
@type value: string
@param value: ASN1 GENERALIZEDTIME timestamp
+ @return: Seconds since the Epoch (1970-01-01 00:00:00 UTC)
"""
m = _ASN1_TIME_REGEX.match(value)
if not_before is not None and not_after is not None:
msg += (" (valid from %s to %s)" %
- (FormatTimestampWithTZ(not_before),
- FormatTimestampWithTZ(not_after)))
+ (FormatTime(not_before), FormatTime(not_after)))
elif not_before is not None:
- msg += " (valid from %s)" % FormatTimestampWithTZ(not_before)
+ msg += " (valid from %s)" % FormatTime(not_before)
elif not_after is not None:
- msg += " (valid until %s)" % FormatTimestampWithTZ(not_after)
+ msg += " (valid until %s)" % FormatTime(not_after)
return (CERT_ERROR, msg)
elif not_before is not None and not_before > now:
return (CERT_WARNING,
"Certificate not yet valid (valid from %s)" %
- FormatTimestampWithTZ(not_before))
+ FormatTime(not_before))
elif not_after is not None:
remaining_days = int((not_after - now) / (24 * 3600))
FormatTime(int(time.time()))
-class TestFormatTimestampWithTZ(unittest.TestCase):
- @staticmethod
- def _TestInProcess(tz, timestamp, expected):
- os.environ["TZ"] = tz
- time.tzset()
- return utils.FormatTimestampWithTZ(timestamp) == expected
-
- def _Test(self, *args):
- # Need to use separate process as we want to change TZ
- self.assert_(utils.RunInSeparateProcess(self._TestInProcess, *args))
-
- def test(self):
- self._Test("UTC", 0, "1970-01-01 00:00:00 UTC")
- self._Test("America/Sao_Paulo", 1292606926, "2010-12-17 15:28:46 BRST")
- self._Test("Europe/London", 1292606926, "2010-12-17 17:28:46 GMT")
- self._Test("Europe/Zurich", 1292606926, "2010-12-17 18:28:46 CET")
- self._Test("Australia/Sydney", 1292606926, "2010-12-18 04:28:46 EST")
-
-
class RunInSeparateProcess(unittest.TestCase):
def test(self):
for exp in [True, False]: