本文整理汇总了Python中sipsimple.util.ISOTimestamp.now方法的典型用法代码示例。如果您正苦于以下问题:Python ISOTimestamp.now方法的具体用法?Python ISOTimestamp.now怎么用?Python ISOTimestamp.now使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sipsimple.util.ISOTimestamp
的用法示例。
在下文中一共展示了ISOTimestamp.now方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _message_queue_handler
# 需要导入模块: from sipsimple.util import ISOTimestamp [as 别名]
# 或者: from sipsimple.util.ISOTimestamp import now [as 别名]
def _message_queue_handler(self):
notification_center = NotificationCenter()
try:
while True:
message = self.message_queue.wait()
if self.msrp_session is None:
if message.notify_progress:
data = NotificationData(message_id=message.id, message=None, code=0, reason='Stream ended')
notification_center.post_notification('ChatStreamDidNotDeliverMessage', sender=self, data=data)
break
try:
if isinstance(message.content, unicode):
message.content = message.content.encode('utf8')
charset = 'utf8'
else:
charset = None
if not isinstance(message, QueuedOTRInternalMessage):
try:
message.content = self.encryption.otr_session.handle_output(message.content, message.content_type)
except OTRError, e:
raise ChatStreamError(str(e))
message.sender = message.sender or self.local_identity
message.recipients = message.recipients or [self.remote_identity]
# check if we MUST use CPIM
need_cpim = (message.sender != self.local_identity or message.recipients != [self.remote_identity] or
message.courtesy_recipients or message.subject or message.timestamp or message.required or message.additional_headers)
if need_cpim or not contains_mime_type(self.remote_accept_types, message.content_type):
if not contains_mime_type(self.remote_accept_wrapped_types, message.content_type):
raise ChatStreamError('Unsupported content_type for outgoing message: %r' % message.content_type)
if not self.cpim_enabled:
raise ChatStreamError('Additional message meta-data cannot be sent, because the CPIM wrapper is not used')
if not self.private_messages_allowed and message.recipients != [self.remote_identity]:
raise ChatStreamError('The remote end does not support private messages')
if message.timestamp is None:
message.timestamp = ISOTimestamp.now()
payload = CPIMPayload(charset=charset, **{name: getattr(message, name) for name in Message.__slots__})
elif self.prefer_cpim and self.cpim_enabled and contains_mime_type(self.remote_accept_wrapped_types, message.content_type):
if message.timestamp is None:
message.timestamp = ISOTimestamp.now()
payload = CPIMPayload(charset=charset, **{name: getattr(message, name) for name in Message.__slots__})
else:
payload = SimplePayload(message.content, message.content_type, charset)
except ChatStreamError, e:
if message.notify_progress:
data = NotificationData(message_id=message.id, message=None, code=0, reason=e.args[0])
notification_center.post_notification('ChatStreamDidNotDeliverMessage', sender=self, data=data)
continue
示例2: offline_state
# 需要导入模块: from sipsimple.util import ISOTimestamp [as 别名]
# 或者: from sipsimple.util.ISOTimestamp import now [as 别名]
def offline_state(self):
if self.account is BonjourAccount():
return None
blink_settings = BlinkSettings()
account_id = hashlib.md5(self.account.id).hexdigest()
timestamp = ISOTimestamp.now()
doc = pidf.PIDF(str(self.account.uri))
person = pidf.Person('PID-%s' % account_id)
person.timestamp = timestamp
person.activities = rpid.Activities()
person.activities.add('offline')
doc.add(person)
service = pidf.Service('SID-%s' % account_id)
service.status = 'closed'
service.status.extended = 'offline'
service.contact = str(self.account.uri)
service.timestamp = timestamp
service.capabilities = caps.ServiceCapabilities()
service.display_name = self.account.display_name or None
service.icon = "%s#blink-icon%s" % (self.account.xcap.icon.url, self.account.xcap.icon.etag) if self.account.xcap.icon is not None else None
if blink_settings.presence.offline_note:
service.notes.add(blink_settings.presence.offline_note)
doc.add(service)
return doc
示例3: offline_state
# 需要导入模块: from sipsimple.util import ISOTimestamp [as 别名]
# 或者: from sipsimple.util.ISOTimestamp import now [as 别名]
def offline_state(self):
blink_settings = BlinkSettings()
if self.account is BonjourAccount() or not blink_settings.presence.offline_note:
return None
account_id = hashlib.md5(self.account.id).hexdigest()
timestamp = ISOTimestamp.now()
doc = pidf.PIDF(str(self.account.uri))
person = pidf.Person('PID-%s' % account_id)
person.timestamp = timestamp
person.activities = rpid.Activities()
person.activities.add('offline')
doc.add(person)
service = pidf.Service('SID-%s' % account_id)
service.status = 'closed'
service.status.extended = 'offline'
service.contact = str(self.account.uri)
service.timestamp = timestamp
service.capabilities = caps.ServiceCapabilities()
service.notes.add(blink_settings.presence.offline_note)
doc.add(service)
return doc
示例4: _janus_send_request
# 需要导入模块: from sipsimple.util import ISOTimestamp [as 别名]
# 或者: from sipsimple.util.ISOTimestamp import now [as 别名]
def _janus_send_request(self, req):
data = json.dumps(req.as_dict())
if JanusConfig.trace_janus:
self.factory.janus_logger.msg("OUT", ISOTimestamp.now(), data)
self.sendMessage(data)
d = defer.Deferred()
self._janus_pending_transactions[req.transaction_id] = (req, d)
return d
示例5: inject
# 需要导入模块: from sipsimple.util import ISOTimestamp [as 别名]
# 或者: from sipsimple.util.ISOTimestamp import now [as 别名]
def inject(self, msg, appdata=None):
msg = unicode(msg)
if appdata is not None:
stream = appdata.get('stream', None)
if stream is not None:
try:
stream.send_message(msg, timestamp=ISOTimestamp.now())
except ChatStreamError, e:
BlinkLogger().log_error(u"Error sending OTR chat message: %s" % e)
示例6: updateIdleTimer_
# 需要导入模块: from sipsimple.util import ISOTimestamp [as 别名]
# 或者: from sipsimple.util.ISOTimestamp import now [as 别名]
def updateIdleTimer_(self, timer):
must_publish = False
hostname = socket.gethostname().split(".")[0]
if hostname != self.hostname:
must_publish = True
self.hostname = hostname
last_time_offset = int(pidf.TimeOffset())
if last_time_offset != self.last_time_offset:
must_publish = True
self.last_time_offset = last_time_offset
# secret sausage after taking the red pill = indigestion
last_idle_counter = CGEventSourceSecondsSinceLastEventType(0, int(4294967295))
self.previous_idle_counter = last_idle_counter
if self.previous_idle_counter > last_idle_counter:
self.last_input = ISOTimestamp.now()
selected_item = self.owner.presenceActivityPopUp.selectedItem()
if selected_item is None:
return
activity_object = selected_item.representedObject()
if activity_object is None:
return
if activity_object['title'] not in ('Available', 'Away'):
if must_publish:
self.publish()
return
settings = SIPSimpleSettings()
if last_idle_counter > settings.gui.idle_threshold:
if not self.idle_mode:
self.user_input = {'state': 'idle', 'last_input': self.last_input}
if activity_object['title'] != "Away":
i = self.owner.presenceActivityPopUp.indexOfItemWithTitle_('Away')
self.owner.presenceActivityPopUp.selectItemAtIndex_(i)
self.presenceStateBeforeIdle = activity_object
self.presenceStateBeforeIdle['note'] = unicode(self.owner.presenceNoteText.stringValue())
self.idle_mode = True
must_publish = True
else:
if self.idle_mode:
self.user_input = {'state': 'active', 'last_input': None}
if activity_object['title'] == "Away":
if self.presenceStateBeforeIdle:
i = self.owner.presenceActivityPopUp.indexOfItemWithRepresentedObject_(self.presenceStateBeforeIdle)
self.owner.presenceActivityPopUp.selectItemAtIndex_(i)
self.owner.presenceNoteText.setStringValue_(self.presenceStateBeforeIdle['note'])
self.presenceStateBeforeIdle = None
self.idle_mode = False
must_publish = True
if must_publish:
self.publish()
示例7: onMessage
# 需要导入模块: from sipsimple.util import ISOTimestamp [as 别名]
# 或者: from sipsimple.util.ISOTimestamp import now [as 别名]
def onMessage(self, payload, isBinary):
if isBinary:
log.warn('Unexpected binary payload received')
return
if JanusConfig.trace_janus:
self.factory.janus_logger.msg("IN", ISOTimestamp.now(), payload)
try:
data = json.loads(payload)
except Exception, e:
log.warn('Error decoding payload: %s' % e)
return
示例8: onMessage
# 需要导入模块: from sipsimple.util import ISOTimestamp [as 别名]
# 或者: from sipsimple.util.ISOTimestamp import now [as 别名]
def onMessage(self, payload, is_binary):
if is_binary:
log.warn('Received invalid binary message')
return
if GeneralConfig.trace_websocket:
self.factory.ws_logger.msg("IN", ISOTimestamp.now(), payload)
try:
data = json.loads(payload)
except Exception, e:
log.warn('Error parsing WebSocket payload: %s' % e)
return
示例9: _handle_SEND
# 需要导入模块: from sipsimple.util import ISOTimestamp [as 别名]
# 或者: from sipsimple.util.ISOTimestamp import now [as 别名]
def _handle_SEND(self, chunk):
if chunk.size == 0: # keep-alive
self.msrp_session.send_report(chunk, 200, 'OK')
return
content_type = chunk.content_type.lower()
if not contains_mime_type(self.accept_types, content_type):
self.msrp_session.send_report(chunk, 413, 'Unwanted Message')
return
if chunk.contflag == '#':
self.incoming_queue.pop(chunk.message_id, None)
self.msrp_session.send_report(chunk, 200, 'OK')
return
elif chunk.contflag == '+':
self.incoming_queue[chunk.message_id].append(chunk.data)
self.msrp_session.send_report(chunk, 200, 'OK')
return
else:
data = ''.join(self.incoming_queue.pop(chunk.message_id, [])) + chunk.data
if content_type == 'message/cpim':
try:
payload = CPIMPayload.decode(data)
except CPIMParserError:
self.msrp_session.send_report(chunk, 400, 'CPIM Parser Error')
return
else:
message = Message(**{name: getattr(payload, name) for name in Message.__slots__})
if not contains_mime_type(self.accept_wrapped_types, message.content_type):
self.msrp_session.send_report(chunk, 413, 'Unwanted Message')
return
if message.timestamp is None:
message.timestamp = ISOTimestamp.now()
if message.sender is None:
message.sender = self.remote_identity
private = self.session.remote_focus and len(message.recipients) == 1 and message.recipients[0] != self.remote_identity
else:
payload = SimplePayload.decode(data, content_type)
message = Message(payload.content, payload.content_type, sender=self.remote_identity, recipients=[self.local_identity], timestamp=ISOTimestamp.now())
private = False
try:
message.content = self.encryption.otr_session.handle_input(message.content, message.content_type)
except IgnoreMessage:
self.msrp_session.send_report(chunk, 200, 'OK')
return
except UnencryptedMessage:
encrypted = False
encryption_active = True
except EncryptedMessageError, e:
self.msrp_session.send_report(chunk, 400, str(e))
notification_center = NotificationCenter()
notification_center.post_notification('ChatStreamOTRError', sender=self, data=NotificationData(error=str(e)))
return
示例10: _NH_SIPApplicationDidStart
# 需要导入模块: from sipsimple.util import ISOTimestamp [as 别名]
# 或者: from sipsimple.util.ISOTimestamp import now [as 别名]
def _NH_SIPApplicationDidStart(self, notification):
settings = SIPSimpleSettings()
if settings.presence_state.timestamp is None:
settings.presence_state.timestamp = ISOTimestamp.now()
settings.save()
self.get_location([account for account in AccountManager().iter_accounts() if account is not BonjourAccount()])
self.publish()
idle_timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(1.0, self, "updateIdleTimer:", None, True)
NSRunLoop.currentRunLoop().addTimer_forMode_(idle_timer, NSRunLoopCommonModes)
NSRunLoop.currentRunLoop().addTimer_forMode_(idle_timer, NSEventTrackingRunLoopMode)
示例11: _NH_XMPPSubscriptionGotNotify
# 需要导入模块: from sipsimple.util import ISOTimestamp [as 别名]
# 或者: from sipsimple.util.ISOTimestamp import now [as 别名]
def _NH_XMPPSubscriptionGotNotify(self, notification):
stanza = notification.data.presence
self._stanza_cache[stanza.sender.uri] = stanza
stanza.timestamp = ISOTimestamp.now() # TODO: mirror the one in the stanza, if present
pidf_doc = self._build_pidf()
if XMPPGatewayConfig.log_presence:
log.msg('XMPP notification from %s to %s for presence flow 0x%x' % (format_uri(self.xmpp_identity.uri, 'xmpp'), format_uri(self.sip_identity.uri, 'sip'), id(self)))
for subscription in self._sip_subscriptions:
try:
subscription.push_content(pidf.PIDFDocument.content_type, pidf_doc)
except SIPCoreError, e:
if XMPPGatewayConfig.log_presence:
log.msg('Failed to send SIP NOTIFY from %s to %s for presence flow 0x%x: %s' % (format_uri(self.xmpp_identity.uri, 'xmpp'), format_uri(self.sip_identity.uri, 'sip'), id(self), e))
示例12: from_session
# 需要导入模块: from sipsimple.util import ISOTimestamp [as 别名]
# 或者: from sipsimple.util.ISOTimestamp import now [as 别名]
def from_session(cls, session):
if session.start_time is None and session.end_time is not None:
# Session may have anded before it fully started
session.start_time = session.end_time
call_time = session.start_time or ISOTimestamp.now()
if session.start_time and session.end_time:
duration = session.end_time - session.start_time
else:
duration = None
remote_uri = '%[email protected]%s' % (session.remote_identity.uri.user, session.remote_identity.uri.host)
match = cls.phone_number_re.match(remote_uri)
if match:
remote_uri = match.group('number')
display_name = session.remote_identity.display_name
return cls(session.direction, display_name, remote_uri, unicode(session.account.id), call_time, duration)
示例13: addAnsweringMachineRecordingToHistory
# 需要导入模块: from sipsimple.util import ISOTimestamp [as 别名]
# 或者: from sipsimple.util.ISOTimestamp import now [as 别名]
def addAnsweringMachineRecordingToHistory(self, filename, duration):
message = "<h3>Answering Machine Recording</h3>"
message += "<p>%s" % filename
message += "<br>Duration: %s seconds" % duration
message += "<p><audio src='%s' controls='controls'>" % urllib.quote(filename)
media_type = 'voicemail'
local_uri = format_identity_to_string(self.session.account)
remote_uri = format_identity_to_string(self.session.remote_identity)
direction = 'incoming'
status = 'delivered'
cpim_from = format_identity_to_string(self.session.remote_identity)
cpim_to = format_identity_to_string(self.session.remote_identity)
timestamp = str(ISOTimestamp.now())
self.add_to_history(media_type, local_uri, remote_uri, direction, cpim_from, cpim_to, timestamp, message, status)
示例14: add_to_history
# 需要导入模块: from sipsimple.util import ISOTimestamp [as 别名]
# 或者: from sipsimple.util.ISOTimestamp import now [as 别名]
def add_to_history(self):
FileTransferHistory().add_transfer(transfer_id=self.ft_info.transfer_id, direction=self.ft_info.direction, local_uri=self.ft_info.local_uri, remote_uri=self.ft_info.remote_uri, file_path=self.ft_info.file_path, bytes_transfered=self.ft_info.bytes_transfered, file_size=self.ft_info.file_size or 0, status=self.ft_info.status)
message = "<h3>%s File Transfer</h3>" % self.ft_info.direction.capitalize()
message += "<p>%s (%s)" % (self.ft_info.file_path, format_size(self.ft_info.file_size or 0))
media_type = 'file-transfer'
local_uri = self.ft_info.local_uri
remote_uri = self.ft_info.remote_uri
direction = self.ft_info.direction
status = 'delivered' if self.ft_info.status == 'completed' else 'failed'
cpim_from = self.ft_info.remote_uri
cpim_to = self.ft_info.remote_uri
timestamp = str(ISOTimestamp.now())
ChatHistory().add_message(self.ft_info.transfer_id, media_type, local_uri, remote_uri, direction, cpim_from, cpim_to, timestamp, message, "html", "0", status)
示例15: incoming_session
# 需要导入模块: from sipsimple.util import ISOTimestamp [as 别名]
# 或者: from sipsimple.util.ISOTimestamp import now [as 别名]
def incoming_session(originator, destination, tokens):
for token in tokens:
data = {'to': token,
'notification': {},
'data': {'sylkrtc': {}},
'content_available': True
}
data['notification']['body'] = 'Incoming session from %s' % originator
data['priority'] = 'high'
data['time_to_live'] = 60 # don't deliver if phone is out for over a minute
data['data']['sylkrtc']['event'] = 'incoming_session'
data['data']['sylkrtc']['originator'] = originator
data['data']['sylkrtc']['destination'] = destination
data['data']['sylkrtc']['timestamp'] = str(ISOTimestamp.now())
_send_push_notification(json.dumps(data))