Django

Code

Changeset 5091

Show
Ignore:
Timestamp:
04/26/07 08:30:48 (1 year ago)
Author:
mtredinnick
Message:

Fixed #4040 -- Changed uses of has_key() to "in". Slight performance
improvement and forward-compatible with future Python releases. Patch from Gary
Wilson.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/bin/profiling/gather_profile_stats.py

    r4265 r5091  
    2323            continue 
    2424        print "Processing %s" % f 
    25         if profiles.has_key(path)
     25        if path in profiles
    2626            profiles[path].add(prof) 
    2727        else: 
  • django/trunk/django/contrib/admin/templatetags/admin_modify.py

    r4692 r5091  
    7575 
    7676    def get_nodelist(cls, klass): 
    77         if not cls.nodelists.has_key(klass)
     77        if klass not in cls.nodelists
    7878            try: 
    7979                field_class_name = klass.__name__ 
  • django/trunk/django/contrib/admin/views/auth.py

    r4486 r5091  
    1818            new_user = manipulator.save(new_data) 
    1919            msg = _('The %(name)s "%(obj)s" was added successfully.') % {'name': 'user', 'obj': new_user} 
    20             if request.POST.has_key("_addanother")
     20            if "_addanother" in request.POST
    2121                request.user.message_set.create(message=msg) 
    2222                return HttpResponseRedirect(request.path) 
     
    3030        'title': _('Add user'), 
    3131        'form': form, 
    32         'is_popup': request.REQUEST.has_key('_popup')
     32        'is_popup': '_popup' in request.REQUEST
    3333        'add': True, 
    3434        'change': False, 
     
    6464        'title': _('Change password: %s') % escape(user.username), 
    6565        'form': form, 
    66         'is_popup': request.REQUEST.has_key('_popup')
     66        'is_popup': '_popup' in request.REQUEST
    6767        'add': True, 
    6868        'change': False, 
  • django/trunk/django/contrib/admin/views/decorators.py

    r5074 r5091  
    1313def _display_login_form(request, error_message=''): 
    1414    request.session.set_test_cookie() 
    15     if request.POST and request.POST.has_key('post_data')
     15    if request.POST and 'post_data' in request.POST
    1616        # User has failed login BUT has previously saved post data. 
    1717        post_data = request.POST['post_data'] 
     
    4949        if request.user.is_authenticated() and request.user.is_staff: 
    5050            # The user is valid. Continue to the admin page. 
    51             if request.POST.has_key('post_data')
     51            if 'post_data' in request.POST
    5252                # User must have re-authenticated through a different window 
    5353                # or tab. 
     
    5858 
    5959        # If this isn't already the login page, display it. 
    60         if not request.POST.has_key(LOGIN_FORM_KEY)
     60        if LOGIN_FORM_KEY not in request.POST
    6161            if request.POST: 
    6262                message = _("Please log in again, because your session has expired. Don't worry: Your submission has been saved.") 
     
    9191                login(request, user) 
    9292                # TODO: set last_login with an event. 
    93                 if request.POST.has_key('post_data')
     93                if 'post_data' in request.POST
    9494                    post_data = _decode_post_data(request.POST['post_data']) 
    95                     if post_data and not post_data.has_key(LOGIN_FORM_KEY)
     95                    if post_data and LOGIN_FORM_KEY not in post_data
    9696                        # overwrite request.POST with the saved post_data, and continue 
    9797                        request.POST = post_data 
  • django/trunk/django/contrib/admin/views/main.py

    r4616 r5091  
    258258            # Here, we distinguish between different save types by checking for 
    259259            # the presence of keys in request.POST. 
    260             if request.POST.has_key("_continue")
     260            if "_continue" in request.POST
    261261                request.user.message_set.create(message=msg + ' ' + _("You may edit it again below.")) 
    262                 if request.POST.has_key("_popup")
     262                if "_popup" in request.POST
    263263                    post_url_continue += "?_popup=1" 
    264264                return HttpResponseRedirect(post_url_continue % pk_value) 
    265             if request.POST.has_key("_popup")
     265            if "_popup" in request.POST
    266266                if type(pk_value) is str: # Quote if string, so JavaScript doesn't think it's a variable. 
    267267                    pk_value = '"%s"' % pk_value.replace('"', '\\"') 
    268268                return HttpResponse('<script type="text/javascript">opener.dismissAddAnotherPopup(window, %s, "%s");</script>' % \ 
    269269                    (pk_value, str(new_object).replace('"', '\\"'))) 
    270             elif request.POST.has_key("_addanother")
     270            elif "_addanother" in request.POST
    271271                request.user.message_set.create(message=msg + ' ' + (_("You may add another %s below.") % opts.verbose_name)) 
    272272                return HttpResponseRedirect(request.path) 
     
    289289        'title': _('Add %s') % opts.verbose_name, 
    290290        'form': form, 
    291         'is_popup': request.REQUEST.has_key('_popup')
     291        'is_popup': '_popup' in request.REQUEST
    292292        'show_delete': show_delete, 
    293293    }) 
     
    309309        raise PermissionDenied 
    310310 
    311     if request.POST and request.POST.has_key("_saveasnew")
     311    if request.POST and "_saveasnew" in request.POST
    312312        return add_stage(request, app_label, model_name, form_url='../../add/') 
    313313 
     
    344344 
    345345            msg = _('The %(name)s "%(obj)s" was changed successfully.') % {'name': opts.verbose_name, 'obj': new_object} 
    346             if request.POST.has_key("_continue")
     346            if "_continue" in request.POST
    347347                request.user.message_set.create(message=msg + ' ' + _("You may edit it again below.")) 
    348                 if request.REQUEST.has_key('_popup')
     348                if '_popup' in request.REQUEST
    349349                    return HttpResponseRedirect(request.path + "?_popup=1") 
    350350                else: 
    351351                    return HttpResponseRedirect(request.path) 
    352             elif request.POST.has_key("_saveasnew")
     352            elif "_saveasnew" in request.POST
    353353                request.user.message_set.create(message=_('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % {'name': opts.verbose_name, 'obj': new_object}) 
    354354                return HttpResponseRedirect("../%s/" % pk_value) 
    355             elif request.POST.has_key("_addanother")
     355            elif "_addanother" in request.POST
    356356                request.user.message_set.create(message=msg + ' ' + (_("You may add another %s below.") % opts.verbose_name)) 
    357357                return HttpResponseRedirect("../add/") 
     
    393393        'object_id': object_id, 
    394394        'original': manipulator.original_object, 
    395         'is_popup': request.REQUEST.has_key('_popup')
     395        'is_popup': '_popup' in request.REQUEST
    396396    }) 
    397397    return render_change_form(model, manipulator, c, change=True) 
     
    559559        except ValueError: 
    560560            self.page_num = 0 
    561         self.show_all = request.GET.has_key(ALL_VAR) 
    562         self.is_popup = request.GET.has_key(IS_POPUP_VAR) 
     561        self.show_all = ALL_VAR in request.GET 
     562        self.is_popup = IS_POPUP_VAR in request.GET 
    563563        self.params = dict(request.GET.items()) 
    564         if self.params.has_key(PAGE_VAR)
     564        if PAGE_VAR in self.params
    565565            del self.params[PAGE_VAR] 
    566         if self.params.has_key(ERROR_FLAG)
     566        if ERROR_FLAG in self.params
    567567            del self.params[ERROR_FLAG] 
    568568 
     
    595595                    del p[k] 
    596596        for k, v in new_params.items(): 
    597             if p.has_key(k) and v is None: 
     597            if k in p and v is None: 
    598598                del p[k] 
    599599            elif v is not None: 
     
    657657        else: 
    658658            order_field, order_type = ordering[0], 'asc' 
    659         if params.has_key(ORDER_VAR)
     659        if ORDER_VAR in params
    660660            try: 
    661661                field_name = lookup_opts.admin.list_display[int(params[ORDER_VAR])] 
     
    675675            except (IndexError, ValueError): 
    676676                pass # Invalid ordering specified. Just use the default. 
    677         if params.has_key(ORDER_TYPE_VAR) and params[ORDER_TYPE_VAR] in ('asc', 'desc'): 
     677        if ORDER_TYPE_VAR in params and params[ORDER_TYPE_VAR] in ('asc', 'desc'): 
    678678            order_type = params[ORDER_TYPE_VAR] 
    679679        return order_field, order_type 
     
    683683        lookup_params = self.params.copy() # a dictionary of the query string 
    684684        for i in (ALL_VAR, ORDER_VAR, ORDER_TYPE_VAR, SEARCH_VAR, IS_POPUP_VAR): 
    685             if lookup_params.has_key(i)
     685            if i in lookup_params
    686686                del lookup_params[i] 
    687687 
  • django/trunk/django/contrib/comments/templatetags/comments.py

    r5072 r5091  
    117117 
    118118        if not self.free: 
    119             if context.has_key('user') and context['user'].is_authenticated(): 
     119            if 'user' in context and context['user'].is_authenticated(): 
    120120                user_id = context['user'].id 
    121121                context['user_can_moderate_comments'] = Comment.objects.user_is_moderator(context['user']) 
  • django/trunk/django/contrib/comments/views/comments.py

    r4486 r5091  
    218218    # If user gave correct username/password and wasn't already logged in, log them in 
    219219    # so they don't have to enter a username/password again. 
    220     if manipulator.get_user() and not manipulator.get_user().is_authenticated() and new_data.has_key('password') and manipulator.get_user().check_password(new_data['password']): 
     220    if manipulator.get_user() and not manipulator.get_user().is_authenticated() and 'password' in new_data and manipulator.get_user().check_password(new_data['password']): 
    221221        from django.contrib.auth import login 
    222222        login(request, manipulator.get_user()) 
    223     if errors or request.POST.has_key('preview')
     223    if errors or 'preview' in request.POST
    224224        class CommentFormWrapper(oldforms.FormWrapper): 
    225225            def __init__(self, manipulator, new_data, errors, rating_choices): 
     
    245245            'rating_choices': rating_choices, 
    246246        }, context_instance=RequestContext(request)) 
    247     elif request.POST.has_key('post')
     247    elif 'post' in request.POST
    248248        # If the IP is banned, mail the admins, do NOT save the comment, and 
    249249        # serve up the "Thanks for posting" page as if the comment WAS posted. 
     
    299299    manipulator = PublicFreeCommentManipulator() 
    300300    errors = manipulator.get_validation_errors(new_data) 
    301     if errors or request.POST.has_key('preview')
     301    if errors or 'preview' in request.POST
    302302        comment = errors and '' or manipulator.get_comment(new_data) 
    303303        return render_to_response('comments/free_preview.html', { 
     
    308308            'hash': security_hash, 
    309309        }, context_instance=RequestContext(request)) 
    310     elif request.POST.has_key('post')
     310    elif 'post' in request.POST
    311311        # If the IP is banned, mail the admins, do NOT save the comment, and 
    312312        # serve up the "Thanks for posting" page as if the comment WAS posted. 
     
    331331    """ 
    332332    obj = None 
    333     if request.GET.has_key('c')
     333    if 'c' in request.GET
    334334        content_type_id, object_id = request.GET['c'].split(':') 
    335335        try: 
  • django/trunk/django/contrib/sitemaps/views.py

    r4265 r5091  
    1717    maps, urls = [], [] 
    1818    if section is not None: 
    19         if not sitemaps.has_key(section)
     19        if section not in sitemaps
    2020            raise Http404("No sitemap available for section: %r" % section) 
    2121        maps.append(sitemaps[section]) 
  • django/trunk/django/core/cache/backends/simple.py

    r4265 r5091  
    5353 
    5454    def has_key(self, key): 
    55         return self._cache.has_key(key) 
     55        return key in self._cache 
    5656 
    5757    def _cull(self): 
  • django/trunk/django/core/handlers/modpython.py

    r4265 r5091  
    4343    def is_secure(self): 
    4444        # Note: modpython 3.2.10+ has req.is_https(), but we need to support previous versions 
    45         return self._req.subprocess_env.has_key('HTTPS') and self._req.subprocess_env['HTTPS'] == 'on' 
     45        return 'HTTPS' in self._req.subprocess_env and self._req.subprocess_env['HTTPS'] == 'on' 
    4646 
    4747    def _load_post_and_files(self): 
    4848        "Populates self._post and self._files" 
    49         if self._req.headers_in.has_key('content-type') and self._req.headers_in['content-type'].startswith('multipart'): 
     49        if 'content-type' in self._req.headers_in and self._req.headers_in['content-type'].startswith('multipart'): 
    5050            self._post, self._files = http.parse_file_upload(self._req.headers_in, self.raw_post_data) 
    5151        else: 
  • django/trunk/django/core/handlers/wsgi.py

    r4265 r5091  
    104104 
    105105    def is_secure(self): 
    106         return self.environ.has_key('HTTPS') and self.environ['HTTPS'] == 'on' 
     106        return 'HTTPS' in self.environ and self.environ['HTTPS'] == 'on' 
    107107 
    108108    def _load_post_and_files(self): 
  • django/trunk/django/core/management.py

    r4989 r5091  
    315315            output.append('%s %s;' % (style.SQL_KEYWORD('DROP TABLE'), 
    316316                style.SQL_TABLE(backend.quote_name(model._meta.db_table)))) 
    317             if backend.supports_constraints and references_to_delete.has_key(model)
     317            if backend.supports_constraints and model in references_to_delete
    318318                for rel_class, f in references_to_delete[model]: 
    319319                    table = rel_class._meta.db_table 
     
    844844                comment_notes.append('Field renamed because it was a Python reserved word.') 
    845845 
    846             if relations.has_key(i)
     846            if i in relations
    847847                rel_to = relations[i][1] == table_name and "'self'" or table2model(relations[i][1]) 
    848848                field_type = 'ForeignKey(%s' % rel_to 
     
    15511551    except IndexError: 
    15521552        parser.print_usage_and_exit() 
    1553     if not action_mapping.has_key(action)
     1553    if action not in action_mapping
    15541554        print_error("Your action, %r, was invalid." % action, argv[0]) 
    15551555 
  • django/trunk/django/core/servers/basehttp.py

    r4265 r5091  
    209209        return 'http' 
    210210 
    211 _hoppish = { 
     211_hop_headers = { 
    212212    'connection':1, 'keep-alive':1, 'proxy-authenticate':1, 
    213213    'proxy-authorization':1, 'te':1, 'trailers':1, 'transfer-encoding':1, 
    214214    'upgrade':1 
    215 }.has_key 
     215} 
    216216 
    217217def is_hop_by_hop(header_name): 
    218218    """Return true if 'header_name' is an HTTP/1.1 "Hop-by-Hop" header""" 
    219     return _hoppish(header_name.lower()) 
     219    return header_name.lower() in _hop_headers 
    220220 
    221221class ServerHandler(object): 
     
    335335        Subclasses can extend this to add other defaults. 
    336336        """ 
    337         if not self.headers.has_key('Content-Length')
     337        if 'Content-Length' not in self.headers
    338338            self.set_content_length() 
    339339 
     
    369369            if self.client_is_modern(): 
    370370                self._write('HTTP/%s %s\r\n' % (self.http_version,self.status)) 
    371                 if not self.headers.has_key('Date')
     371                if 'Date' not in self.headers
    372372                    self._write( 
    373373                        'Date: %s\r\n' % time.asctime(time.gmtime(time.time())) 
    374374                    ) 
    375                 if self.server_software and not self.headers.has_key('Server')
     375                if self.server_software and 'Server' not in self.headers
    376376                    self._write('Server: %s\r\n' % self.server_software) 
    377377        else: 
  • django/trunk/django/core/validators.py

    r4704 r5091  
    285285 
    286286    def __call__(self, field_data, all_data): 
    287         if all_data.has_key(self.other_field) and all_data[self.other_field] == self.other_value: 
     287        if self.other_field in all_data and all_data[self.other_field] == self.other_value: 
    288288            for v in self.validator_list: 
    289289                v(field_data, all_data) 
     
    323323 
    324324    def __call__(self, field_data, all_data): 
    325         if all_data.has_key(self.other_field) and all_data[self.other_field] == self.other_value and not field_data: 
     325        if self.other_field in all_data and all_data[self.other_field] == self.other_value and not field_data: 
    326326            raise ValidationError(self.error_message) 
    327327 
     
    336336 
    337337    def __call__(self, field_data, all_data): 
    338         if all_data.has_key(self.other_field) and all_data[self.other_field] != self.other_value and not field_data: 
     338        if self.other_field in all_data and all_data[self.other_field] != self.other_value and not field_data: 
    339339            raise ValidationError(self.error_message) 
    340340 
  • django/trunk/django/db/backends/mysql_old/base.py

    r5076 r5091  
    5454 
    5555    def __getattr__(self, attr): 
    56         if self.__dict__.has_key(attr)
     56        if attr in self.__dict__
    5757            return self.__dict__[attr] 
    5858        else: 
  • django/trunk/django/db/backends/postgresql/base.py

    r5076 r5091  
    4949 
    5050    def __getattr__(self, attr): 
    51         if self.__dict__.has_key(attr)
     51        if attr in self.__dict__
    5252            return self.__dict__[attr] 
    5353        else: 
  • django/trunk/django/db/backends/util.py

    r4265 r5091  
    3434 
    3535    def __getattr__(self, attr): 
    36         if self.__dict__.has_key(attr)
     36        if attr in self.__dict__
    3737            return self.__dict__[attr] 
    3838        else: 
  • django/trunk/django/db/models/fields/generic.py

    r4752 r5091  
    3838        # Handle initalizing an object with the generic FK instaed of  
    3939        # content-type/object-id fields.         
    40         if kwargs.has_key(self.name)
     40        if self.name in kwargs
    4141            value = kwargs.pop(self.name) 
    4242            kwargs[self.ct_field] = self.get_content_type(value) 
  • django/trunk/django/db/models/fields/__init__.py

    r4954 r5091  
    780780        kwargs.setdefault('validator_list', []).append(validators.isSlug) 
    781781        # Set db_index=True unless it's been set manually. 
    782         if not kwargs.has_key('db_index')
     782        if 'db_index' not in kwargs
    783783            kwargs['db_index'] = True 
    784784        Field.__init__(self, *args, **kwargs) 
  • django/trunk/django/db/models/fields/related.py

    r4611 r5091  
    475475        kwargs['verbose_name'] = kwargs.get('verbose_name', '') 
    476476 
    477         if kwargs.has_key('edit_inline_type')
     477        if 'edit_inline_type' in kwargs
    478478            import warnings 
    479479            warnings.warn("edit_inline_type is deprecated. Use edit_inline instead.") 
     
    568568        kwargs['verbose_name'] = kwargs.get('verbose_name', '') 
    569569 
    570         if kwargs.has_key('edit_inline_type')
     570        if 'edit_inline_type' in kwargs
    571571            import warnings 
    572572            warnings.warn("edit_inline_type is deprecated. Use edit_inline instead.") 
  • django/trunk/django/db/models/loading.py

    r4265 r5091  
    104104        model_name = model._meta.object_name.lower() 
    105105        model_dict = _app_models.setdefault(app_label, {}) 
    106         if model_dict.has_key(model_name)
     106        if model_name in model_dict
    107107            # The same model may be imported via different paths (e.g. 
    108108            # appname.models and project.appname.models). We use the source 
  • django/trunk/django/db/models/options.py

    r4752 r5091  
    141141        follow = {} 
    142142        for f in self.fields + self.many_to_many + self.get_all_related_objects(): 
    143             if override and override.has_key(f.name)
     143            if override and f.name in override
    144144                child_override = override[f.name] 
    145145            else: 
     
    183183        if not hasattr(self, '_field_types'): 
    184184            self._field_types = {} 
    185         if not self._field_types.has_key(field_type)
     185        if field_type not in self._field_types
    186186            try: 
    187187                # First check self.fields. 
  • django/trunk/django/db/transaction.py

    r4265 r5091  
    4747    """ 
    4848    thread_ident = thread.get_ident() 
    49     if state.has_key(thread_ident) and state[thread_ident]: 
     49    if thread_ident in state and state[thread_ident]: 
    5050        state[thread_ident].append(state[thread_ident][-1]) 
    5151    else: 
    5252        state[thread_ident] = [] 
    5353        state[thread_ident].append(settings.TRANSACTIONS_MANAGED) 
    54     if not dirty.has_key(thread_ident)
     54    if thread_ident not in dirty
    5555        dirty[thread_ident] = False 
    5656 
     
    6262    """ 
    6363    thread_ident = thread.get_ident() 
    64     if state.has_key(thread_ident) and state[thread_ident]: 
     64    if thread_ident in state and state[thread_ident]: 
    6565        del state[thread_ident][-1] 
    6666    else: 
     
    8585    """ 
    8686    thread_ident = thread.get_ident() 
    87     if dirty.has_key(thread_ident)
     87    if thread_ident in dirty
    8888        dirty[thread_ident] = True 
    8989    else: 
     
    9797    """ 
    9898    thread_ident = thread.get_ident() 
    99     if dirty.has_key(thread_ident)
     99    if thread_ident in dirty
    100100        dirty[thread_ident] = False 
    101101    else: 
     
    107107    """ 
    108108    thread_ident = thread.get_ident() 
    109     if state.has_key(thread_ident)
     109    if thread_ident in state
    110110        if state[thread_ident]: 
    111111            return state[thread_ident][-1] 
  • django/trunk/django/http/__init__.py

    r4866 r5091  
    3030    def __getitem__(self, key): 
    3131        for d in (self.POST, self.GET): 
    32             if d.has_key(key)
     32            if key in d
    3333                return d[key] 
    3434        raise KeyError, "%s not found in either POST or GET" % key 
    3535 
    3636    def has_key(self, key): 
    37         return self.GET.has_key(key) or self.POST.has_key(key) 
     37        return key in self.GET or key in self.POST 
    3838 
    3939    def get_full_path(self): 
     
    5858            # or {'name': 'blah'} for POST fields 
    5959            # We assume all uploaded files have a 'filename' set. 
    60             if name_dict.has_key('filename')
     60            if 'filename' in name_dict
    6161                assert type([]) != type(submessage.get_payload()), "Nested MIME messages are not supported" 
    6262                if not name_dict['filename'].strip(): 
     
    6767                FILES.appendlist(name_dict['name'], { 
    6868                    'filename': filename, 
    69                     'content-type': (submessage.has_key('Content-Type') and submessage['Content-Type'] or None)
     69                    'content-type': 'Content-Type' in submessage and submessage['Content-Type'] or None
    7070                    'content': submessage.get_payload(), 
    7171                }) 
  • django/trunk/django/middleware/common.py

    r5043 r5091  
    2626 
    2727        # Check for denied User-Agents 
    28         if request.META.has_key('HTTP_USER_AGENT')
     28        if 'HTTP_USER_AGENT' in request.META
    2929            for user_agent_regex in settings.DISALLOWED_USER_AGENTS: 
    3030                if user_agent_regex.search(request.META['HTTP_USER_AGENT']): 
  • django/trunk/django/newforms/forms.py

    r4925 r5091  
    245245        attrs = attrs or {} 
    246246        auto_id = self.auto_id 
    247         if auto_id and not attrs.has_key('id') and not widget.attrs.has_key('id')
     247        if auto_id and 'id' not in attrs and 'id' not in widget.attrs
    248248            attrs['id'] = auto_id 
    249249        if not self.form.is_bound: 
  • django/trunk/django/newforms/widgets.py

    r5088 r5091  
    231231 
    232232    def tag(self): 
    233         if self.attrs.has_key('id')
     233        if 'id' in self.attrs
    234234            self.attrs['id'] = '%s_%s' % (self.attrs['id'], self.index) 
    235235        final_attrs = dict(self.attrs, type='radio', name=self.name, value=self.choice_value) 
     
    277277    def render(self, name, value, attrs=None, choices=()): 
    278278        if value is None: value = [] 
    279         has_id = attrs and attrs.has_key('id') 
     279        has_id = attrs and 'id' in attrs 
    280280        final_attrs = self.build_attrs(attrs, name=name) 
    281281        output = [u'<ul>'] 
  • django/trunk/django/oldforms/__init__.py

    r4896 r5091  
    330330    def convert_post_data(self, new_data): 
    331331        name = self.get_member_name() 
    332         if new_data.has_key(self.field_name)
     332        if self.field_name in new_data
    333333            d = new_data.getlist(self.field_name) 
    334334            try: 
  • django/trunk/django/template/context.py

    r4480 r5091  
    3636        "Get a variable's value, starting at the current context and going upward" 
    3737        for d in self.dicts: 
    38             if d.has_key(key)
     38            if key in d
    3939                return d[key] 
    4040        raise KeyError(key) 
     
    4646    def has_key(self, key): 
    4747        for d in self.dicts: 
    48             if d.has_key(key)
     48            if key in d
    4949                return True 
    5050        return False 
     
    5555    def get(self, key, otherwise=None): 
    5656        for d in self.dicts: 
    57             if d.has_key(key)
     57            if key in d
    5858                return d[key] 
    5959        return otherwise 
  • django/trunk/django/template/defaulttags.py

    r5077 r5091  
    8888    def render(self, context): 
    8989        nodelist = NodeList() 
    90         if context.has_key('forloop')
     90        if 'forloop' in context
    9191            parentloop = context['forloop'] 
    9292        else: 
     
    134134 
    135135    def render(self, context): 
    136         if context.has_key('forloop') and context['forloop']['first']: 
     136        if 'forloop' in context and context['forloop']['first']: 
    137137            self._last_seen = None 
    138138        try: 
     
    433433        if not hasattr(parser, '_namedCycleNodes'): 
    434434            raise TemplateSyntaxError("No named cycles in template: '%s' is not defined" % name) 
    435         if not parser._namedCycleNodes.has_key(name)
     435        if name not in parser._namedCycleNodes
    436436            raise TemplateSyntaxError("Named cycle '%s' does not exist" % name) 
    437437        return parser._namedCycleNodes[name] 
     
    912912        raise TemplateSyntaxError, "'templatetag' statement takes one argument" 
    913913    tag = bits[1] 
    914     if not TemplateTagNode.mapping.has_key(tag)
     914    if tag not in TemplateTagNode.mapping
    915915        raise TemplateSyntaxError, "Invalid templatetag argument: '%s'. Must be one of: %s" % \ 
    916916            (tag, TemplateTagNode.mapping.keys()) 
  • django/trunk/django/template/__init__.py

    r5067 r5091  
    339339 
    340340    def find_filter(self, filter_name): 
    341         if self.filters.has_key(filter_name)
     341        if filter_name in self.filters
    342342            return self.filters[filter_name] 
    343343        else: 
  • django/trunk/django/utils/datastructures.py

    r5069 r5091  
    4343    def has_key(self, key): 
    4444        for dict in self.dicts: 
    45             if dict.has_key(key)
     45            if key in dict
    4646                return True 
    4747        return False 
  • django/trunk/django/utils/functional.py

    r4265 r5091  
    4343                return self.__dispatch[type(res)][funcname](res, *args, **kw) 
    4444 
    45             if not self.__dispatch.has_key(klass)
     45            if klass not in self.__dispatch
    4646                self.__dispatch[klass] = {} 
    4747            self.__dispatch[klass][funcname] = func 
  • django/trunk/django/utils/translation/trans_real.py

    r4905 r5091  
    200200    """ 
    201201    global _active 
    202     if _active.has_key(currentThread())
     202    if currentThread() in _active
    203203        del _a