当前位置: 首页>>代码示例>>Python>>正文


Python core.SIPURI类代码示例

本文整理汇总了Python中sipsimple.core.SIPURI的典型用法代码示例。如果您正苦于以下问题:Python SIPURI类的具体用法?Python SIPURI怎么用?Python SIPURI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SIPURI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _NH_IncomingFileTransferHandlerDidEnd

    def _NH_IncomingFileTransferHandlerDidEnd(self, notification):
        notification.center.remove_observer(self, sender=self)

        remote_hash = self.file_selector.hash
        if not self.transfer_finished:
            log.msg('File transfer of %s cancelled' % os.path.basename(self.filename))
            self.remove_bogus_file(self.filename)
            self.status = 'INCOMPLETE'
        else:
            local_hash = 'sha1:' + ':'.join(re.findall(r'..', self.hash.hexdigest().upper()))
            if local_hash != remote_hash:
                log.warning('Hash of transferred file does not match the remote hash (file may have changed).')
                self.status = 'HASH_MISSMATCH'
                self.remove_bogus_file(self.filename)
            else:
                self.status = 'OK'

        self_uri = SIPURI.new(self.session.local_identity.uri)
        self_uri.parameters.clear()
        sender_uri = SIPURI.new(self.session.remote_identity.uri)
        sender_uri.parameters.clear()

        self.session = None
        self.stream = None

        file = File(self.filename, remote_hash, self.file_selector.size)
        notification.center.post_notification('IncomingFileTransferHandlerGotFile', sender=self, data=NotificationData(local_uri=self_uri, remote_uri=sender_uri, file=file))
开发者ID:saghul,项目名称:sipstache,代码行数:27,代码来源:__init__.py

示例2: parse

 def parse(cls, value):
     if isinstance(value, BaseSIPURI):
         user = unicode(value.user)
         host = unicode(value.host)
         resource = unicode(value.parameters.get('gr', '')) or None
         return cls(user, host, resource)
     elif isinstance(value, JID):
         user = value.user
         host = value.host
         resource = value.resource
         return cls(user, host, resource)
     elif not isinstance(value, basestring):
         raise TypeError('uri needs to be a string')
     if not value.startswith(('sip:', 'sips:', 'xmpp:')):
         raise ValueError('invalid uri scheme for %s' % value)
     if value.startswith(('sip:', 'sips:')):
         try:
             uri = SIPURI.parse(value)
         except SIPCoreError:
             raise ValueError('invalid SIP uri: %s' % value)
         user = unicode(uri.user)
         host = unicode(uri.host)
         resource = unicode(uri.parameters.get('gr', '')) or None
     else:
         try:
             jid = JID(value[5:])
         except Exception:
             raise ValueError('invalid XMPP uri: %s' % value)
         user = jid.user
         host = jid.host
         resource = jid.resource
     return cls(user, host, resource)
开发者ID:madhawa,项目名称:sylkserver,代码行数:32,代码来源:datatypes.py

示例3: start

 def start(self):
     if not self.refer_to_uri.startswith(('sip:', 'sips:')):
         self.refer_to_uri = 'sip:%s' % self.refer_to_uri
     try:
         self.refer_to_uri = SIPURI.parse(self.refer_to_uri)
     except SIPCoreError:
         log.msg('Room %s - failed to add %s' % (self.room_uri_str, self.refer_to_uri))
         self._refer_request.reject(488)
         return
     notification_center = NotificationCenter()
     notification_center.add_observer(self, sender=self._refer_request)
     if self.method == 'INVITE':
         self._refer_request.accept()
         settings = SIPSimpleSettings()
         account = DefaultAccount()
         if account.sip.outbound_proxy is not None:
             uri = SIPURI(host=account.sip.outbound_proxy.host,
                          port=account.sip.outbound_proxy.port,
                          parameters={'transport': account.sip.outbound_proxy.transport})
         else:
             uri = self.refer_to_uri
         lookup = DNSLookup()
         notification_center.add_observer(self, sender=lookup)
         lookup.lookup_sip_proxy(uri, settings.sip.transport_list)
     elif self.method == 'BYE':
         log.msg('Room %s - %s removed %s from the room' % (self.room_uri_str, self._refer_headers.get('From').uri, self.refer_to_uri))
         self._refer_request.accept()
         conference_application = ConferenceApplication()
         conference_application.remove_participant(self.refer_to_uri, self.room_uri)
         self._refer_request.end(200)
     else:
         self._refer_request.reject(488)
