Django

Code

Changeset 5342

Show
Ignore:
Timestamp:
05/25/07 04:48:02 (1 year ago)
Author:
mtredinnick
Message:

unicode: Added a more convenient way to set/change the encoding on a request
instance.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/unicode/django/core/handlers/modpython.py

    r5126 r5342  
    5050            self._post, self._files = http.parse_file_upload(self._req.headers_in, self.raw_post_data) 
    5151        else: 
    52             self._post, self._files = http.QueryDict(self.raw_post_data), datastructures.MultiValueDict() 
     52            self._post, self._files = http.QueryDict(self.raw_post_data, encoding=self._encoding), datastructures.MultiValueDict() 
    5353 
    5454    def _get_request(self): 
     
    5959    def _get_get(self): 
    6060        if not hasattr(self, '_get'): 
    61             self._get = http.QueryDict(self._req.args
     61            self._get = http.QueryDict(self._req.args, encoding=self._encoding
    6262        return self._get 
    6363 
  • django/branches/unicode/django/core/handlers/wsgi.py

    r5126 r5342  
    114114                self._post, self._files = http.parse_file_upload(header_dict, self.raw_post_data) 
    115115            else: 
    116                 self._post, self._files = http.QueryDict(self.raw_post_data), datastructures.MultiValueDict() 
     116                self._post, self._files = http.QueryDict(self.raw_post_data, encoding=self._encoding), datastructures.MultiValueDict() 
    117117        else: 
    118             self._post, self._files = http.QueryDict(''), datastructures.MultiValueDict() 
     118            self._post, self._files = http.QueryDict('', encoding=self._encoding), datastructures.MultiValueDict() 
    119119 
    120120    def _get_request(self): 
     
    126126        if not hasattr(self, '_get'): 
    127127            # The WSGI spec says 'QUERY_STRING' may be absent. 
    128             self._get = http.QueryDict(self.environ.get('QUERY_STRING', '')
     128            self._get = http.QueryDict(self.environ.get('QUERY_STRING', ''), encoding=self._encoding
    129129        return self._get 
    130130 
  • django/branches/unicode/django/http/__init__.py

    r5310 r5342  
    1919class HttpRequest(object): 
    2020    "A basic HTTP request" 
     21 
     22    # The encoding used in GET/POST dicts. None means use default setting. 
     23    _encoding = None 
     24 
    2125    def __init__(self): 
    2226        self.GET, self.POST, self.COOKIES, self.META, self.FILES = {}, {}, {}, {}, {} 
     
    4347    def is_secure(self): 
    4448        return os.environ.get("HTTPS") == "on" 
     49 
     50    def _set_encoding(self, val): 
     51        """ 
     52        Sets the encoding used for GET/POST accesses. 
     53        """ 
     54        self._encoding = val 
     55        if hasattr(self, '_get'): 
     56            self.GET.encoding = val 
     57        if hasattr(self, '_post'): 
     58            self.POST.encoding = val 
     59 
     60    def _get_encoding(self): 
     61        return self._encoding 
     62 
     63    encoding = property(_get_encoding, _set_encoding) 
    4564 
    4665def parse_file_upload(header_dict, post_data): 
  • django/branches/unicode/docs/unicode.txt

    r5340 r5342  
    338338for form data. If you need to change this for a particular form, you can set 
    339339the ``encoding`` attribute on the ``GET`` and ``POST`` data structures. For 
    340 example:: 
     340convenience, changing the ``encoding`` property on an ``HttpRequest`` instance 
     341does this for you. For example:: 
    341342 
    342343    def some_view(request): 
    343344        # We know that the data must be encoded as KOI8-R (for some reason). 
    344         request.GET.encoding = 'koi8-r' 
    345         request.POST.encoding = 'koi8-r' 
     345        request.encoding = 'koi8-r' 
    346346        ... 
     347 
     348You can even change the encoding after having accessed ``request.GET`` or 
     349``request.POST`` and all subsequent accesses will use the new encoding. 
    347350 
    348351It will typically be very rare that you would need to worry about changing the