Close the connection without assuming anything about it.
(self)
| 281 | return resp |
| 282 | |
| 283 | def close(self): |
| 284 | """Close the connection without assuming anything about it.""" |
| 285 | try: |
| 286 | file = self.file |
| 287 | self.file = None |
| 288 | if file is not None: |
| 289 | file.close() |
| 290 | finally: |
| 291 | sock = self.sock |
| 292 | self.sock = None |
| 293 | if sock is not None: |
| 294 | try: |
| 295 | sock.shutdown(socket.SHUT_RDWR) |
| 296 | except OSError as exc: |
| 297 | # The server might already have closed the connection. |
| 298 | # On Windows, this may result in WSAEINVAL (error 10022): |
| 299 | # An invalid operation was attempted. |
| 300 | if (exc.errno != errno.ENOTCONN |
| 301 | and getattr(exc, 'winerror', 0) != 10022): |
| 302 | raise |
| 303 | finally: |
| 304 | sock.close() |
| 305 | |
| 306 | #__del__ = quit |
| 307 |