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