[英]Parsing telephone number from a SIP URI in Python
Is urlparse
the right module to use for this, or do we have something else? urlparse
是用于此的正确模块,还是我们还有其他东西?
>>> o = urlparse.urlparse('"User Name" <sips:+msisdn@domain?Accept-Contact=+sip.instance="<urn:uuid:2e7671fd-31dd-1393-dkd6-835fe09f314f>";require;explicit>', scheme='sips')
>>> print o
ParseResult(scheme='sips', netloc='', path='"User Name" <sips:+msisdn@domain', params='', query='Accept-Contact=+sip.instance="<urn:uuid:2e7671fd-31dd-1393-dkd6-835fe09f314f>";require;explicit>', fragment='')
>>>
I expected +msisdn@domain
at netloc
or path
, but the value in path
is a bit strange. 我预期+msisdn@domain
在netloc
或path
,但在价值path
是有点怪。
你可以看看它是如何在其他库中实现的,例如在twisted中 : https : //github.com/twisted/twisted/blob/trunk/twisted/protocols/sip.py#L427
You're not parsing a SIPS URI, but an Address-Of-Record (AOR). 您没有解析SIPS URI,而是解析记录地址(AOR)。 If you extract the URI from the AOR, you'll get: 如果从AOR中提取URI,您将获得:
>>> o = urlparse.urlparse('sips:+msisdn@domain?Accept-Contact=+sip.instance="<urn:uuid:2e7671fd-31dd-1393-dkd6-835fe09f314f>";require;explicit')
>>> print o
ParseResult(scheme='sips', netloc='', path='+msisdn@domain', params='', query='Accept-Contact=+sip.instance="<urn:uuid:2e7671fd-31dd-1393-dkd6-835fe09f314f>";require;explicit', fragment='')
According to RFC 3986 , the userinfo@host
part of the SIPS URI should go into the path
component, so the result is correct here. 根据RFC 3986 ,SIPS URI的userinfo@host
部分应该进入path
组件,因此这里的结果是正确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.