Changeset 29
- Timestamp:
- 11/19/04 06:55:00
- Files:
-
- trunk/__init__.py (modified) (5 diffs)
- trunk/doc/api.html (modified) (1 diff)
- trunk/doc/framework.html (modified) (1 diff)
- trunk/doc/index.html (modified) (1 diff)
- trunk/doc/intro.html (modified) (5 diffs)
- trunk/doc/modeling.html (modified) (8 diffs)
- trunk/doc/storage.html (modified) (1 diff)
- trunk/engines.py (modified) (3 diffs)
- trunk/readme.py (modified) (1 diff)
- trunk/storage/storeado.py (modified) (3 diffs)
- trunk/storage/test_storeado.py (modified) (3 diffs)
- trunk/test_codewalk.py (modified) (1 diff)
- trunk/test_dejavu.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/__init__.py
r28 r29 111 111 post = None 112 112 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): 115 114 self.type = type 116 115 self.index = index 117 116 self.hints = hints 117 self.key = key 118 118 119 119 def __get__(self, unit, unitclass=None): … … 167 167 for key, val in dct.iteritems(): 168 168 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 169 173 props[key] = val 170 174 … … 208 212 sequencer = UnitSequencerInteger() 209 213 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 210 224 def __init__(self, **kwargs): 211 225 # Copy the class _properties dict into self, setting … … 222 236 descriptor=UnitProperty): 223 237 """Set a Unit Property for cls.""" 224 setattr(cls, key, descriptor( key, type, index))238 setattr(cls, key, descriptor(type, index, key=key)) 225 239 cls._properties[key] = None 226 240 set_property = classmethod(set_property) … … 304 318 # If far key is already set, it will simply be overwritten. 305 319 setattr(unit, farKey, nearval) 306 307 308 # The default ID type is int. If you wish to use a different type for309 # the ID's of a subclass of Unit, just overwrite ID, e.g.:310 # ID = UnitProperty('ID', unicode, index=True)311 # or312 # UnitSubclass.set_property('ID', unicode, index=True)313 # or even314 # UnitSubclass.ID.type = unicode315 # You will probably also want to override Unit.sequencer for the class.316 Unit.set_property(u'ID', int, index=True)317 318 320 319 321 trunk/doc/api.html
r28 r29 26 26 27 27 class Publisher(dejavu.Unit): 28 name = dejavu.UnitProperty( 'name',str)28 name = dejavu.UnitProperty(str) 29 29 30 30 class Author(dejavu.Unit): trunk/doc/framework.html
r28 r29 1 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 2 2 "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"> 4 4 5 5 <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" /> 7 7 <title>Dejavu: Framework Development</title> 8 8 <link href='dejavu.css' rel='stylesheet' type='text/css' /> trunk/doc/index.html
r28 r29 1 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 2 2 "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"> 4 4 5 5 <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" /> 7 7 <title>Dejavu: Table of Contents</title> 8 8 <link href='dejavu.css' rel='stylesheet' type='text/css' /> trunk/doc/intro.html
r28 r29 1 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 2 2 "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"> 4 4 5 5 <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" /> 7 7 <title>Dejavu: Introduction</title> 8 8 <link href='dejavu.css' rel='stylesheet' type='text/css' /> … … 80 80 81 81 class Zoo(dejavu.Unit): 82 Name = dejavu.UnitProperty( 'Name', unicode)83 Size = dejavu.UnitProperty( 'Size',int)82 Name = dejavu.UnitProperty() 83 Size = dejavu.UnitProperty(int) 84 84 85 85 def total_legs(self): … … 207 207 class Book(Unit): 208 208 # 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) 213 213 214 214 def author_names(self): … … 220 220 221 221 class Publisher(Unit): 222 name = UnitProperty( 'name',str)222 name = UnitProperty(str) 223 223 224 224 class Author(Unit): 225 name = UnitProperty( 'name',str)225 name = UnitProperty(str) 226 226 227 227 def addAuthor(self, author): … … 232 232 233 233 class Authorship(Unit): 234 authorID = UnitProperty( 'authorID',int)235 bookID = UnitProperty( 'bookID',int)234 authorID = UnitProperty(int) 235 bookID = UnitProperty(int) 236 236 237 237 arena = Arena() trunk/doc/modeling.html
r28 r29 1 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 2 2 "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"> 4 4 5 5 <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" /> 7 7 <title>Dejavu: Modeling your Application</title> 8 8 <link href='dejavu.css' rel='stylesheet' type='text/css' /> … … 41 41 <pre>from dejavu import Unit, UnitProperty 42 42 class 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> 46 46 This adds three persistent attributes to our <tt>Printer</tt> objects, 47 47 each with a different datatype. In addition, every subclass of <tt>Unit</tt> … … 69 69 two classes are equivalent: 70 70 <pre>class Publication(Unit): 71 Content = UnitProperty( 'Content',unicode)71 Content = UnitProperty(unicode) 72 72 73 73 class Publication(Unit): pass 74 74 Publication.set_property('Content', unicode)</pre> 75 75 76 Declarations outside of the class body allow more dynamic setting of 76 77 Unit properties. You can define multiple properties at once via 77 78 the <tt>set_properties()</tt> classmethod: 79 78 80 <pre>class Publication(Unit): pass 79 81 Publication.set_properties({'Content': unicode, … … 89 91 modify. Keyword arguments also work when instantiating the object. For 90 92 example, the following three code snippets are equivalent: 93 91 94 <pre>pub = Publication() 92 95 pub.Publisher = 'Walter J. Black' … … 132 135 133 136 class Topic(Unit): 134 Date = UnitProperty( u'Date',datetime.date)135 Content = DatedProperty( u'Content')</pre>137 Date = UnitProperty(datetime.date) 138 Content = DatedProperty()</pre> 136 139 In this example, whenever Topic().Content is set, the <tt>post</tt> 137 140 method will be called and the object's <tt>Date</tt> attribute will … … 143 146 the ID attribute in your subclass: 144 147 <pre>class Printer(Unit): 145 ID = UnitProperty( 'ID',unicode)</pre>148 ID = UnitProperty(unicode)</pre> 146 149 Every Unit must possess an ID property. This ensures that each Unit within 147 150 the system is unique.</p> … … 178 181 to memorize it): 179 182 <pre>class Publisher(Unit): 180 City = UnitProperty( 'City',unicode)183 City = UnitProperty(unicode) 181 184 182 185 p = Publisher(ID='Walter J. Black') … … 531 534 might be called <i>foreign keys</i> in a database context). 532 535 <pre>class Archaeologist(Unit): 533 Height = UnitProperty( 'Height',float)536 Height = UnitProperty(float) 534 537 535 538 class Biography(Unit): 536 ArchID = UnitProperty( 'ArchID',int)</pre>539 ArchID = UnitProperty(int)</pre> 537 540 In this example, each <tt>Biography</tt> object will have an <tt>ArchID</tt> 538 541 attribute, which will equal the <tt>ID</tt> of some <tt>Archaeologist</tt>. trunk/doc/storage.html
r28 r29 1 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 2 2 "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"> 4 4 5 5 <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" /> 7 7 <title>Dejavu: Configuring Storage</title> 8 8 <link href='dejavu.css' rel='stylesheet' type='text/css' /> trunk/engines.py
r28 r29 41 41 """ 42 42 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) 48 48 49 49 def __init__(self, **kwargs): … … 157 157 """A Rule for Unit Engines.""" 158 158 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) 165 165 166 166 def __init__(self, **kwargs): … … 235 235 """A factory for Unit Collections.""" 236 236 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) 242 242 243 243 def __init__(self, **kwargs): trunk/readme.py
r28 r29 94 94 95 95 changelog = """ 96 1.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 96 101 1.2.5 (11/15/04): 97 102 1. Rewrote UnitProperty to enable declaration within class body trunk/storage/storeado.py
r28 r29 630 630 limitations of the particular database. You should use one of the 631 631 subclasses for your particular database if you need storage for 632 strings over 255 characters.""" 632 strings over 255 characters. 633 """ 633 634 prop = getattr(cls, key) 634 size = prop.hints.get(u'Size', '255')635 size = int(prop.hints.get(u'Size', '255')) 635 636 return u"VARCHAR(%s)" % size 636 637 … … 967 968 def _create_str_storage(self, cls, key): 968 969 prop = getattr(cls, key) 969 size = prop.hints.get(u'Size', '255')970 size = int(prop.hints.get(u'Size', '255')) 970 971 if size == 0 or size > 8000: 971 972 # 8000 *bytes* is the absolute upper limit, based on T_SQL docs … … 1015 1016 def _create_str_storage(self, cls, key): 1016 1017 prop = getattr(cls, key) 1017 size = prop.hints.get(u'Size', '255')1018 size = int(prop.hints.get(u'Size', '255')) 1018 1019 if size == 0 or size > 255: 1019 1020 # 255 chars is the upper limit for TEXT / VARCHAR in MS Access. trunk/storage/test_storeado.py
r28 r29 4 4 import storeado 5 5 import dejavu 6 from dejavu import logic 6 from dejavu import logic, Unit, UnitProperty 7 7 8 8 arena = dejavu.Arena() … … 16 16 17 17 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): pass18 class 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 25 class Animals(Unit): pass 26 26 Animals.set_properties({"Name": unicode, 27 27 "Legs": int, … … 30 30 arena.associate(Things, 'Size', Animals, 'Legs') 31 31 32 class Other( dejavu.Unit):33 Blob = dejavu.UnitProperty("Blob",list)34 Bunch = dejavu.UnitProperty("Bunch",list)32 class Other(Unit): 33 Blob = UnitProperty(list) 34 Bunch = UnitProperty(list) 35 35 arena.register(Other) 36 36 trunk/test_codewalk.py
r28 r29 188 188 self.assertEqual(codewalk.KeywordInspector(e).kwargs(), ["Size"]) 189 189 e = lambda x: x.Size > kw['Size'] 190 self.assertRaises( AssertionError, codewalk.KeywordInspector, e)190 self.assertRaises(ValueError, codewalk.KeywordInspector, e) 191 191 e = lambda x, **kw: x.Date > x.newdate(kw['Year'], 1, 1) 192 192 self.assertEqual(codewalk.KeywordInspector(e).kwargs(), ["Year"]) trunk/test_dejavu.py
r28 r29 29 29 30 30 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) 35 35 36 36 # Instance creation and population
