Ticket #126: post_data.patch

File post_data.patch, 3.2 KB (added by slashzero, 19 years ago)
  • wsgi.py

     
    2020        # Populates self._post and self._files
    2121        if self.environ['REQUEST_METHOD'] == 'POST':
    2222            post_data = self.environ['wsgi.input'].read(int(self.environ["CONTENT_LENGTH"]))
     23            self._post_data = post_data
    2324            if self.environ.get('CONTENT_TYPE', '').startswith('multipart'):
    2425                header_dict = dict([(k, v) for k, v in self.environ.items() if k.startswith('HTTP_')])
    2526                self._post, self._files = httpwrappers.parse_file_upload(header_dict, post_data)
     
    8990
    9091    def _set_user(self, user):
    9192        self._user = user
     93       
     94    def _set_post_data(self,post_data):
     95        self._post_data = post_data
    9296
     97    def _get_post_data(self):
     98        if not hasattr(self, '_post_data'):
     99            self._load_post_and_files()
     100        if hasattr(self, '_post_data'):
     101            return(self._post_data)
     102        else:
     103            return("")
     104
    93105    GET = property(_get_get, _set_get)
    94106    POST = property(_get_post, _set_post)
    95107    COOKIES = property(_get_cookies, _set_cookies)
     
    97109    REQUEST = property(_get_request)
    98110    session = property(_get_session, _set_session)
    99111    user = property(_get_user, _set_user)
     112    post_data = property(_get_post_data,_set_post_data)
    100113
    101114class WSGIHandler:
    102115    def __init__(self):
  • modpython.py

     
    2121
    2222    def _load_post_and_files(self):
    2323        "Populates self._post and self._files"
     24        self._post_data = self._req.read()
    2425        if self._req.headers_in.has_key('content-type') and self._req.headers_in['content-type'].startswith('multipart'):
    25             self._post, self._files = httpwrappers.parse_file_upload(self._req.headers_in, self._req.read())
     26            self._post, self._files = httpwrappers.parse_file_upload(self._req.headers_in, self._post_data)
    2627        else:
    27             self._post, self._files = httpwrappers.QueryDict(self._req.read()), datastructures.MultiValueDict()
     28            self._post, self._files = httpwrappers.QueryDict(self._post_data), datastructures.MultiValueDict()
    2829
    2930    def _get_request(self):
    3031        if not hasattr(self, '_request'):
     
    115116    def _set_user(self, user):
    116117        self._user = user
    117118
     119    def _set_post_data(self,post_data):
     120        self._post_data = post_data
     121
     122    def _get_post_data(self):
     123        if not hasattr(self, '_post_data'):
     124            self._load_post_and_files()
     125        if hasattr(self, '_post_data'):
     126            return(self._post_data)
     127        else:
     128            return("")
     129
     130
    118131    GET = property(_get_get, _set_get)
    119132    POST = property(_get_post, _set_post)
    120133    COOKIES = property(_get_cookies, _set_cookies)
     
    123136    REQUEST = property(_get_request)
    124137    session = property(_get_session, _set_session)
    125138    user = property(_get_user, _set_user)
    126 
     139    post_data = property(_get_post_data,_set_post_data)
     140   
    127141class ModPythonHandler:
    128142    def __init__(self):
    129143        self._request_middleware = self._view_middleware = self._response_middleware = None
Back to Top