开发者ID:AGProjects,项目名称:sylkserver,代码行数:32,代码来源:__init__.py

示例4: __init__

 def __init__(self, request):
     self.finished = False
     request.notifyFinish().addCallbacks(self._responseSucceeded, self._responseFailed)
     jsondata = request.content.getvalue()
     try:
         data = jsonlib.loads(jsondata)
     except (jsonlib.DecodeError, ValueError):
         if not self.finished:
             request.setResponseCode(400, 'Could not decode JSON data')
             request.finish()
         return
     try:
         target_uri = data.get('target_uri', '')
         if not re.match('^(sip:|sips:)', target_uri):
             target_uri = 'sip:%s' % target_uri
         target_uri = SIPURI.parse(target_uri)
     except SIPCoreError:
         if not self.finished:
             request.setResponseCode(400, 'Supplied SIP URI is invalid')
             request.finish()
         return
     cache = DataCache()
     data = cache.get(str(target_uri))
     if data is not None:
         if not self.finished:
             request.setHeader('Content-Type', 'application/json')
             request.write(jsonlib.dumps(data))
             request.finish()
         return
     self._target_uri = target_uri
     self._request = request
     self._handler = SIPOptionsRequestHandler(target_uri)
     NotificationCenter().add_observer(self, sender=self._handler)
     self._handler.start()
开发者ID:BioSoundSystems,项目名称:SIPwPing-server,代码行数:34,代码来源:web.py

示例5: incoming_message

    def incoming_message(self, message_request, data):
        content_type = data.headers.get("Content-Type", Null).content_type
        from_header = data.headers.get("From", Null)
        to_header = data.headers.get("To", Null)
        if Null in (content_type, from_header, to_header):
            message_request.answer(400)
            return
        log.msg("New SIP Message from %s to %s" % (from_header.uri, to_header.uri))

        # Check domain
        if from_header.uri.host not in XMPPGatewayConfig.domains:
            log.msg("Message rejected: From domain is not a local XMPP domain")
            message_request.answer(606)
            return

        if content_type == "message/cpim":
            try:
                cpim_message = CPIMPayload.decode(data.body)
            except CPIMParserError:
                log.msg("Message rejected: CPIM parse error")
                message_request.answer(400)
                return
            else:
                body = cpim_message.content
                content_type = cpim_message.content_type
                sender = cpim_message.sender or from_header
                from_uri = sender.uri
        else:
            body = data.body
            from_uri = from_header.uri
        to_uri = str(to_header.uri)
        message_request.answer(200)
        if from_uri.parameters.get("gr", None) is None:
            from_uri = SIPURI.new(from_uri)
            from_uri.parameters["gr"] = generate_sylk_resource()
        sender = Identity(FrozenURI.parse(from_uri))
        recipient = Identity(FrozenURI.parse(to_uri))
        if content_type in ("text/plain", "text/html"):
            if content_type == "text/plain":
                html_body = None
            else:
                html_body = body
                body = None
            if XMPPGatewayConfig.use_msrp_for_chat:
                message = NormalMessage(sender, recipient, body, html_body, use_receipt=False)
                self.xmpp_manager.send_stanza(message)
            else:
                message = ChatMessage(sender, recipient, body, html_body, use_receipt=False)
                self.xmpp_manager.send_stanza(message)
        elif content_type == IsComposingDocument.content_type:
            if not XMPPGatewayConfig.use_msrp_for_chat:
                try:
                    msg = IsComposingMessage.parse(body)
                except ParserError:
                    pass
                else:
                    state = "composing" if msg.state == "active" else "paused"
                    message = ChatComposingIndication(sender, recipient, state, use_receipt=False)
                    self.xmpp_manager.send_stanza(message)
