string += ";" + ";".join(["%s%s" % (name, ("" if val is None else "="+urllib.quote(val, safe="()[]-_.!~*'/:&+$")))
for name, val in self.parameters.iteritems()])
if self.headers:
string += "?" + "&".join(["%s%s" % (name, ("" if val is None else "="+urllib.quote(val, safe="()[]-_.!~*'/:?+$")))
for name, val in self.headers.iteritems()])
if self.secure:
string = "sips:" + string
else:
string = "sip:" + string
return string
def __richcmp__(self, other, op):
return BaseSIPURI_richcmp(self, other, op)
property transport:
def __get__(self):
return self.parameters.get('transport', 'udp')
def __set__(self, str transport not None):
if isinstance(self, FrozenSIPURI):
raise AttributeError("can't set readonly attribute")
if transport.lower() == 'udp':
self.parameters.pop('transport', None)
else:
self.parameters['transport'] = transport
def matches(self, address):
match = re.match(r'^((?P<scheme>sip|sips):)?(?P<username>.+?)(@(?P<domain>.+?)(:(?P<port>\d+?))?)?(;(?P<parameters>.+?))?(\?(?P<headers>.+?))?$', address)
if match is None:
return False
components = match.groupdict()
if components['scheme'] is not None:
expected_scheme = 'sips' if self.secure else 'sip'
if components['scheme'] != expected_scheme:
return False
if components['username'] != self.user:
return False
if components['domain'] is not None and components['domain'] != self.host:
return False
if components['port'] is not None and int(components['port']) != self.port:
return False
if components['parameters']:
parameters = dict([(name, value) for name, sep, value in [param.partition('=') for param in components['parameters'].split(';')]])
expected_parameters = dict([(name, str(value) if value is not None else None) for name, value in self.parameters.iteritems() if name in parameters])
if parameters != expected_parameters:
return False
if components['headers']:
headers = dict([(name, value) for name, sep, value in [header.partition('=') for header in components['headers'].split('&')]])
expected_headers = dict([(name, str(value) if value is not None else None) for name, value in self.headers.iteritems() if name in headers])