fix bosh url parsing (wrong regex replaced by urlparse.urlsplit() funxtion)
This commit is contained in:
		
							parent
							
								
									c1cbc07645
								
							
						
					
					
						commit
						1a76b72b58
					
				
					 2 changed files with 15 additions and 17 deletions
				
			
		| 
						 | 
				
			
			@ -35,6 +35,7 @@ import errno
 | 
			
		|||
import time
 | 
			
		||||
import traceback
 | 
			
		||||
import base64
 | 
			
		||||
import urlparse
 | 
			
		||||
 | 
			
		||||
import logging
 | 
			
		||||
log = logging.getLogger('gajim.c.x.transports_nb')
 | 
			
		||||
| 
						 | 
				
			
			@ -46,25 +47,19 @@ def urisplit(uri):
 | 
			
		|||
	('http', 'httpcm.jabber.org', 123, '/webclient')
 | 
			
		||||
	return 443 as default port if proto is https else 80
 | 
			
		||||
	'''
 | 
			
		||||
	import re
 | 
			
		||||
	regex = '(([^:/]+)(://))?([^/]*)(:)*([^/]*)(/?.*)'
 | 
			
		||||
	grouped = re.match(regex, uri).groups()
 | 
			
		||||
	proto, host, port, path = grouped[1], grouped[3], grouped[5], grouped[6]
 | 
			
		||||
	splitted =  urlparse.urlsplit(uri)
 | 
			
		||||
	proto, host, path = splitted.scheme, splitted.hostname, splitted.path
 | 
			
		||||
	try:
 | 
			
		||||
		port = splitted.port
 | 
			
		||||
	except ValueError:
 | 
			
		||||
		log.warn('port cannot be extracted from BOSH URL %s, using default port' \
 | 
			
		||||
			% uri)
 | 
			
		||||
		port = ''
 | 
			
		||||
	if not port:
 | 
			
		||||
		if proto == 'https':
 | 
			
		||||
			port = 443
 | 
			
		||||
		else:
 | 
			
		||||
			port = 80
 | 
			
		||||
	else:
 | 
			
		||||
		try:
 | 
			
		||||
			port = int(port)
 | 
			
		||||
		except ValueError:
 | 
			
		||||
			if proto == 'https':
 | 
			
		||||
				port = 443
 | 
			
		||||
			else:
 | 
			
		||||
				port = 80
 | 
			
		||||
			log.warn('port cannot be extracted from BOSH URL %s, using port %i',
 | 
			
		||||
				uri, port)
 | 
			
		||||
	return proto, host, port, path
 | 
			
		||||
 | 
			
		||||
def get_proxy_data_from_dict(proxy):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,13 +17,16 @@ class TestModuleLevelFunctions(unittest.TestCase):
 | 
			
		|||
	Test class for functions defined at module level
 | 
			
		||||
	'''
 | 
			
		||||
	def test_urisplit(self):
 | 
			
		||||
		def check_uri(uri, proto, host, path):
 | 
			
		||||
			_proto, _host, _path = transports_nb.urisplit(uri)
 | 
			
		||||
		def check_uri(uri, proto, host, port, path):
 | 
			
		||||
			_proto, _host, _port, _path = transports_nb.urisplit(uri)
 | 
			
		||||
			self.assertEqual(proto, _proto)
 | 
			
		||||
			self.assertEqual(host, _host)
 | 
			
		||||
			self.assertEqual(port, _port)
 | 
			
		||||
			self.assertEqual(path, _path)
 | 
			
		||||
		check_uri('http://httpcm.jabber.org/webclient',
 | 
			
		||||
			proto='http', host='httpcm.jabber.org', path='/webclient')
 | 
			
		||||
			proto='http', host='httpcm.jabber.org', port=80, path='/webclient')
 | 
			
		||||
		check_uri('http://httpcm.jabber.org:5280/webclient',
 | 
			
		||||
			proto='http', host='httpcm.jabber.org', port=5280, path='/webclient')
 | 
			
		||||
 | 
			
		||||
	def test_get_proxy_data_from_dict(self):
 | 
			
		||||
		def check_dict(proxy_dict, host, port, user, passwd):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue