| Home | Trees | Indices | Help |
|
|---|
|
|
1 # This program is public domain 2 """ 3 Parse user-host-port string. 4 """6 """ 7 Parse a resource locator into user, password, host and port. 8 9 user:password@host:port 10 11 This is a subset of URL, which also includes scheme and path. 12 """41 4214 user = password = host = '' 15 port = '0' 16 if '@' in value: 17 user,value = value.split('@') 18 if ':' in user: 19 user,password = user.split(':') 20 if ':' in value: 21 host,port = value.split(':') 22 else: 23 host = value 24 if host == '': host = 'localhost' 25 self.user = user 26 self.password = password 27 self.host = host 28 self.port = int(port)44 h = Host('a') 45 assert h.user=='' and h.password=='' and h.host=='a' and h.port==0 46 h = Host('a:4') 47 assert h.user=='' and h.password=='' and h.host=='a' and h.port==4 48 h = Host('u@a') 49 assert h.user=='u' and h.password=='' and h.host=='a' and h.port==0 50 h = Host('u:p@a') 51 assert h.user=='u' and h.password=='p' and h.host=='a' and h.port==0 52 h = Host('u@a:4') 53 assert h.user=='u' and h.password=='' and h.host=='a' and h.port==4 54 h = Host('u:p@a:4') 55 assert h.user=='u' and h.password=='p' and h.host=='a' and h.port==4 56 h = Host('') 57 assert h.user=='' and h.password=='' and h.host=='localhost' and h.port==0 58 h = Host('u@') 59 assert h.user=='u' and h.password=='' and h.host=='localhost' and h.port==0 60 h = Host('u@:4') 61 assert h.user=='u' and h.password=='' and h.host=='localhost' and h.port==4 62 h = Host('u:p@') 63 assert h.user=='u' and h.password=='p' and h.host=='localhost' and h.port==0 64 h = Host('u:p@:4') 65 assert h.user=='u' and h.password=='p' and h.host=='localhost' and h.port==466 67 if __name__ == "__main__": test() 68
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Mon Mar 16 15:04:52 2009 | http://epydoc.sourceforge.net |