예제 #1
0
class Options(object):
    implements(IObserver)

    def __init__(self, from_header, to_header, route_header, credentials=None, extra_headers=[]):
        self._request = Request("OPTIONS", to_header.uri, from_header, to_header, route_header,
                                credentials=credentials, extra_headers=extra_headers)
        self._lock = RLock()

    from_header = property(lambda self: self._request.from_header)
    to_header = property(lambda self: self._request.to_header)
    route_header = property(lambda self: self._request.route_header)
    credentials = property(lambda self: self._request.credentials)
    in_progress = property(lambda self: self._request.state == "IN_PROGRESS")
    peer_address = property(lambda self: self._request.peer_address)

    def send(self, timeout=None):
        notification_center = NotificationCenter()
        with self._lock:
            notification_center.add_observer(self, sender=self._request)
            try:
                self._request.send(timeout)
            except:
                notification_center.remove_observer(self, sender=self._request)

    def end(self):
        with self._lock:
            self._request.end()

    def handle_notification(self, notification):
        handler = getattr(self, '_NH_%s' % notification.name, Null)
        handler(notification)

    def _NH_SIPRequestDidSucceed(self, notification):
        with self._lock:
            NotificationCenter().post_notification("SIPOptionsDidSucceed", sender=self,
                                                   data=TimestampedNotificationData(code=notification.data.code,
                                                                                    reason=notification.data.reason))

    def _NH_SIPRequestDidFail(self, notification):
        with self._lock:
            NotificationCenter().post_notification("SIPOptionsDidFail", sender=self,
                                                   data=TimestampedNotificationData(code=notification.data.code,
                                                                                    reason=notification.data.reason))

    def _NH_SIPRequestDidEnd(self, notification):
        with self._lock:
            NotificationCenter().remove_observer(self, sender=notification.sender)
예제 #2
0
 def __init__(self, from_header, to_header, route_header, credentials=None, extra_headers=[]):
     self._request = Request("OPTIONS", to_header.uri, from_header, to_header, route_header,
                             credentials=credentials, extra_headers=extra_headers)
     self._lock = RLock()