Close the connection without assuming anything about it.
(self)
| 294 | return resp |
| 295 | |
| 296 | def close(self): |
| 297 | """Close the connection without assuming anything about it.""" |
| 298 | try: |
| 299 | file = self.file |
| 300 | self.file = None |
| 301 | if file is not None: |
| 302 | file.close() |
| 303 | finally: |
| 304 | sock = self.sock |
| 305 | self.sock = None |
| 306 | if sock is not None: |
| 307 | try: |
| 308 | sock.shutdown(socket.SHUT_RDWR) |
| 309 | except OSError as exc: |
| 310 | # The server might already have closed the connection. |
| 311 | # On Windows, this may result in WSAEINVAL (error 10022): |
| 312 | # An invalid operation was attempted. |
| 313 | if (exc.errno != errno.ENOTCONN |
| 314 | and getattr(exc, 'winerror', 0) != 10022): |
| 315 | raise |
| 316 | finally: |
| 317 | sock.close() |
| 318 | |
| 319 | #__del__ = quit |
| 320 |