58 messages in com.googlegroups.sqlalchemy[sqlalchemy] Re: Integrating ORM with...
FromSent OnAttachments
Phillip J. Eby26 Feb 2008 09:18 
sdob...@sistechnology.com26 Feb 2008 10:36 
Michael Bayer26 Feb 2008 11:05 
Phillip J. Eby26 Feb 2008 11:42 
Michael Bayer26 Feb 2008 12:27 
Michael Bayer26 Feb 2008 12:28 
sdob...@sistechnology.com26 Feb 2008 12:35 
sdob...@sistechnology.com26 Feb 2008 13:05 
jason kirtland26 Feb 2008 13:51 
Phillip J. Eby26 Feb 2008 14:27 
Phillip J. Eby26 Feb 2008 14:39 
Michael Bayer26 Feb 2008 14:44 
Michael Bayer26 Feb 2008 16:22 
Phillip J. Eby26 Feb 2008 17:07 
Phillip J. Eby26 Feb 2008 17:30 
Michael Bayer26 Feb 2008 17:39 
sdob...@sistechnology.com26 Feb 2008 22:05 
Michael Bayer26 Feb 2008 23:48 
sdob...@sistechnology.com26 Feb 2008 23:50 
svilen27 Feb 2008 04:58 
Judah De Paula27 Feb 2008 06:46 
Michael Bayer27 Feb 2008 07:22 
Michael Bayer27 Feb 2008 08:58.py
Judah De Paula27 Feb 2008 09:00 
Judah De Paula27 Feb 2008 09:05 
jason kirtland27 Feb 2008 09:19 
Michael Bayer27 Feb 2008 09:40 
Michael Bayer27 Feb 2008 10:06 
Phillip J. Eby27 Feb 2008 12:10 
Michael Bayer27 Feb 2008 13:03 
Michael Bayer27 Feb 2008 13:09 
sdob...@sistechnology.com27 Feb 2008 22:50 
sdob...@sistechnology.com27 Feb 2008 23:20 
Michael Bayer28 Feb 2008 07:18 
Michael Bayer28 Feb 2008 13:16 
Michael Bayer28 Feb 2008 13:19 
sdob...@sistechnology.com28 Feb 2008 13:25 
sdob...@sistechnology.com28 Feb 2008 13:38 
sdob...@sistechnology.com28 Feb 2008 14:15 
Phillip J. Eby28 Feb 2008 14:17 
Phillip J. Eby28 Feb 2008 14:26 
sdob...@sistechnology.com28 Feb 2008 14:37 
Michael Bayer28 Feb 2008 14:41 
Michael Bayer28 Feb 2008 14:48 
sdob...@sistechnology.com28 Feb 2008 15:22 
sdob...@sistechnology.com28 Feb 2008 15:38 
Phillip J. Eby28 Feb 2008 16:15 
Phillip J. Eby28 Feb 2008 16:26 
sdob...@sistechnology.com28 Feb 2008 22:59 
Phillip J. Eby29 Feb 2008 07:38 
Michael Bayer29 Feb 2008 09:55.patch
Phillip J. Eby29 Feb 2008 10:44 
Judah De Paula29 Feb 2008 11:08 
Phillip J. Eby03 Mar 2008 10:38.patch
Michael Bayer03 Mar 2008 11:03 
Phillip J. Eby04 Mar 2008 16:27 
Michael Bayer05 Mar 2008 07:42 
jason kirtland06 Mar 2008 14:41 
Subject:[sqlalchemy] Re: Integrating ORM with classes that directly access __dict__ (was Re: Integrating the ORM with Trellis)
From:sdob...@sistechnology.com (sdob@sistechnology.com)
Date:02/28/2008 02:37:44 PM
List:com.googlegroups.sqlalchemy

On Thursday 28 February 2008 23:17:14 Michael Bayer wrote:

On Feb 28, 2008, at 4:25 PM, sdob@sistechnology.com wrote:

What i'm talking about is a protocol of how SA is using that attr-value-storage. i.e. that dict-like thing must have these and these methods (like, why u need pop?), and expect them do behave so and so if not really obvious (like that getitem failing when a trigger is pending), etc. i dont expect u to do it straight away, from my experience with SA code these things are scattered all around and sometimes in quite weird occasions. do u understand me now? sorry about being a bit, er, intrusive..

what dict-like thing, you mean __dict__ ? the contract between __dict__ and a trigger firing is pretty straightforward. key is in dict, no trigger fires. key is not there, trigger fires. that logic takes place entirely within attributes.py in the get() method starting on line 208.

okay, if u say so. (therefore in my case i have to know if there's a trigger pending to simulate a missing value. not very clean..)

any other similar contracts?

we use pop() sometimes to remove an item if its present, else ignore. you can make any old dict that acts like __dict__ and that should be pretty easy to do.

ok, so u need the method pop() to be there, and do exactly what plain dict does.

let me do a draft:

class dict4attr_storage_protocol: 'required methods of the state.dict's usage-protocol'

def has_key( self, sk): 'return True if present, else False' raise NotImplementedError __contains__ = has_key

def __getitem__( self, key, *defaultvalue): '''return value of that key if found else if defaultvalue present, return that else raise KeyError ''' raise NotImplementedError

def get( self, key, defaultvalue =None): return self.__getitem__( key, defaultvalue)

def __setitem__( self, key, value): '''store value for key''' raise NotImplementedError

def __delitem__( self, key): '''delete value for key''' raise NotImplementedError

def pop( self, key, *defaultvalue): '''if key found, remove it and return its value else if defaultvalue present, return that else raise KeyError ''' raise NotImplementedError

for example having has_key AND __contains__ being same, is redundant.

contract for triggerring: trigger checks for key in state.dict via (contains?haskey?getitem?get?) and fires if not found.

contract for ... any other specific behaviours that may have some influence into the dict itself...

etc..... is this making sense?