本文整理汇总了Python中sipsimple.core.SIPURI.parse方法的典型用法代码示例。如果您正苦于以下问题:Python SIPURI.parse方法的具体用法?Python SIPURI.parse怎么用?Python SIPURI.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sipsimple.core.SIPURI
的用法示例。
在下文中一共展示了SIPURI.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from sipsimple.core import SIPURI [as 别名]
# 或者: from sipsimple.core.SIPURI import parse [as 别名]
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()
示例2: parse
# 需要导入模块: from sipsimple.core import SIPURI [as 别名]
# 或者: from sipsimple.core.SIPURI import parse [as 别名]
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)
示例3: start
# 需要导入模块: from sipsimple.core import SIPURI [as 别名]
# 或者: from sipsimple.core.SIPURI import parse [as 别名]
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)
示例4: get_audio_recordings
# 需要导入模块: from sipsimple.core import SIPURI [as 别名]
# 或者: from sipsimple.core.SIPURI import parse [as 别名]
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
示例5: checkURI
# 需要导入模块: from sipsimple.core import SIPURI [as 别名]
# 或者: from sipsimple.core.SIPURI import parse [as 别名]
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
示例6: validateParticipant
# 需要导入模块: from sipsimple.core import SIPURI [as 别名]
# 或者: from sipsimple.core.SIPURI import parse [as 别名]
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
示例7: create_uri
# 需要导入模块: from sipsimple.core import SIPURI [as 别名]
# 或者: from sipsimple.core.SIPURI import parse [as 别名]
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))
示例8: _start_outgoing_jingle_session
# 需要导入模块: from sipsimple.core import SIPURI [as 别名]
# 或者: from sipsimple.core.SIPURI import parse [as 别名]
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)
示例9: parse
# 需要导入模块: from sipsimple.core import SIPURI [as 别名]
# 或者: from sipsimple.core.SIPURI import parse [as 别名]
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)
示例10: privmsg
# 需要导入模块: from sipsimple.core import SIPURI [as 别名]
# 或者: from sipsimple.core.SIPURI import parse [as 别名]
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)
示例11: resolveAvatarUrl
# 需要导入模块: from sipsimple.core import SIPURI [as 别名]
# 或者: from sipsimple.core.SIPURI import parse [as 别名]
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 ""
示例12: __eq__
# 需要导入模块: from sipsimple.core import SIPURI [as 别名]
# 或者: from sipsimple.core.SIPURI import parse [as 别名]
def __eq__(self, other):
if isinstance(other, ChatIdentity):
return self.uri.user == other.uri.user and self.uri.host == other.uri.host
elif isinstance(other, BaseSIPURI):
return self.uri.user == other.user and self.uri.host == other.host
elif isinstance(other, basestring):
try:
other_uri = SIPURI.parse(other)
except Exception:
return False
else:
return self.uri.user == other_uri.user and self.uri.host == other_uri.host
else:
return NotImplemented
示例13: is_sip_aor_format
# 需要导入模块: from sipsimple.core import SIPURI [as 别名]
# 或者: from sipsimple.core.SIPURI import parse [as 别名]
def is_sip_aor_format(uri):
"""
Check if the given URI is a full SIP URI with username and host.
"""
if isinstance(uri, (SIPURI, FrozenSIPURI)):
return uri.user is not None and uri.host is not None
else:
if not (uri.startswith('sip:') or uri.startswith('sips:')):
uri = "sip:%s" % uri
try:
sip_uri = SIPURI.parse(str(uri))
except:
return False
else:
return sip_uri.user is not None and sip_uri.host is not None
示例14: is_anonymous
# 需要导入模块: from sipsimple.core import SIPURI [as 别名]
# 或者: from sipsimple.core.SIPURI import parse [as 别名]
def is_anonymous(uri):
"""
Check if the given URI is an anonymous uri
"""
if isinstance(uri, (SIPURI, FrozenSIPURI)):
return (uri.user is None or uri.user.lower() == 'anonymous') and (uri.host is None or uri.host.lower() == 'anonymous.invalid')
else:
if not (uri.startswith('sip:') or uri.startswith('sips:')):
uri = "sip:%s" % uri
try:
sip_uri = SIPURI.parse(str(uri))
except:
return False
else:
return (sip_uri.user is None or sip_uri.user.lower() == 'anonymous') and (sip_uri.host is None or sip_uri.host.lower() == 'anonymous.invalid')
示例15: _lookup_sip_proxy
# 需要导入模块: from sipsimple.core import SIPURI [as 别名]
# 或者: from sipsimple.core.SIPURI import parse [as 别名]
def _lookup_sip_proxy(self, account):
sip_uri = SIPURI.parse('sip:%s' % account)
# The proxy dance: Sofia-SIP seems to do a DNS lookup per SIP message when a domain is passed
# as the proxy, so do the resolution ourselves and give it pre-resolver proxy URL. Since we use
# caching to avoid long delays, we randomize the results matching the highest priority route's
# transport.
proxy = GeneralConfig.outbound_sip_proxy
if proxy is not None:
proxy_uri = SIPURI(host=proxy.host,
port=proxy.port,
parameters={'transport': proxy.transport})
else:
proxy_uri = SIPURI(host=sip_uri.host)
settings = SIPSimpleSettings()
try:
routes = self.resolver.lookup_sip_proxy(proxy_uri, settings.sip.transport_list).wait()
except DNSLookupError, e:
raise DNSLookupError('DNS lookup error: %s' % e)