Ejemplo n.º 1
0
	def parse( self, value ):
		try:
			n = value.find( ':' )
			if n < 0:
				raise SipException( 'Failed to parse protocol of URI, ' + value + '.' )
			self.protocol = value[:n]
			value = value[n+1:]

			n = value.find( '@' )
			if n < 0:
				self.host = value
			else:
				self.host = value[n+1:]
				self.user = value[:n]

			if self.user:
				n = self.user.find( ':' )
				if n >= 0:
					self.password = self.user[n+1:]
					self.user = self.user[:n]

			self.host = HParams.parse( self.hparams, self.hkparams, self.host )

			self.host = Params.parse( self.params, self.kparams, self.host )

			n = self.host.find( ':' )
			if n >= 0:
				self.port = int( self.host[n+1:] )
				self.host = self.host[:n]

			if not self.host:
				raise SipException( 'Failed to parse host of URI, ' + value + '.' )
		except not SipException:
			raise SipException( 'Failed to parse the URI, ' + value + '.' )
Ejemplo n.º 2
0
	def build( self ):
		s = MutableString()

		s += str(self.value)
		s += Params.build( self.params, self.kparams )

		return str(s)
Ejemplo n.º 3
0
	def __cmp__( self, other ):
		if self.protocol != other.protocol:
			return self.protocol.__cmp__( other.protocol )

		if self.user != other.user:
			return self.user.__cmp__( other.user )

		if self.password != other.password:
			return self.password.__cmp__( other.password )

		if self.host != other.host:
			return self.host.__cmp__( other.host )

		if self.port != other.port:
			return self.port.__cmp__( other.port )

		n = Params.__cmp__( self.params, self.kparams, other.params, other.kparams )
		if n != 0:
			return n

		n = HParams.__cmp__( self.hparams, self.hkparams, other.hparams, other.hkparams )
		if n != 0:
			return n

		return 0
Ejemplo n.º 4
0
	def build( self ):
		s = MutableString()

		if self.protocol:
			s += self.protocol
			s += ':'

		if self.user:
			s += self.user
			if self.password:
				s += ':'
				s += self.password
			s += '@'

		if not self.host:
			raise SipException( 'Host not specified' )

		s += self.host

		if self.port:
			s += ':'
			s += str(self.port)

		s += Params.build( self.params, self.kparams )

		s += HParams.build( self.hparams, self.hkparams )

		return str(s)
Ejemplo n.º 5
0
	def parse( self, value ):
		lvalue = Params.parse( self.params, self.kparams, value )
		if lvalue.startswith( '<' ) and lvalue.endswith( '>' ):
			lvalue = lvalue.lstrip( '<' )
			lvalue = lvalue.rstrip( '>' )
			self.uri = Uri( uri )
		else:
			SipException( 'InfoElement, ' + str(self.value) + ', does not have opening or closing brackets.' )
Ejemplo n.º 6
0
	def __cmp__( self, other ):
		if self.value != other.value:
			return self.value.__cmp__( other.value )

		n = Params.__cmp__( self.params, self.kparams, other.params, other.kparams )
		if n != 0:
			return n

		return 0
Ejemplo n.º 7
0
	def parse( self, value ):
		value = Params.parse( self.params, self.kparams, value )
		if value:
			n = value.find( '/' )
			if n >= 0:
				self.type = value[:n]
				self.subtype = value[n+1:]
			else:
				self.type = value
Ejemplo n.º 8
0
	def __cmp__( self, other ):
		if self.uri != other.uri:
			return self.uri.__cmp__( other.uri )

		n = Params.__cmp__( self.params, self.kparams, other.params, other.kparams )
		if n != 0:
			return n

		return 0
Ejemplo n.º 9
0
	def parse( self, value ):
		value = Params.parse( self.params, self.kparams, value )
		if value:
			values = value.split( ' ' )
			self.host = values[1]

			values = values[0].split( '/' )
			self.protocol  = values[0]
			self.version   = values[1]
			self.transport = values[2]
Ejemplo n.º 10
0
	def build( self ):
		s = MutableString()

		if self.uri:
			s += '<'
			s += str(self.uri)
			s += '>'

		s += Params.build( self.params, self.kparams )

		return str(s)
Ejemplo n.º 11
0
	def dump( self ):
		s = MutableString()

		s += '['
		s += 'raw:\'' + str(self.raw) + '\'' + ', '
		s += 'protocol:\'' + str(self.protocol) + '\'' + ', '
		s += 'user:\'' + str(self.user) + '\'' + ', '
		s += Params.dump( self.params, self.kparams )
		s += ']'

		return str(s)
