metaclass

Is there a way to emulate the __prepare__ special method of a Python 3-metaclass in Python 2.5?

In my project I have to stick to Python 2.5 (Google App Engine). Somewhere in the application (actually a framework), I have to keep track which variables are defined and in which order they are defined, in other words I would like to intercept whenever an assignment operator is processed. Using Python 3, I would define a metaclass M wi...

Python Metaclass to Parametrize Inheritance

I've read some tutorials on Python metaclasses. I've never used one before, but I need one for something relatively simple and all the tutorials seem geared towards much more complex use cases. I basically want to create a template class that has some pre-specified body, but takes its base class as a parameter. Since I got the idea fr...

Generic Python metaclass to keep track of subclasses

I'm trying to writing a generic metaclass for tracking subclasses Since I want this to be generic, I didn't want to hardcode any class name within this metaclass, therefore I came up with a function that generates the proper metaclass, something like: def make_subtracker(root): class SubclassTracker(type): def __init__(cls,...

[Django] Get parameters of object in metaclass of this object

My problem is a python/django mix. I have a form model that will display some fields. Basing on some parameter of this model, the data sent to metaclass creating this object should differ. But how can I reach this parameter when inside the body of Meta ? Should I use some global var instead of object parameter (as it is introduced only t...

Put a key named metaClass in a Map

Hi, I've written a small Groovy script that exposes a very weird behaviour. can anyone explain it ? // Creating a groovy map def map = [:] // Putting a value in map["a"]="b" // Render it without trouble println map["a"] // Putting another value in (yup, this one has THE name) map["metaClass"]="c" // Failing to render it println m...

How to prevent groovy from creating lowercase (meta) property names?

Hi folks, I've a problem. I want to have nice dynamic groovy classes to represent an ugly XML structure (unfortunately JAXB, XmlBeans etc. is not possible). For this goal I need case-sensitive properties to map the element values from XML to my classes. But Groovy generates automatically lowercase property names due to the JavaBeans sp...