diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2001-07-26 13:37:33 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2001-07-26 13:37:33 (GMT) |
commit | 4eb5940a4d350d250ab4af08a8b5b6e553e1814d (patch) | |
tree | b3d063c4d166a00f994bf64a80921553b15f1740 /Lib | |
parent | 2e441f7836134c475e35eea4a005f19699703a9b (diff) | |
download | cpython-4eb5940a4d350d250ab4af08a8b5b6e553e1814d.zip cpython-4eb5940a4d350d250ab4af08a8b5b6e553e1814d.tar.gz cpython-4eb5940a4d350d250ab4af08a8b5b6e553e1814d.tar.bz2 |
Untabify IPv6 changes.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/ftplib.py | 132 | ||||
-rw-r--r-- | Lib/httplib.py | 32 | ||||
-rw-r--r-- | Lib/poplib.py | 34 | ||||
-rwxr-xr-x | Lib/smtplib.py | 32 | ||||
-rw-r--r-- | Lib/telnetlib.py | 22 |
5 files changed, 126 insertions, 126 deletions
diff --git a/Lib/ftplib.py b/Lib/ftplib.py index 693d5a9..885b5cd 100644 --- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -109,28 +109,28 @@ class FTP: if user: self.login(user, passwd, acct) def connect(self, host = '', port = 0): - '''Connect to host. Arguments are: - - host: hostname to connect to (string, default previous host) - - port: port to connect to (integer, default previous port)''' - if host: self.host = host - if port: self.port = port - self.passiveserver = 0 - for res in socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM): - af, socktype, proto, canonname, sa = res - try: - self.sock = socket.socket(af, socktype, proto) - self.sock.connect(sa) - except socket.error, msg: - self.sock.close() - self.sock = None - continue - break - if not self.sock: - raise socket.error, msg - self.af = af - self.file = self.sock.makefile('rb') - self.welcome = self.getresp() - return self.welcome + '''Connect to host. Arguments are: + - host: hostname to connect to (string, default previous host) + - port: port to connect to (integer, default previous port)''' + if host: self.host = host + if port: self.port = port + self.passiveserver = 0 + for res in socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM): + af, socktype, proto, canonname, sa = res + try: + self.sock = socket.socket(af, socktype, proto) + self.sock.connect(sa) + except socket.error, msg: + self.sock.close() + self.sock = None + continue + break + if not self.sock: + raise socket.error, msg + self.af = af + self.file = self.sock.makefile('rb') + self.welcome = self.getresp() + return self.welcome def getwelcome(self): '''Get the welcome message from the server. @@ -256,47 +256,47 @@ class FTP: return self.voidcmd(cmd) def sendeprt(self, host, port): - '''Send a EPRT command with the current host and the given port number.''' - af = 0 - if self.af == socket.AF_INET: - af = 1 - if self.af == socket.AF_INET6: - af = 2 - if af == 0: - raise error_proto, 'unsupported address family' - fields = ['', `af`, host, `port`, ''] - cmd = 'EPRT ' + string.joinfields(fields, '|') - return self.voidcmd(cmd) + '''Send a EPRT command with the current host and the given port number.''' + af = 0 + if self.af == socket.AF_INET: + af = 1 + if self.af == socket.AF_INET6: + af = 2 + if af == 0: + raise error_proto, 'unsupported address family' + fields = ['', `af`, host, `port`, ''] + cmd = 'EPRT ' + string.joinfields(fields, '|') + return self.voidcmd(cmd) def makeport(self): - '''Create a new socket and send a PORT command for it.''' - for res in socket.getaddrinfo(None, 0, self.af, socket.SOCK_STREAM, 0, socket.AI_PASSIVE): - af, socktype, proto, canonname, sa = res - try: - sock = socket.socket(af, socktype, proto) - sock.bind(sa) - except socket.error, msg: - sock.close() - sock = None - continue - break - if not sock: - raise socket.error, msg - sock.listen(1) - port = sock.getsockname()[1] # Get proper port - host = self.sock.getsockname()[0] # Get proper host - if self.af == socket.AF_INET: - resp = self.sendport(host, port) - else: - resp = self.sendeprt(host, port) - return sock + '''Create a new socket and send a PORT command for it.''' + for res in socket.getaddrinfo(None, 0, self.af, socket.SOCK_STREAM, 0, socket.AI_PASSIVE): + af, socktype, proto, canonname, sa = res + try: + sock = socket.socket(af, socktype, proto) + sock.bind(sa) + except socket.error, msg: + sock.close() + sock = None + continue + break + if not sock: + raise socket.error, msg + sock.listen(1) + port = sock.getsockname()[1] # Get proper port + host = self.sock.getsockname()[0] # Get proper host + if self.af == socket.AF_INET: + resp = self.sendport(host, port) + else: + resp = self.sendeprt(host, port) + return sock def makepasv(self): - if self.af == socket.AF_INET: - host, port = parse227(self.sendcmd('PASV')) - else: - host, port = parse229(self.sendcmd('EPSV'), self.sock.getpeername()) - return host, port + if self.af == socket.AF_INET: + host, port = parse227(self.sendcmd('PASV')) + else: + host, port = parse229(self.sendcmd('EPSV'), self.sock.getpeername()) + return host, port def ntransfercmd(self, cmd, rest=None): """Initiate a transfer over the data connection. @@ -316,9 +316,9 @@ class FTP: size = None if self.passiveserver: host, port = self.makepasv() - af, socktype, proto, canon, sa = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)[0] - conn = socket.socket(af, socktype, proto) - conn.connect(sa) + af, socktype, proto, canon, sa = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)[0] + conn = socket.socket(af, socktype, proto) + conn.connect(sa) if rest is not None: self.sendcmd("REST %s" % rest) resp = self.sendcmd(cmd) @@ -575,17 +575,17 @@ def parse229(resp, peer): Return ('host.addr.as.numbers', port#) tuple.''' if resp[:3] <> '229': - raise error_reply, resp + raise error_reply, resp left = string.find(resp, '(') if left < 0: raise error_proto, resp right = string.find(resp, ')', left + 1) if right < 0: - raise error_proto, resp # should contain '(|||port|)' + raise error_proto, resp # should contain '(|||port|)' if resp[left + 1] <> resp[right - 1]: - raise error_proto, resp + raise error_proto, resp parts = string.split(resp[left + 1:right], resp[left+1]) if len(parts) <> 5: - raise error_proto, resp + raise error_proto, resp host = peer[0] port = string.atoi(parts[3]) return host, port diff --git a/Lib/httplib.py b/Lib/httplib.py index d566b35..1038831 100644 --- a/Lib/httplib.py +++ b/Lib/httplib.py @@ -357,22 +357,22 @@ class HTTPConnection: def connect(self): """Connect to the host and port specified in __init__.""" - for res in socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM): - af, socktype, proto, canonname, sa = res - try: - self.sock = socket.socket(af, socktype, proto) - if self.debuglevel > 0: - print "connect: (%s, %s)" % (self.host, self.port) - self.sock.connect(sa) - except socket.error, msg: - if self.debuglevel > 0: - print 'connect fail:', (self.host, self.port) - self.sock.close() - self.sock = None - continue - break - if not self.sock: - raise socket.error, msg + for res in socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM): + af, socktype, proto, canonname, sa = res + try: + self.sock = socket.socket(af, socktype, proto) + if self.debuglevel > 0: + print "connect: (%s, %s)" % (self.host, self.port) + self.sock.connect(sa) + except socket.error, msg: + if self.debuglevel > 0: + print 'connect fail:', (self.host, self.port) + self.sock.close() + self.sock = None + continue + break + if not self.sock: + raise socket.error, msg def close(self): """Close the connection to the HTTP server.""" diff --git a/Lib/poplib.py b/Lib/poplib.py index c6c432d..592f7df 100644 --- a/Lib/poplib.py +++ b/Lib/poplib.py @@ -73,23 +73,23 @@ class POP3: def __init__(self, host, port = POP3_PORT): - self.host = host - self.port = port - for res in socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM): - af, socktype, proto, canonname, sa = res - try: - self.sock = socket.socket(af, socktype, proto) - self.sock.connect(sa) - except socket.error, msg: - self.sock.close() - self.sock = None - continue - break - if not self.sock: - raise socket.error, msg - self.file = self.sock.makefile('rb') - self._debugging = 0 - self.welcome = self._getresp() + self.host = host + self.port = port + for res in socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM): + af, socktype, proto, canonname, sa = res + try: + self.sock = socket.socket(af, socktype, proto) + self.sock.connect(sa) + except socket.error, msg: + self.sock.close() + self.sock = None + continue + break + if not self.sock: + raise socket.error, msg + self.file = self.sock.makefile('rb') + self._debugging = 0 + self.welcome = self._getresp() def _putline(self, line): diff --git a/Lib/smtplib.py b/Lib/smtplib.py index fde6c69..27cda40 100755 --- a/Lib/smtplib.py +++ b/Lib/smtplib.py @@ -208,7 +208,7 @@ class SMTP: specified during instantiation. """ - if not port and (host.find(':') == host.rfind(':')): + if not port and (host.find(':') == host.rfind(':')): i = host.rfind(':') if i >= 0: host, port = host[:i], host[i+1:] @@ -216,21 +216,21 @@ class SMTP: except ValueError: raise socket.error, "nonnumeric port" if not port: port = SMTP_PORT - if self.debuglevel > 0: print 'connect:', (host, port) - for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM): - af, socktype, proto, canonname, sa = res - try: - self.sock = socket.socket(af, socktype, proto) - if self.debuglevel > 0: print 'connect:', (host, port) - self.sock.connect(sa) - except socket.error, msg: - if self.debuglevel > 0: print 'connect fail:', (host, port) - self.sock.close() - self.sock = None - continue - break - if not self.sock: - raise socket.error, msg + if self.debuglevel > 0: print 'connect:', (host, port) + for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM): + af, socktype, proto, canonname, sa = res + try: + self.sock = socket.socket(af, socktype, proto) + if self.debuglevel > 0: print 'connect:', (host, port) + self.sock.connect(sa) + except socket.error, msg: + if self.debuglevel > 0: print 'connect fail:', (host, port) + self.sock.close() + self.sock = None + continue + break + if not self.sock: + raise socket.error, msg (code, msg) = self.getreply() if self.debuglevel > 0: print "connect:", msg return (code, msg) diff --git a/Lib/telnetlib.py b/Lib/telnetlib.py index 77ed39e..5bac9e7 100644 --- a/Lib/telnetlib.py +++ b/Lib/telnetlib.py @@ -136,18 +136,18 @@ class Telnet: port = TELNET_PORT self.host = host self.port = port - for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM): - af, socktype, proto, canonname, sa = res - try: - self.sock = socket.socket(af, socktype, proto) - self.sock.connect(sa) - except socket.error, msg: - self.sock.close() - self.sock = None - continue - break + for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM): + af, socktype, proto, canonname, sa = res + try: + self.sock = socket.socket(af, socktype, proto) + self.sock.connect(sa) + except socket.error, msg: + self.sock.close() + self.sock = None + continue + break if not self.sock: - raise socket.error, msg + raise socket.error, msg def __del__(self): """Destructor -- close the connection.""" |