Hi everybody,
I am writing a base class for <<entity>> stereotype classes, to implement
controlled access to the state and expose some of the access logic (in order
to dinamically build javascript code for client-side checks, for example).
Currently the idiom needed to subclass it is something like:
class Group(Entity):
_interface = Entity._extend_ interface(
id = Direct(state_fi eld='grp_id',
filters=(ReadOn lyFilter(),),
doc="The univocal database id for the group."),
name = Direct(
filters=(
StringFilter(),
MaxLenFilter(ma x_len=40,
message="The group name can be at most "
"%(max_len) s characters long."),),
doc = "A descriptive name for the group."),
)
_state = Entity._extend_ state(
grp_id=None,
name=None,
)
# ... class definition ...
make_entity(Gro up)
The make_entity() call compiles some dinamically generated code to produce
the properties required to access the class. But adding such line after each
entity definition bothers me.
I don't know much about metaclasses: could they help me to automatically
perform such mangling on the classes "at compile time" (or at least once in
the class lifetime)? Hints about that?
What make_entity does is here down. Basically each Field instance (Direct is
a Field subclass) in the _interface dictionary (a class member) create a
property object on the same class that will perform the access for the class
instances.
def make_entity(ent ity):
"""Complete the Entity subclass building its attributes."""
for (field_name, field) in entity._interfa ce.iteritems():
if not hasattr(entity, field_name):
field.field_nam e = field_name
field.create_ac cessors(entity)
Thank you in advance
Daniele 0 1100 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stephan Diehl |
last post by:
I have a question about metaclasses:
How would be the best way to "merge" different metaclasses?
Or, more precisely, what is the best way to merge metaclass functionality?
The idea is basicly the following:
One has several (metaclass) modules that implements an interesting feature.
Lets say, I have a metaclass L, that adds logging capabilities to all method
calls and another one, called P, that creates properties on the fly.
|
by: Mike C. Fletcher |
last post by:
Slides from my PyGTA presentation on Tuesday, focusing mostly on
why/where you would want to use meta-classes, are available in PDF format:
http://members.rogers.com/mcfletch/programming/metaclasses.pdf
BTW, for those not on Python-list, be sure to check out David &
Michele's newest developerworks article on the topic:
http://www.ibm.com/developerworks/library/l-pymeta.html...
|
by: Santiago Aguiar |
last post by:
Im trying to use AOP techniques on python but, even if I understand
the idea behind metaclasses, I cant find a way to use AOP in a dynamic
way.
What im trying to do is to weave an aspect to a class at runtime, but
i don't want to include any special code or definition in the class
itself. Also, i want to do
it just for some particular classes. Is there any way to do this?
I know its possible to apply an aspect to all the classes by
|
by: Michele Simionato |
last post by:
> Hello, my name is Skip and I am metaclass-unaware. I've been programming in
> Python for about ten years and I have yet to write a metaclass. At first I
> thought it was just that metaclasses were new to the language, but now as
> more and more people use them and proclaim their widespread benefits, I have
> come to realize that through years of abuse my brain has become addicted to
> classic classes.
I began using Python since...
|
by: Michael Sparks |
last post by:
Anyway...
At Europython Guido discussed with everyone the outstanding issue with
decorators and there was a clear majority in favour of having them, which
was good. From where I was sitting it looked like about 20:20 split on the
following syntaxes:
1 def func(arg1, arg2, arg3) :
function...
2 def func(arg1, arg2, arg3):
function...
| |
by: Jan-Ole Esleben |
last post by:
Hi!
I am new to this list, and maybe this is a stupid question, but I
can't seem to find _any_ kind of answer anywhere.
What I want to do is the following:
I want to insert a class variable into a class upon definition and
actually use it during definition.
Manually, that is possible, e.g.:
|
by: Lawrence Oluyede |
last post by:
I've never used metaclasses in real life before and while searching through
the online Cookbook I found this gorgeous example:
"Wrapping method calls (meta-class example)"
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/198078
What I want to do in my app is to log all method calls and seems that the
metaclass example above do this fine but it fails when it's needed to
instantiate the class I'm in in a method. So if I do:
|
by: Brian van den Broek |
last post by:
Hi all,
I've the following code snippet that puzzles me:
class Base(object):
__v, u = "Base v", "Base u"
def __init__(self):
print self.__v, self.u
class Derived(Base):
|
by: David Hirschfield |
last post by:
Is it possible for one class definition to have multiple metaclasses?
I don't think it is, but I'm just checking to make sure.
From what I know, you can only define "__metaclass__" to set the
metaclass for a class, and that's it, is that correct?
-David
--
Presenting:
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |