本文整理汇总了Python中epsilon.extime.Time类的典型用法代码示例。如果您正苦于以下问题:Python Time类的具体用法?Python Time怎么用?Python Time使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Time类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: guessSentTime
def guessSentTime(self, default=None):
"""
Try to determine the time this message claims to have been sent by
analyzing various headers.
@return: a L{Time} instance, or C{None}, if we don't have a guess.
"""
try:
sentHeader = self.getHeader(u'date')
except equotient.NoSuchHeader:
sentHeader = None
else:
try:
return Time.fromRFC2822(sentHeader)
except ValueError:
pass
for received in list(self.getHeaders(u'received'))[::-1]:
lines = received.value.splitlines()
if lines:
lastLine = lines[-1]
parts = lastLine.split('; ')
if parts:
date = parts[-1]
try:
when = rfc822.parsedate(date)
if when is None:
continue
except ValueError:
pass
else:
return Time.fromStructTime(when)
return default
示例2: _testSchedule
def _testSchedule(self, scheduler):
t1 = TestEvent(store=scheduler.store)
scheduler.schedule(t1, Time.fromPOSIXTimestamp(0))
self.failIf(self.calls,
"Should not have had any calls: %r" % (self.calls,))
self.assertIdentical(
scheduler._getNextEvent(Time.fromPOSIXTimestamp(1)).runnable, t1)
示例3: testScheduleWithEarlierTimedEvents
def testScheduleWithEarlierTimedEvents(self):
"""
Like L{testSchedule}, but use a SubScheduler which has pre-existing
TimedEvents which are before the new runnable's scheduled time.
"""
now = self.clock.seconds()
when = Time.fromPOSIXTimestamp(now + 15)
null = NullRunnable(store=self.substore)
self.subscheduler.schedule(null, when)
runnable = self._scheduleRunner(now, 10)
self.clock.advance(11)
self.assertEqual(
list(self.subscheduler.scheduledTimes(runnable)),
[Time.fromPOSIXTimestamp(now + 20)])
self.assertEqual(
list(self.subscheduler.scheduledTimes(null)),
[Time.fromPOSIXTimestamp(now + 15)])
hook = self.store.findUnique(
_SubSchedulerParentHook,
_SubSchedulerParentHook.subStore == self.substoreItem)
self.assertEqual(
list(self.scheduler.scheduledTimes(hook)),
[Time.fromPOSIXTimestamp(now + 15)])
示例4: setUp
def setUp(self):
self.clock = Clock()
self.dbdir = filepath.FilePath(self.mktemp())
self.store = Store(self.dbdir)
self.substoreItem = SubStore.createNew(self.store, ['sub'])
self.substore = self.substoreItem.open()
self.scheduler = IScheduler(self.store)
self.subscheduler = IScheduler(self.substore)
self.scheduler.callLater = self.clock.callLater
self.scheduler.now = lambda: Time.fromPOSIXTimestamp(self.clock.seconds())
self.subscheduler.now = lambda: Time.fromPOSIXTimestamp(self.clock.seconds())
IService(self.store).startService()
示例5: _parse_get_bucket
def _parse_get_bucket(self, xml_bytes):
root = XML(xml_bytes)
name = root.findtext("Name")
prefix = root.findtext("Prefix")
marker = root.findtext("Marker")
max_keys = root.findtext("MaxKeys")
is_truncated = root.findtext("IsTruncated")
contents = []
for content_data in root.findall("Contents"):
key = content_data.findtext("Key")
date_text = content_data.findtext("LastModified")
modification_date = Time.fromISO8601TimeAndDate(
date_text).asDatetime()
etag = content_data.findtext("ETag")
size = content_data.findtext("Size")
storage_class = content_data.findtext("StorageClass")
owner_id = content_data.findtext("Owner/ID")
owner_display_name = content_data.findtext("Owner/DisplayName")
owner = ItemOwner(owner_id, owner_display_name)
content_item = BucketItem(key, modification_date, etag, size,
storage_class, owner)
contents.append(content_item)
common_prefixes = []
for prefix_data in root.findall("CommonPrefixes"):
common_prefixes.append(prefix_data.text)
return BucketListing(name, prefix, marker, max_keys, is_truncated,
contents, common_prefixes)
示例6: _setUpMsg
def _setUpMsg(self):
"""
Install an innocuous incoming message in a newly-created store
@rtype: L{xquotient.exmess.Message}
"""
s = self._setUpStore()
m = Message.createIncoming(s, _Part(store=s), u'test://test')
m.subject = u'the subject'
m.sender = u'[email protected]'
m.senderDisplay = u'Sender'
m.recipient = u'[email protected]'
m.sentWhen = Time.fromPOSIXTimestamp(0)
m.receivedWhen = Time.fromPOSIXTimestamp(1)
m.classifyClean()
return m
示例7: peerRequestedAppointment
def peerRequestedAppointment(self, whom, when):
app = Appointment(
store=self.store, when=Time.fromISO8601TimeAndDate(when),
withWhomUsername=whom.localpart, withWhomDomain=whom.domain,
withWhomShareID=whom.shareID, remoteID=whom.shareID)
role = getPrimaryRole(self.store, u"%[email protected]%s" % (whom.localpart, whom.domain), True)
appointmentID = role.shareItem(app, interfaces=[IMessageReceiver]).shareID
return {'appointmentID': appointmentID}
示例8: test_getValue
def test_getValue(self):
"""
L{methanal.view.DateInput.getValue} retrieves an empty string in the
C{None} case and a string representing the C{Time} specified by
parameter's value, in the case where a value exists.
"""
control = self.createControl(dict(timezone=FixedOffset(0, 0)))
param = control.parent.param
param.value = None
self.assertEquals(control.getValue(), u"")
param.value = Time.fromDatetime(datetime(2007, 1, 1))
self.assertTrue(isinstance(control.getValue(), unicode))
self.assertEquals(control.getValue(), u"2007-01-01")
param.value = Time.fromDatetime(datetime(542, 12, 18))
self.assertEquals(control.getValue(), u"0542-12-18")
示例9: testSchedule
def testSchedule(self):
"""
Test the schedule method, as invoked from the run method of an item
being run by the subscheduler.
"""
now = self.clock.seconds()
runnable = self._scheduleRunner(now, 10)
self.clock.advance(11)
self.assertEqual(
list(self.subscheduler.scheduledTimes(runnable)),
[Time.fromPOSIXTimestamp(now + 20)])
hook = self.store.findUnique(
_SubSchedulerParentHook,
_SubSchedulerParentHook.subStore == self.substoreItem)
self.assertEqual(
list(self.scheduler.scheduledTimes(hook)),
[Time.fromPOSIXTimestamp(now + 20)])
示例10: test_now
def test_now(self):
"""
The user store's L{IScheduler} powerup's C{now} method returns whatever
the site store's L{IScheduler} powerup's C{now} method returns.
"""
# I don't want the stubbed now method.
del self.scheduler.now
self.clock.advance(17)
self.assertEquals(
self.scheduler.now(),
Time.fromPOSIXTimestamp(self.clock.seconds()))
示例11: _parse_list_buckets
def _parse_list_buckets(self, xml_bytes):
"""
Parse XML bucket list response.
"""
root = XML(xml_bytes)
buckets = []
for bucket_data in root.find("Buckets"):
name = bucket_data.findtext("Name")
date_text = bucket_data.findtext("CreationDate")
date_time = Time.fromISO8601TimeAndDate(date_text).asDatetime()
bucket = Bucket(name, date_time)
buckets.append(bucket)
return buckets
示例12: test_attributes
def test_attributes(self):
"""
Verify all the attributes directly on the Message class are preserved
by the upgrade function.
"""
for i, msg in enumerate(self.messageList):
# The code at the revision which this stub requires randomly
# mangles the sentWhen of the 3rd and 4th message (because they're
# drafts), so we can't reasonably test them, except to make sure
# they're not none.
if i == 3 or i == 4:
self.assertNotEqual(msg.sentWhen, None)
else:
self.assertEqual(
msg.sentWhen,
Time.fromRFC2822("Thu, 26 Apr 2001 22:01:%d GMT" % (i,)))
# Received when is set to the time the stub is generated! So we
# can only test for non-Noneness.
self.assertNotEqual(msg.receivedWhen, None)
self.assertEqual(msg.sender, u"[email protected]")
self.assertEqual(msg.senderDisplay, u"[email protected]")
self.assertEqual(msg.recipient, u"[email protected]")
self.assertEqual(msg.subject, u"message number %d" % (i,))
self.assertEqual(msg.attachments, i * 2)
self.assertEqual(msg.read, i == 2)
self.assertEqual(msg.everDeferred, i == 1 or i == 2)
if i == 0 or i == 1 or i == 2 or i == 5:
_spam = False
elif i == 3 or i == 4:
_spam = None
elif i == 6 or i == 7:
_spam = True
self.assertEqual(msg._spam, _spam)
self.assertEqual(msg.shouldBeClassified, not (i == 3 or i == 4 or i == 7))
self.assertEqual(msg.impl.getHeader(u"subject"), msg.subject)
if i == 7:
frozenWith = SPAM_STATUS
elif i == 5 or i == 6:
frozenWith = TRASH_STATUS
else:
frozenWith = None
self.assertEqual(msg._frozenWith, frozenWith)
示例13: test_blurbTimestampColumn
def test_blurbTimestampColumn(self):
"""
Verify the L{xmantissa.ixmantissa.IColumn} implementation of
L{hyperbola_view._BlurbTimestampColumn}.
"""
col = hyperbola_view._BlurbTimestampColumn()
self.assertEqual(col.attributeID, 'dateCreated')
self.assertEqual(col.getType(), 'timestamp')
self.blogPostItem.dateCreated = Time.fromPOSIXTimestamp(345)
value = col.extractValue(None, self.blogPostItem)
self.assertEqual(value, 345)
self.assertIdentical(col.sortAttribute(), hyperblurb.Blurb.dateCreated)
comparable = col.toComparableValue(345)
self.assertEqual(comparable, self.blogPostItem.dateCreated)
示例14: setMetadata
def setMetadata(self, meta):
"""
Set the topic in the database
"""
self.channelItem.topic = unicode(meta['topic'])
self.channelItem.topicAuthor = unicode(meta['topic_author'])
self.channelItem.topicTime = Time.fromPOSIXTimestamp(meta['topic_date'])
sets = []
for p in self.users.itervalues():
d = defer.maybeDeferred(p.groupMetaUpdate, self, meta)
d.addErrback(self._ebUserCall, p=p)
sets.append(d)
defer.DeferredList(sets).addCallback(self._cbUserCall)
return defer.succeed(None)
示例15: testMultipleEventsPerTick
def testMultipleEventsPerTick(self):
"""
Test running several runnables in a single tick of the subscheduler.
"""
now = self.clock.seconds()
runnables = [
self._scheduleRunner(now, 10),
self._scheduleRunner(now, 11),
self._scheduleRunner(now, 12)]
self.clock.advance(13)
for n, runnable in enumerate(runnables):
self.assertEqual(
list(self.subscheduler.scheduledTimes(runnable)),
[Time.fromPOSIXTimestamp(now + n + 20)])
hook = self.store.findUnique(
_SubSchedulerParentHook,
_SubSchedulerParentHook.subStore == self.substoreItem)
self.assertEqual(
list(self.scheduler.scheduledTimes(hook)),
[Time.fromPOSIXTimestamp(now + 20)])