'#20128 -- IOErrors during POST data reading should be caught and
treated as if the POST data wasn\'t there.'

def test_post_data_read_failure(self):

    class CsrfPostRequest(HttpRequest, ):
        '\n                                                HttpRequest    that    can    raise    an    IOError    when    accessing    POST    data\n                                                '
        def __init__(self, token, raise_error):
            super().__init__()
            self.method = 'POST'
            self.raise_error = False
            self.COOKIES[settings.CSRF_COOKIE_NAME] = token
            self.session = {}
            self.session[CSRF_SESSION_KEY] = token
            self.POST['csrfmiddlewaretoken'] = token
            self.raise_error = raise_error
        def _load_post_and_files(self):
            raise IOError('error    reading    input    data')
        def _get_post(self):
            if self.raise_error:
                self._load_post_and_files()
            return self._post
        def _set_post(self, post):
            self._post = post
        POST = property(_get_post, _set_post)
    token = ('ABC' + self._csrf_id)[:CSRF_TOKEN_LENGTH]
    req = CsrfPostRequest(token, raise_error=False)
    resp = CsrfViewMiddleware().process_view(req, post_form_view, (), {})
    self.assertIsNone(resp)
    req = CsrfPostRequest(token, raise_error=True)
    with patch_logger('django.security.csrf', 'warning') as logger_calls:
        resp = CsrfViewMiddleware().process_view(req, post_form_view, (), {})
        self.assertEqual(resp.status_code, 403)
        self.assertEqual(logger_calls[0], ('Forbidden    (%s):    ' % REASON_BAD_TOKEN))