Ejemplo n.º 12
0
	def parse( self, value ):
		name = None
		uri = None

		# Try to parse using angle-brackets.
		n = value.find( '>' )
		if n >= 0:
			dummy = Params.parse( self.params, self.kparams, value[n+1:] )

			nameUri = value[:n]
			n = nameUri.find( '<' )
			if n < 0:
				raise SipException( 'Failed to find the matching left-angle-bracket for address, ' + value + '.' )

			uri = nameUri[n+1:]
			name = nameUri[:n]
		else:
			nameUri = Params.parse( self.params, self.kparams, value )

			uriIndex = 0
			nameUriArray = nameUri.split( '"' )
			if len(nameUriArray) == 1:
				pass
			elif len(nameUriArray) == 3:
				name = nameUriArray[1]
				uriIndex = 2
			else:
				raise SipException( 'Failed to parse address, ' + value + '.' )

			uri = nameUriArray[uriIndex]

		# Display Name
		if name:
			name = name.strip( ' ' )
			self.name = name.strip( '"' )

		# URI
		if uri:
			self.uri = Uri( uri )
		else:
			raise SipException( 'Failed to find URI in address, ' + value + '.' )
Ejemplo n.º 13
0
	def build( self ):
		s = MutableString()

		if self.type:
			s += self.type

		if self.subtype:
			s += '/'
			s += str(self.subtype)

		s += Params.build( self.params, self.kparams )

		return str(s)
Ejemplo n.º 14
0
	def parse( self, value ):
		try:
			n = value.find( ':' )
			if n < 0:
				raise SipException( 'Failed to parse protocol of URI, ' + value + '.' )
			self.protocol = value[:n]
			value = value[n+1:]

			self.user = Params.parse( self.params, self.kparams, value )

			if not self.user:
				raise SipException( 'Failed to parse user of URI, ' + value + '.' )
		except not SipException:
			raise SipException( 'Failed to parse the URI, ' + value + '.' )
Ejemplo n.º 15
0
	def __cmp__( self, other ):
		if self.name != other.name:
			return self.name.__cmp__( other.name )

		if self.uri != other.uri:
			return self.uri.__cmp__( other.uri )

#FIXME:DEBUG:		return super( Address, self ).__cmp__( other )

		n = Params.__cmp__( self.params, self.kparams, other.params, other.kparams )
		if n != 0:
			return n

		return 0
Ejemplo n.º 16
0
	def build( self ):
		s = MutableString()

		s += self.protocol
		s += '/'
		s += self.version
		s += '/'
		s += self.transport
		s += ' '
		s += str(self.host)

		s += Params.build( self.params, self.kparams )

		return str(s)
Ejemplo n.º 17
0
	def __cmp__( self, other ):
#FIXME: Other __cmp__ must handler other=None
		if not other:
			return 0

		if self.value != other.value:
			return self.value.__cmp__( other.value )

		n = Params.__cmp__( self.params, self.kparams, other.params, other.kparams )
#FIXME: Why this check here and in other cases?
		if n != 0:
			return n

		return 0
Ejemplo n.º 18
0
	def dump( self ):
		s = MutableString()

		s += '['
		s += 'raw:\'' + str(self.raw) + '\'' + ', '
		s += 'protocol:\'' + str(self.protocol) + '\'' + ', '
		s += 'user:\'' + str(self.user) + '\'' + ', '
		s += 'password:\'' + str(self.password) + '\'' + ', '
		s += 'host:\'' + str(self.host) + '\'' + ', '
		s += 'port:\'' + str(self.port) + '\'' + ', '
		s += Params.dump( self.params, self.kparams )
		s += HParams.dump( self.hparams, self.hkparams )
		s += ']'

		return str(s)
Ejemplo n.º 19
0
	def build( self ):
		s = MutableString()

		if self.protocol:
			s += self.protocol
			s += ':'

		if not self.user:
			raise SipException( 'User not specified' )

		if self.user:
			s += self.user

		s += Params.build( self.params, self.kparams )

		return str(s)
Ejemplo n.º 20
0
	def __cmp__( self, other ):
		if self.protocol != other.protocol:
			return self.protocol.__cmp__( other.protocol )

		if self.version != other.version:
			return self.version.__cmp__( other.version )

		if self.transport != other.transport:
			return self.transport.__cmp__( other.transport )

		if self.host != other.host:
			return self.host.__cmp__( other.host )

		n = Params.__cmp__( self.params, self.kparams, other.params, other.kparams )
		if n != 0:
			return n

		return 0
Ejemplo n.º 21
0
	def parse( self, value ):
		if ( isinstance( value, int ) ):
			self.value = int(value)
		else:
			value = Params.parse( self.params, self.kparams, value )
			self.value = int(value)
Ejemplo n.º 22
0
	def parse( self, value ):
		value = Params.parse( self.params, self.kparams, value )
		if value:
			self.value = value
		else:
			self.value = ''