Ticket #8092: request.__getitem__.patch

File request.__getitem__.patch, 1.6 KB (added by Uz, 16 years ago)

removes getitem contains and has_key from HttpRequest

  • django/http/__init__.py

     
    3939            (pformat(self.GET), pformat(self.POST), pformat(self.COOKIES),
    4040            pformat(self.META))
    4141
    42     def __getitem__(self, key):
    43         for d in (self.POST, self.GET):
    44             if key in d:
    45                 return d[key]
    46         raise KeyError, "%s not found in either POST or GET" % key
    47 
    48     def has_key(self, key):
    49         return key in self.GET or key in self.POST
    50 
    51     __contains__ = has_key
    52 
    5342    def get_host(self):
    5443        """Returns the HTTP host using the environment or request headers."""
    5544        # We try three options, in order of decreasing preference.
  • docs/request_response.txt

     
    170170Methods
    171171-------
    172172
    173 ``__getitem__(key)``
    174    Returns the GET/POST value for the given key, checking POST first, then
    175    GET. Raises ``KeyError`` if the key doesn't exist.
    176 
    177    This lets you use dictionary-accessing syntax on an ``HttpRequest``
    178    instance. Example: ``request["foo"]`` would return ``True`` if either
    179    ``request.POST`` or ``request.GET`` had a ``"foo"`` key.
    180 
    181 ``has_key()``
    182    Returns ``True`` or ``False``, designating whether ``request.GET`` or
    183    ``request.POST`` has the given key.
    184 
    185173``get_host()``
    186174   **New in Django development version**
    187175
Back to Top