Contact: fumanchu@aminus.org

Log in as guest/dejavu to create tickets

I think I've seen this ORM somewhere before...

Changeset 2

Show
Ignore:
Timestamp:
09/29/04 22:13:11
Author:
fumanchu
Message:

Allow Unit properties to be set in Unit.init() by **kwargs.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/__init__.py

    r1 r2  
    206206    sequencer = UnitSequencerInteger() 
    207207     
    208     def __init__(self): 
     208    def __init__(self, **kwargs): 
    209209        # Copy the class _properties dict into self. 
    210210        self._properties = self.__class__._properties.copy() 
     
    213213        self.dirty = False 
    214214        self.temporary = False 
     215         
     216        for k, v in kwargs: 
     217            setattr(self, k, v) 
    215218     
    216219    def set_property(cls, key, type=unicode, index=False, 
  • trunk/engines.py

    r1 r2  
    4343    _IDs = None 
    4444     
    45     def __init__(self, Type=None): 
     45    def __init__(self, **kwargs): 
    4646        dejavu.Unit.__init__(self) 
    4747        self._IDs = sets.Set() 
    4848        self._mutex = threading.RLock() 
    49         self.Type = Type 
     49         
     50        for k, v in kwargs: 
     51            setattr(self, k, v) 
    5052     
    5153    def acquire(self): 
     
    124126    """A Rule for Unit Engines.""" 
    125127     
    126     def __init__(self, Operation=None, SetID=None, Operand=None): 
    127         """(Operation, SetID, Operand=(Type | logic.Expression | otherSet) 
     128    def __init__(self, **kwargs): 
     129        """kw: Operation, SetID, Operand=(Type | logic.Expression | otherSet) 
    128130         
    129131        Expressions: 
     
    156158        """ 
    157159        dejavu.Unit.__init__(self) 
    158         self.Operation = Operation 
    159         self.SetID = SetID 
    160         if Operation == 'FILTER': 
    161             if not isinstance(Operand, (str, unicode)): 
    162                 Operand = pickle.dumps(Operand) 
    163         self.Operand = Operand 
     160         
     161        if kwargs.get('Operation', '') == 'FILTER': 
     162            if not isinstance(kwargs.get('Operand'), (str, unicode)): 
     163                kwargs['Operand'] = pickle.dumps(kwargs['Operand']) 
     164         
     165        for k, v in kwargs: 
     166            setattr(self, k, v) 
    164167     
    165168    def __repr__(self): 
     
    192195    """A factory for Unit Collections.""" 
    193196     
    194     def __init__(self): 
     197    def __init__(self, **kwargs): 
    195198        dejavu.Unit.__init__(self) 
    196199        self.Created = datetime.datetime.today() 
    197200        self.Owner = u'' 
     201         
     202        for k, v in kwargs: 
     203            setattr(self, k, v) 
    198204     
    199205    def on_forget(self): 
     
    238244                except IndexError: 
    239245                    SetID = 1 
    240             newRule = UnitEngineRule(Operation, SetID, Operand) 
     246            newRule = UnitEngineRule(Operation=Operation, SetID=SetID, 
     247                                     Operand=Operand) 
    241248         
    242249        try: 
     
    345352        else: 
    346353            # Create a new set. 
    347             B = UnitCollection(A.Type) 
     354            B = UnitCollection(Type=A.Type) 
    348355            self.sets[operand] = B 
    349356        B.empty = A.empty 
     
    358365    def visit_CREATE(self, setID, operand): 
    359366        """Create an empty set. The next instruction is responsible to fill it.""" 
    360         newset = UnitCollection(operand) 
     367        newset = UnitCollection(Type=operand) 
    361368        newset.empty = True 
    362369        self.sets[setID] = newset 
  • trunk/readme.py

    r1 r2  
    5050    a = A() 
    5151    b = B() 
    52     a.add(b) 
    53     Since the keys are known, take whichever is None and supply it 
     52    a.add(b)    <-- 
     53    Since the related keys are known, take whichever is None and supply it 
    5454    from the other Unit instance. 
    55552. Convenience function for retrieving all far classes from an association 
    5656    and treating them as a list, with len, slicing, etc. 
    57 3. Allow Unit properties to be set in __init__() by **kwargs. 
    58     SM's should still go the manual route, but app developers could 
    59     use it to good effect. 
    60 4. Batched triggers: 
     573. Batched triggers: 
    6158    Some pre/post triggers should be delayed until end of request, 
    6259    particularly those which affect related Units. Also on_forget(), etc. 
     
    7067        3. Pre-forget/post-forget. 
    7168        4. on_flush (end of request) 
    72 5. For UnitProperty types which are mutable (like dicts), we currently have to 
     694. For UnitProperty types which are mutable (like dicts), we currently have to 
    7370    explicitly set dirty, because dirty only sets automatically on rebind, 
    7471    not mutate. Fix if possible, or doc the heck out of it. 
     
    9087""" 
    9188 
    92 version = "1.2.3
     89version = "1.2.4
    9390 
    9491changelog = """ 
     921.2.4 (): 
     93    1. Allow Unit properties to be set in __init__() by **kwargs. 
     94        SM's should still go the manual route, but app developers could 
     95        use it to good effect. 
     96 
    95971.2.3 (9/3/04): 
    9698    1. Decoupled construction of stores from arena._load() into add_store().