Contact: fumanchu@aminus.org

Log in as guest/dejavu to create tickets

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

Changeset 29

Show
Ignore:
Timestamp:
11/19/04 06:55:00
Author:
fumanchu
Message:

1. Fixed bug in storeado with hints:Size of wrong type.
2. UnitProperty? now supplies .key from local attribute name when specified in class body (see MetaUnit? init).
3. Signature of UnitProperty? changed to (type, index, hints, key).
4. Minor bug in test_codewalk.

Files:

Legend:

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

    r28 r29  
    111111    post = None 
    112112     
    113     def __init__(self, key, type=unicode, index=False, hints={}): 
    114         self.key = key 
     113    def __init__(self, type=unicode, index=False, hints={}, key=None): 
    115114        self.type = type 
    116115        self.index = index 
    117116        self.hints = hints 
     117        self.key = key 
    118118     
    119119    def __get__(self, unit, unitclass=None): 
     
    167167        for key, val in dct.iteritems(): 
    168168            if isinstance(val, UnitProperty): 
     169                # If the UnitProperty.key is None, 
     170                # supply it from the attribute name (key). 
     171                if val.key is None: 
     172                    val.key = key 
    169173                props[key] = val 
    170174         
     
    208212    sequencer = UnitSequencerInteger() 
    209213     
     214    # The default ID type is int. If you wish to use a different type for 
     215    # the ID's of a subclass of Unit, just overwrite ID, e.g.: 
     216    #     ID = UnitProperty(unicode, index=True) 
     217    #       or 
     218    #     UnitSubclass.set_property('ID', unicode, index=True) 
     219    #       or even 
     220    #     UnitSubclass.ID.type = unicode 
     221    # You will probably also want to override Unit.sequencer for the class. 
     222    ID = UnitProperty(int, index=True) 
     223     
    210224    def __init__(self, **kwargs): 
    211225        # Copy the class _properties dict into self, setting 
     
    222236                     descriptor=UnitProperty): 
    223237        """Set a Unit Property for cls.""" 
    224         setattr(cls, key, descriptor(key, type, index)) 
     238        setattr(cls, key, descriptor(type, index, key=key)) 
    225239        cls._properties[key] = None 
    226240    set_property = classmethod(set_property) 
     
    304318            # If far key is already set, it will simply be overwritten. 
    305319            setattr(unit, farKey, nearval) 
    306  
    307  
    308 # The default ID type is int. If you wish to use a different type for 
    309 # the ID's of a subclass of Unit, just overwrite ID, e.g.: 
    310 #     ID = UnitProperty('ID', unicode, index=True) 
    311 #       or 
    312 #     UnitSubclass.set_property('ID', unicode, index=True) 
    313 #       or even 
    314 #     UnitSubclass.ID.type = unicode 
    315 # You will probably also want to override Unit.sequencer for the class. 
    316 Unit.set_property(u'ID', int, index=True) 
    317  
    318320 
    319321 
  • trunk/doc/api.html

    r28 r29  
    2626 
    2727class Publisher(dejavu.Unit): 
    28     name = dejavu.UnitProperty('name', str) 
     28    name = dejavu.UnitProperty(str) 
    2929 
    3030class Author(dejavu.Unit): 
  • trunk/doc/framework.html

    r28 r29  
    11<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    22   "http://www.w3.org/TR/xhtml1/DTD/strict.dtd"> 
    3 <html xmlns="http://www.w3.org/TR/xhtml1/strict" xml:lang="en" lang="en"> 
     3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
    44 
    55<head> 
    6     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
     6    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /
    77    <title>Dejavu: Framework Development</title> 
    88    <link href='dejavu.css' rel='stylesheet' type='text/css' /> 
  • trunk/doc/index.html

    r28 r29  
    11<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    22   "http://www.w3.org/TR/xhtml1/DTD/strict.dtd"> 
    3 <html xmlns="http://www.w3.org/TR/xhtml1/strict" xml:lang="en" lang="en"> 
     3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
    44 
    55<head> 
    6     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
     6    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /
    77    <title>Dejavu: Table of Contents</title> 
    88    <link href='dejavu.css' rel='stylesheet' type='text/css' /> 
  • trunk/doc/intro.html

    r28 r29  
    11<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    22   "http://www.w3.org/TR/xhtml1/DTD/strict.dtd"> 
    3 <html xmlns="http://www.w3.org/TR/xhtml1/strict" xml:lang="en" lang="en"> 
     3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
    44 
    55<head> 
    6     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
     6    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /
    77    <title>Dejavu: Introduction</title> 
    88    <link href='dejavu.css' rel='stylesheet' type='text/css' /> 
     
    8080 
    8181class Zoo(dejavu.Unit): 
    82     Name = dejavu.UnitProperty('Name', unicode
    83     Size = dejavu.UnitProperty('Size', int) 
     82    Name = dejavu.UnitProperty(
     83    Size = dejavu.UnitProperty(int) 
    8484     
    8585    def total_legs(self): 
     
    207207class Book(Unit): 
    208208    # The ID field is already set to 'int' for all Unit subclasses. 
    209     title = UnitProperty('title', str) 
    210     price = UnitProperty('price', fixedpoint.Fixedpoint) 
    211     publishDate = UnitProperty('publishDate', datetime.datetime) 
    212     publisher = UnitProperty('publisher', int) 
     209    title = UnitProperty(str) 
     210    price = UnitProperty(fixedpoint.Fixedpoint) 
     211    publishDate = UnitProperty(datetime.datetime) 
     212    publisher = UnitProperty(int) 
    213213     
    214214    def author_names(self): 
     
    220220 
    221221class Publisher(Unit): 
    222     name = UnitProperty('name', str) 
     222    name = UnitProperty(str) 
    223223 
    224224class Author(Unit): 
    225     name = UnitProperty('name', str) 
     225    name = UnitProperty(str) 
    226226     
    227227    def addAuthor(self, author): 
     
    232232 
    233233class Authorship(Unit): 
    234     authorID = UnitProperty('authorID', int) 
    235     bookID = UnitProperty('bookID', int) 
     234    authorID = UnitProperty(int) 
     235    bookID = UnitProperty(int) 
    236236 
    237237arena = Arena() 
  • trunk/doc/modeling.html

    r28 r29  
    11<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    22   "http://www.w3.org/TR/xhtml1/DTD/strict.dtd"> 
    3 <html xmlns="http://www.w3.org/TR/xhtml1/strict" xml:lang="en" lang="en"> 
     3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
    44 
    55<head> 
    6     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
     6    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /
    77    <title>Dejavu: Modeling your Application</title> 
    88    <link href='dejavu.css' rel='stylesheet' type='text/css' /> 
     
    4141<pre>from dejavu import Unit, UnitProperty 
    4242class Printer(Unit): 
    43     Manufacturer = UnitProperty('Manufacturer', unicode) 
    44     ColorCopies = UnitProperty('ColorCopies', bool) 
    45     PPM = UnitProperty('PPM', float)</pre> 
     43    Manufacturer = UnitProperty(unicode) 
     44    ColorCopies = UnitProperty(bool) 
     45    PPM = UnitProperty(float)</pre> 
    4646This adds three persistent attributes to our <tt>Printer</tt> objects, 
    4747each with a different datatype. In addition, every subclass of <tt>Unit</tt> 
     
    6969two classes are equivalent: 
    7070<pre>class Publication(Unit): 
    71     Content = UnitProperty('Content', unicode) 
     71    Content = UnitProperty(unicode) 
    7272 
    7373class Publication(Unit): pass 
    7474Publication.set_property('Content', unicode)</pre> 
     75 
    7576Declarations outside of the class body allow more dynamic setting of 
    7677Unit properties. You can define multiple properties at once via 
    7778the <tt>set_properties()</tt> classmethod: 
     79 
    7880<pre>class Publication(Unit): pass 
    7981Publication.set_properties({'Content': unicode, 
     
    8991modify. Keyword arguments also work when instantiating the object. For 
    9092example, the following three code snippets are equivalent: 
     93 
    9194<pre>pub = Publication() 
    9295pub.Publisher = 'Walter J. Black' 
     
    132135 
    133136class Topic(Unit): 
    134     Date = UnitProperty(u'Date', datetime.date) 
    135     Content = DatedProperty(u'Content')</pre> 
     137    Date = UnitProperty(datetime.date) 
     138    Content = DatedProperty()</pre> 
    136139In this example, whenever Topic().Content is set, the <tt>post</tt> 
    137140method will be called and the object's <tt>Date</tt> attribute will 
     
    143146the ID attribute in your subclass: 
    144147<pre>class Printer(Unit): 
    145     ID = UnitProperty('ID', unicode)</pre> 
     148    ID = UnitProperty(unicode)</pre> 
    146149Every Unit must possess an ID property. This ensures that each Unit within 
    147150the system is unique.</p> 
     
    178181to memorize it): 
    179182<pre>class Publisher(Unit): 
    180     City = UnitProperty('City', unicode) 
     183    City = UnitProperty(unicode) 
    181184 
    182185p = Publisher(ID='Walter J. Black') 
     
    531534might be called <i>foreign keys</i> in a database context). 
    532535<pre>class Archaeologist(Unit): 
    533     Height = UnitProperty('Height', float) 
     536    Height = UnitProperty(float) 
    534537 
    535538class Biography(Unit): 
    536     ArchID = UnitProperty('ArchID', int)</pre> 
     539    ArchID = UnitProperty(int)</pre> 
    537540In this example, each <tt>Biography</tt> object will have an <tt>ArchID</tt> 
    538541attribute, which will equal the <tt>ID</tt> of some <tt>Archaeologist</tt>. 
  • trunk/doc/storage.html

    r28 r29  
    11<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    22   "http://www.w3.org/TR/xhtml1/DTD/strict.dtd"> 
    3 <html xmlns="http://www.w3.org/TR/xhtml1/strict" xml:lang="en" lang="en"> 
     3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
    44 
    55<head> 
    6     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
     6    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /
    77    <title>Dejavu: Configuring Storage</title> 
    88    <link href='dejavu.css' rel='stylesheet' type='text/css' /> 
  • trunk/engines.py

    r28 r29  
    4141    """ 
    4242     
    43     Members = dejavu.UnitProperty(u'Members', list) 
    44     EngineID = dejavu.UnitProperty(u'EngineID', int, index=True) 
    45     Type = dejavu.UnitProperty(u'Type'
    46     Expiration = dejavu.UnitProperty(u'Expiration', datetime.datetime) 
    47     Timestamp = dejavu.UnitProperty(u'Timestamp', datetime.datetime) 
     43    Members = dejavu.UnitProperty(list) 
     44    EngineID = dejavu.UnitProperty(int, index=True) 
     45    Type = dejavu.UnitProperty(
     46    Expiration = dejavu.UnitProperty(datetime.datetime) 
     47    Timestamp = dejavu.UnitProperty(datetime.datetime) 
    4848     
    4949    def __init__(self, **kwargs): 
     
    157157    """A Rule for Unit Engines.""" 
    158158     
    159     Operation = RuleProperty(u'Operation', str) 
    160     SetID = RuleProperty(u'SetID', int) 
    161     Operand = RuleProperty(u'Operand', str, False, hints = {u'Size': 0}) 
    162     Sequence = RuleProperty(u'Sequence', int) 
    163     EngineID = dejavu.UnitProperty(u'EngineID', int, index=True) 
    164     Expiration = dejavu.UnitProperty(u'Expiration', datetime.datetime) 
     159    Operation = RuleProperty(str) 
     160    SetID = RuleProperty(int) 
     161    Operand = RuleProperty(str, False, hints = {u'Size': 0}) 
     162    Sequence = RuleProperty(int) 
     163    EngineID = dejavu.UnitProperty(int, index=True) 
     164    Expiration = dejavu.UnitProperty(datetime.datetime) 
    165165     
    166166    def __init__(self, **kwargs): 
     
    235235    """A factory for Unit Collections.""" 
    236236     
    237     Owner = dejavu.UnitProperty(u'Owner'
    238     Name = dejavu.UnitProperty(u'Name'
    239     Created = dejavu.UnitProperty(u'Created', datetime.datetime) 
    240     FinalClassName = dejavu.UnitProperty(u'FinalClassName'
    241     Expiration = dejavu.UnitProperty('Expiration', datetime.datetime) 
     237    Owner = dejavu.UnitProperty(
     238    Name = dejavu.UnitProperty(
     239    Created = dejavu.UnitProperty(datetime.datetime) 
     240    FinalClassName = dejavu.UnitProperty(
     241    Expiration = dejavu.UnitProperty(datetime.datetime) 
    242242     
    243243    def __init__(self, **kwargs): 
  • trunk/readme.py

    r28 r29  
    9494 
    9595changelog = """ 
     961.2.6 (): 
     97    1. Fixed bug in storeado with hints:Size of wrong type. 
     98    2. UnitProperty now supplies .key from local attribute name when 
     99        specified in class body (see MetaUnit __init__). 
     100 
    961011.2.5 (11/15/04): 
    97102    1. Rewrote UnitProperty to enable declaration within class body 
  • trunk/storage/storeado.py

    r28 r29  
    630630        limitations of the particular database. You should use one of the 
    631631        subclasses for your particular database if you need storage for 
    632         strings over 255 characters.""" 
     632        strings over 255 characters. 
     633        """ 
    633634        prop = getattr(cls, key) 
    634         size = prop.hints.get(u'Size', '255'
     635        size = int(prop.hints.get(u'Size', '255')
    635636        return u"VARCHAR(%s)" % size 
    636637     
     
    967968    def _create_str_storage(self, cls, key): 
    968969        prop = getattr(cls, key) 
    969         size = prop.hints.get(u'Size', '255'
     970        size = int(prop.hints.get(u'Size', '255')
    970971        if size == 0 or size > 8000: 
    971972            # 8000 *bytes* is the absolute upper limit, based on T_SQL docs 
     
    10151016    def _create_str_storage(self, cls, key): 
    10161017        prop = getattr(cls, key) 
    1017         size = prop.hints.get(u'Size', '255'
     1018        size = int(prop.hints.get(u'Size', '255')
    10181019        if size == 0 or size > 255: 
    10191020            # 255 chars is the upper limit for TEXT / VARCHAR in MS Access. 
  • trunk/storage/test_storeado.py

    r28 r29  
    44import storeado 
    55import dejavu 
    6 from dejavu import logic 
     6from dejavu import logic, Unit, UnitProperty 
    77 
    88arena = dejavu.Arena() 
     
    1616 
    1717 
    18 class Things(dejavu.Unit): 
    19     Name = dejavu.UnitProperty("Name", unicode
    20     Size = dejavu.UnitProperty("Size", int) 
    21     Date = dejavu.UnitProperty("Date", datetime.date) 
    22     Time = dejavu.UnitProperty("Time", datetime.time) 
    23     DateTime = dejavu.UnitProperty("DateTime", datetime.datetime) 
    24  
    25 class Animals(dejavu.Unit): pass 
     18class Things(Unit): 
     19    Name = UnitProperty(
     20    Size = UnitProperty(int) 
     21    Date = UnitProperty(datetime.date) 
     22    Time = UnitProperty(datetime.time) 
     23    DateTime = UnitProperty(datetime.datetime) 
     24 
     25class Animals(Unit): pass 
    2626Animals.set_properties({"Name": unicode, 
    2727                        "Legs": int, 
     
    3030arena.associate(Things, 'Size', Animals, 'Legs') 
    3131 
    32 class Other(dejavu.Unit): 
    33     Blob = dejavu.UnitProperty("Blob", list) 
    34     Bunch = dejavu.UnitProperty("Bunch", list) 
     32class Other(Unit): 
     33    Blob = UnitProperty(list) 
     34    Bunch = UnitProperty(list) 
    3535arena.register(Other) 
    3636 
  • trunk/test_codewalk.py

    r28 r29  
    188188        self.assertEqual(codewalk.KeywordInspector(e).kwargs(), ["Size"]) 
    189189        e = lambda x: x.Size > kw['Size'] 
    190         self.assertRaises(AssertionError, codewalk.KeywordInspector, e) 
     190        self.assertRaises(ValueError, codewalk.KeywordInspector, e) 
    191191        e = lambda x, **kw: x.Date > x.newdate(kw['Year'], 1, 1) 
    192192        self.assertEqual(codewalk.KeywordInspector(e).kwargs(), ["Year"]) 
  • trunk/test_dejavu.py

    r28 r29  
    2929         
    3030        class Thing(dejavu.Unit): 
    31             Integer = dejavu.UnitProperty('Integer', int, index=True) 
    32             String = dejavu.UnitProperty('String', str, hints={'Size': 0}) 
    33             Unicode = dejavu.UnitProperty('Unicode', unicode) 
    34             Datetime = Triggered('Datetime', datetime.datetime) 
     31            Integer = dejavu.UnitProperty(int, index=True) 
     32            String = dejavu.UnitProperty(str, hints={'Size': 0}) 
     33            Unicode = dejavu.UnitProperty(unicode) 
     34            Datetime = Triggered(datetime.datetime) 
    3535         
    3636        # Instance creation and population