开发者ID:LScarpinati,项目名称:sylkserver,代码行数:59,代码来源:__init__.py

示例6: incoming_message

    def incoming_message(self, message_request, data):
        content_type = data.headers.get('Content-Type', Null).content_type
        from_header = data.headers.get('From', Null)
        to_header = data.headers.get('To', Null)
        if Null in (content_type, from_header, to_header):
            message_request.answer(400)
            return
        log.msg('New SIP Message from %s to %s' % (from_header.uri, to_header.uri))

        # Check domain
        if from_header.uri.host not in XMPPGatewayConfig.domains:
            log.msg('Message rejected: From domain is not a local XMPP domain')
            message_request.answer(606)
            return

        if content_type == 'message/cpim':
            try:
                cpim_message = CPIMMessage.parse(data.body)
            except CPIMParserError:
                log.msg('Message rejected: CPIM parse error')
                message_request.answer(400)
                return
            else:
                body = cpim_message.body
                content_type = cpim_message.content_type
                sender = cpim_message.sender or from_header
                from_uri = sender.uri
        else:
            body = data.body
            from_uri = from_header.uri
        to_uri = str(to_header.uri)
        message_request.answer(200)
        if from_uri.parameters.get('gr', None) is None:
            from_uri = SIPURI.new(from_uri)
            from_uri.parameters['gr'] = generate_sylk_resource()
        sender = Identity(FrozenURI.parse(from_uri))
        recipient = Identity(FrozenURI.parse(to_uri))
        if content_type in ('text/plain', 'text/html'):
            if content_type == 'text/plain':
                html_body = None
            else:
                html_body = body
                body = None
            if XMPPGatewayConfig.use_msrp_for_chat:
                message = NormalMessage(sender, recipient, body, html_body, use_receipt=False)
                self.xmpp_manager.send_stanza(message)
            else:
                message = ChatMessage(sender, recipient, body, html_body, use_receipt=False)
                self.xmpp_manager.send_stanza(message)
        elif content_type == IsComposingDocument.content_type:
            if not XMPPGatewayConfig.use_msrp_for_chat:
                try:
                    msg = IsComposingMessage.parse(body)
                except ParserError:
                    pass
                else:
                    state = 'composing' if msg.state == 'active' else 'paused'
                    message = ChatComposingIndication(sender, recipient, state, use_receipt=False)
                    self.xmpp_manager.send_stanza(message)
开发者ID:madhawa,项目名称:sylkserver,代码行数:59,代码来源:__init__.py

示例7: get_audio_recordings

    def get_audio_recordings(self, filter_uris=[]):
        result = []
        historydir = self.get_audio_recordings_directory()

        for acct in os.listdir(historydir):
            dirname = historydir + "/" + acct
            if not os.path.isdir(dirname):
                continue

            files = [dirname+"/"+f for f in os.listdir(dirname) if f.endswith(".wav")]

            for file in files:
                try:
                    stat = os.stat(file)
                    toks = file.split("/")[-1].split("-", 2)
                    if len(toks) == 3:
                        date, time, rest = toks
                        timestamp = date[:4]+"/"+date[4:6]+"/"+date[6:8]+" "+time[:2]+":"+time[2:4]

                        pos = rest.rfind("-")
                        if pos >= 0:
                            remote = rest[:pos]
                        else:
                            remote = rest
                        try:
                            identity = SIPURI.parse('sip:'+str(remote))
                            remote_party = format_identity_to_string(identity, check_contact=True)
                        except SIPCoreError:
                            remote_party = "%s" % (remote)

                    else:
                        try:
                            identity = SIPURI.parse('sip:'+str(file[:-4]))
                            remote_party = format_identity_to_string(identity, check_contact=True)
                        except SIPCoreError:
                            remote_party = file[:-4]
                        timestamp = datetime.fromtimestamp(int(stat.st_ctime)).strftime("%E %T")

                    if filter_uris and remote_party not in filter_uris:
                        continue
                    result.append((timestamp, remote_party, file))
                except Exception:
                    pass

        result.sort(lambda a,b: cmp(a[0],b[0]))
        return result
