Hello,
I have a number of SQLObject-derived classes and want to provide them with the
common functionality. I wrote a separate ResourceMixin class which is then
specified in class' declaration, like this:
class Foo(ResourceMixin, SQLObject):
name = UnicodeCol(length=255)
...
ResourceMixin define some utility methods that got mixed in and worked fine.
Then I decided to reduce duplicate code further by moving properties
declaration into the mixin. E.g. each of model classes contained declaration of
_get_something and _set_something and I wanted to move this into ResourceMixin.
And here is the problem. How can I do this?
I was trying to add a metaclass to ResourceMixin that would inspect the class
and attach these properties but run into a strange conflict with SQLObject's
own magic:
File "D:\Projects\Spaca\spaca\model.py", line 69, in ?
class ResourceMixin(object):
File "D:\Projects\Spaca\spaca\model.py", line 67, in __new__
return super(ResourceMixinMeta, cls).__new__(name, bases,dict)
TypeError: Error when calling the metaclass bases
type.__new__(X): X is not a type object (str)
The code is as follows:
class ResourceMixinMeta(type):
def __new__(cls, name, bases, dict):
print 'new', cls, name, bases
return super(ResourceMixinMeta, cls).__new__(name, bases,dict)
class ResourceMixin(object):
__metaclass__ = ResourceMixinMeta
...
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss