Connect to a host on a given port. If the hostname ends with a colon (`:') followed by a number, and there is no port specified, that suffix will be stripped off and the number interpreted as the port number to use. Note: This method is automatically invoked b
(self, host='localhost', port=0, source_address=None)
| 313 | self.source_address) |
| 314 | |
| 315 | def connect(self, host='localhost', port=0, source_address=None): |
| 316 | """Connect to a host on a given port. |
| 317 | |
| 318 | If the hostname ends with a colon (`:') followed by a number, and |
| 319 | there is no port specified, that suffix will be stripped off and the |
| 320 | number interpreted as the port number to use. |
| 321 | |
| 322 | Note: This method is automatically invoked by __init__, if a host is |
| 323 | specified during instantiation. |
| 324 | |
| 325 | """ |
| 326 | |
| 327 | if source_address: |
| 328 | self.source_address = source_address |
| 329 | |
| 330 | if not port and (host.find(':') == host.rfind(':')): |
| 331 | i = host.rfind(':') |
| 332 | if i >= 0: |
| 333 | host, port = host[:i], host[i + 1:] |
| 334 | try: |
| 335 | port = int(port) |
| 336 | except ValueError: |
| 337 | raise OSError("nonnumeric port") |
| 338 | if not port: |
| 339 | port = self.default_port |
| 340 | sys.audit("smtplib.connect", self, host, port) |
| 341 | self.sock = self._get_socket(host, port, self.timeout) |
| 342 | self.file = None |
| 343 | (code, msg) = self.getreply() |
| 344 | if self.debuglevel > 0: |
| 345 | self._print_debug('connect:', repr(msg)) |
| 346 | return (code, msg) |
| 347 | |
| 348 | def send(self, s): |
| 349 | """Send `s' to the server.""" |
no test coverage detected