开发者ID:uditha-atukorala,项目名称:blink,代码行数:46,代码来源:SIPManager.py

示例8: validateParticipant

def validateParticipant(uri):
    if not (uri.startswith('sip:') or uri.startswith('sips:')):
        uri = "sip:%s" % uri
    try:
        sip_uri = SIPURI.parse(str(uri))
    except SIPCoreError:
        return False
    else:
        return sip_uri.user is not None and sip_uri.host is not None
开发者ID:wilane,项目名称:blink-cocoa,代码行数:9,代码来源:ConferenceController.py

示例9: checkURI

    def checkURI(self, uri):
        if checkValidPhoneNumber(uri):
            return True

        if uri.startswith(('https:', 'http:')):
            url = urlparse.urlparse(uri)
            if url.scheme not in (u'http', u'https'):
                return False
            return True

        if not uri.startswith(('sip:', 'sips:')):
            uri = "sip:%s" % uri
        try:
            SIPURI.parse(str(uri))
        except SIPCoreError:
            return False

        return True
开发者ID:uditha-atukorala,项目名称:blink,代码行数:18,代码来源:ContactController.py

示例10: incoming_sip_message

 def incoming_sip_message(self, message_request, data):
     # Handle incoming MESSAGE
     from_header = data.headers.get('From', Null)
     to_header = data.headers.get('To', Null)
     content_type = data.headers.get('Content-Type', Null)[0]
     if from_header is Null or to_header is Null:
         message_request.answer(400)
         return
     message_request.answer(200)
     if content_type not in ('text/plain', 'text/html'):
         return
     source_uri = SIPURI.new(to_header.uri)
     destination_uri = SIPURI.new(from_header.uri)
     try:
         fact = self.facts.next()
     except StopIteration:
         return
     else:
         self.send_chuck_norris_fact(source_uri, destination_uri, fact)
开发者ID:SibghatullahSheikh,项目名称:sipsimple-examples,代码行数:19,代码来源:__init__.py

示例11: create_uri

 def create_uri(cls, account, address):
     if not address.startswith(('sip:', 'sips:')):
         address = 'sip:' + address
     username, separator, domain = address.partition('@')
     if not domain and isinstance(account, Account):
         domain = account.id.domain
     elif '.' not in domain and isinstance(account, Account):
         domain += '.' + account.id.domain
     elif not domain:
         raise ValueError('SIP address without domain')
     address = username + '@' + domain
     return SIPURI.parse(str(address))
开发者ID:eloycoto,项目名称:op2-daemon,代码行数:12,代码来源:sessions.py

