Django

Code

Changeset 1712

Show
Ignore:
Timestamp:
12/16/05 17:34:44 (3 years ago)
Author:
adrian
Message:

magic-removal: Negligible change to 'set' import

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/magic-removal/django/core/management.py

    r1709 r1712  
    77from optparse import OptionParser 
    88 
    9 #HACK: for Python2.3  
    10 if not hasattr(__builtins__,'set'): 
     9# For Python 2.3 
     10if not hasattr(__builtins__, 'set'): 
    1111    from sets import Set as set 
    1212 
  • django/branches/magic-removal/django/db/models/base.py

    r1708 r1712  
    44from django.db.models.related import RelatedObject 
    55from django.db.models.manager import Manager, ManagerDescriptor 
    6 from django.db.models.query import orderlist2sql  
     6from django.db.models.query import orderlist2sql 
    77from django.db.models.options import Options 
    88from django.db import connection, backend 
     
    1515import sys 
    1616 
    17 #HACK: for Python2.3  
    18 if not hasattr(__builtins__,'set'): 
     17# For Python 2.3 
     18if not hasattr(__builtins__, 'set'): 
    1919    from sets import Set as set 
    2020 
     
    4242        # Create the class, because we need it to use in currying. 
    4343        new_class = type.__new__(cls, name, bases, { '__module__' : attrs.pop('__module__') }) 
    44          
     44 
    4545        opts = Options( 
    4646            module_name = meta_attrs.pop('module_name', get_module_name(name)), 
     
    6666            raise TypeError, "'class META' got invalid attribute(s): %s" % ','.join(meta_attrs.keys()) 
    6767        new_class.add_to_class('_meta', opts) 
    68          
     68 
    6969        # Create the DoesNotExist exception. 
    7070        new_class.DoesNotExist = types.ClassType('DoesNotExist', (ObjectDoesNotExist,), {}) 
    71          
     71 
    7272        # Figure out the app_label by looking one level up. 
    7373        #FIXME: wrong for nested model modules 
     
    7878        # Cache the app label. 
    7979        opts.app_label = app_label 
    80          
     80 
    8181        #Add all attributes to the class 
    8282        #fields, managers = [], [] 
    8383        for obj_name, obj in attrs.items(): 
    8484            new_class.add_to_class(obj_name, obj) 
    85          
     85 
    8686        if not hasattr(new_class, '_default_manager'): 
    8787            # Create the default manager, if needed. 
     
    8989                raise ValueError, "Model %s must specify a custom Manager, because it has a field named 'objects'" % name 
    9090            new_class.add_to_class('objects',  Manager()) 
    91          
     91 
    9292        # Give the class a docstring -- its definition. 
    9393        if new_class.__doc__ is None: 
     
    9696        if hasattr(new_class, 'get_absolute_url'): 
    9797            new_class.get_absolute_url = curry(get_absolute_url, opts, new_class.get_absolute_url) 
    98              
     98 
    9999        opts._prepare() 
    100100        new_class._prepare() 
    101          
     101 
    102102        # If the db_table wasn't provided, use the app_label + module_name. 
    103103        if not opts.db_table: 
    104104            opts.db_table = "%s_%s" % (app_label, opts.module_name) 
    105          
     105 
    106106        # Populate the _MODELS member on the module the class is in. 
    107107        app_package.__dict__.setdefault('_MODELS', []).append(new_class) 
    108          
    109      
     108 
     109 
    110110        return new_class 
    111      
     111 
    112112def cmp_cls(x, y): 
    113113    for field in x._meta.fields: 
     
    121121class Model(object): 
    122122    __metaclass__ = ModelBase 
    123      
     123 
    124124    def add_to_class(cls, name, attribute): 
    125125        if hasattr(attribute, 'contribute_to_class'): 
     
    128128            setattr(cls, name, attribute) 
    129129    add_to_class = classmethod(add_to_class) 
    130      
     130 
    131131    AddManipulator = ManipulatorDescriptor('AddManipulator', ModelAddManipulator) 
    132     ChangeManipulator = ManipulatorDescriptor('ChangeManipulator', ModelChangeManipulator)     
    133      
     132    ChangeManipulator = ManipulatorDescriptor('ChangeManipulator', ModelChangeManipulator) 
     133 
    134134    def __repr__(self): 
    135135        return '<%s object>' % self.__class__.__name__ 
     
    215215            cls.get_next_in_order = curry(cls.__get_next_or_previous_in_order, is_next=True) 
    216216            cls.get_previous_in_order = curry(cls.__get_next_or_previous_in_order, is_next=False) 
    217          
     217 
    218218        RelatedField.do_pending_lookups(cls) 
    219219 
     
    278278    def __collect_sub_objects(self, seen_objs, ignore_objs): 
    279279        pk_val = self.__get_pk_val() 
    280          
    281         key = (self.__class__, pk_val)         
    282          
     280 
     281        key = (self.__class__, pk_val) 
     282 
    283283        if key in seen_objs or key in ignore_objs: 
    284284            return 
    285285        seen_objs[key] = self 
    286          
     286 
    287287        for related in self._meta.get_all_related_objects(): 
    288288            rel_opts_name = related.get_method_name_part() 
     
    302302        ignore_objects = \ 
    303303            ignore_objects and dict([ (o.__class,o.__get_pk_val) for o in ignore_objects ]) or {} 
    304          
     304 
    305305        seen_objs = {} 
    306306        self.__collect_sub_objects(seen_objs, ignore_objects) 
    307          
     307 
    308308        seen_cls = set([cls for cls,pk in seen_objs.keys()]) 
    309309        cls_order = list(seen_cls) 
     
    312312        seen_tups = [ (cls, pk_val, instance) for (cls, pk_val),instance in seen_objs.items() ] 
    313313        seen_tups.sort(lambda x,y: cmp(cls_order.index(x[0]), cls_order.index(y[0]))) 
    314          
     314 
    315315        cursor = connection.cursor() 
    316      
     316 
    317317        for cls, pk_val, instance in seen_tups: 
    318          
     318 
    319319            # Run any pre-delete hooks. 
    320320            if hasattr(instance, '_pre_delete'): 
    321321                instance._pre_delete() 
    322              
     322 
    323323            for related in cls._meta.get_all_related_many_to_many_objects(): 
    324324                cursor.execute("DELETE FROM %s WHERE %s=%%s" % \ 
     
    331331                    backend.quote_name(cls._meta.object_name.lower() + '_id')), 
    332332                    [pk_val]) 
    333                      
     333 
    334334            for field in cls._meta.fields: 
    335335                if field.rel and field.null and field.rel.to in seen_cls: 
    336336                    cursor.execute("UPDATE %s SET %s = NULL WHERE %s =%%s" % \ 
    337                                    ( backend.quote_name(cls._meta.db_table),  
     337                                   ( backend.quote_name(cls._meta.db_table), 
    338338                                     backend.quote_name(field.column), 
    339339                                     backend.quote_name(cls._meta.pk.column)), 
    340340                                   [pk_val] ) 
    341                
     341 
    342342        seen_tups.reverse() 
    343          
     343 
    344344        for cls, pk_val, instance in seen_tups: 
    345345            cursor.execute("DELETE FROM %s WHERE %s=%%s" % \ 
    346346                (backend.quote_name(cls._meta.db_table), backend.quote_name(cls._meta.pk.column)), 
    347347                [pk_val]) 
    348                  
    349              
     348 
    350349            setattr(self, cls._meta.pk.attname, None) 
    351350            for f in cls._meta.fields: 
     
    359358            if hasattr(instance, '_post_delete'): 
    360359                instance._post_delete() 
    361              
     360 
    362361        connection.commit() 
    363362 
    364363    delete.alters_data = True 
    365364 
    366      
     365 
    367366    def __get_FIELD_display(self, field): 
    368367        value = getattr(self, field.attname) 
     
    573572 
    574573 
    575      
     574 
    576575 
    577576