示例12: _start_outgoing_jingle_session

    def _start_outgoing_jingle_session(self, streams):
        if self.xmpp_identity.uri.resource is not None:
            self.sip_session.reject()
            return
        xmpp_manager = XMPPManager()
        local_jid = self.sip_identity.uri.as_xmpp_jid()
        remote_jid = self.xmpp_identity.uri.as_xmpp_jid()

        # If this was an invitation to a conference, use the information in the Referred-By header
        if self.sip_identity.uri.host in xmpp_manager.muc_domains and self.sip_session.transfer_info and self.sip_session.transfer_info.referred_by:
            try:
                referred_by_uri = SIPURI.parse(self.sip_session.transfer_info.referred_by)
            except SIPCoreError:
                self.sip_session.reject(488)
                return
            else:
                inviter_uri = FrozenURI(referred_by_uri.user, referred_by_uri.host)
                local_jid = inviter_uri.as_xmpp_jid()

        # Use disco to gather potential JIDs to call
        d = xmpp_manager.disco_client_protocol.requestItems(remote_jid, sender=local_jid)
        try:
            items = block_on(d)
        except Exception:
            items = []
        if not items:
            self.sip_session.reject(480)
            return

        # Check which items support Jingle
        valid = []
        for item in items:
            d = xmpp_manager.disco_client_protocol.requestInfo(item.entity, nodeIdentifier=item.nodeIdentifier, sender=local_jid)
            try:
                info = block_on(d)
            except Exception:
                continue
            if jingle.NS_JINGLE in info.features and jingle.NS_JINGLE_APPS_RTP in info.features:
                valid.append(item.entity)
        if not valid:
            self.sip_session.reject(480)
            return

        # TODO: start multiple sessions?
        self._xmpp_identity = Identity(FrozenURI.parse(valid[0]))

        notification_center = NotificationCenter()
        if self.sip_identity.uri.host in xmpp_manager.muc_domains:
            self.jingle_session = JingleSession(xmpp_manager.jingle_coin_protocol)
        else:
            self.jingle_session = JingleSession(xmpp_manager.jingle_protocol)
        notification_center.add_observer(self, sender=self.jingle_session)
        self.jingle_session.connect(self.sip_identity, self.xmpp_identity, streams, is_focus=self.sip_session.remote_focus)
开发者ID:AGProjects,项目名称:sylkserver,代码行数:53,代码来源:media.py

示例13: parse

 def parse(cls, value):
     match = cls._re_format.match(value)
     if not match:
         raise ValueError('Cannot parse message/cpim identity header value: %r' % value)
     groupdict =  match.groupdict()
     display_name = groupdict['display_name']
     uri = groupdict['uri']
     # FIXME: silly hack for sip-chatserver which sends incorrect URIs. -Luci
     if not uri.startswith(u'sip:') and not uri.startswith(u'sips:'):
         uri = u'sip:' + uri
     # FIXME: SIPURI is not unicode friendly and expects a str. -Luci
     uri = SIPURI.parse(str(uri))
     return cls(uri, display_name)
开发者ID:LaoHanTeam,项目名称:python-sipsimple,代码行数:13,代码来源:chat.py

示例14: privmsg

 def privmsg(self, user, channel, message):
     if channel == '*':
         return
     username = user.split('!', 1)[0]
     if username == self.nickname:
         return
     if channel == self.nickname:
         self.msg(username, "Sorry, I don't support private messages, I'm a bot.")
         return
     uri = SIPURI.parse('sip:%[email protected]%s' % (urllib.quote(username), self.factory.config.server[0]))
     irc_message = IRCMessage(username, uri, message.decode('utf-8'))
     data = NotificationData(message=irc_message)
     NotificationCenter().post_notification('IRCBotGotMessage', self.factory, data)
开发者ID:AGProjects,项目名称:sylkserver,代码行数:13,代码来源:room.py

示例15: resolveAvatarUrl

    def resolveAvatarUrl(self, url):
        if url.startswith("/avatar/"):
            uri = SIPURI.parse(url[8:].decode("hex"))

            # TODO: see if there is an official way to get this, including notification of changes
            # also needs fixing of webodf, allowing custom avatar renderer
            if self.account.uri == uri:
                avatar = IconManager().get('avatar')
                return avatar.filename if avatar != None else self.default_user_icon_filename

            contact, contact_uri = URIUtils.find_contact(uri)
            return contact.icon.filename

        return ""
开发者ID:kogmbh,项目名称:blink-qt,代码行数:14,代码来源:backendbase.py


注:本文中的sipsimple.core.SIPURI类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。