I'm trying to get the following html out of Zend_Form
<div class="group wat-cf">
<div class="left">
<label class="label right">Username</label>
</div>
<div class="right">
<input type="text" class="text_field">
</div>
</div>
Using the following code:
$username->setAttrib("class", "text_field")
->setDecorators(...
decorator 1:
def dec(f):
def wrap(obj, *args, **kwargs):
f(obj, *args,**kwargs)
return wrap
decorator 2:
class dec:
def __init__(self, f):
self.f = f
def __call__(self, obj, *args, **kwargs):
self.f(obj, *args, **kwargs)
A sample class,
class Test:
@dec
def disp(self, *args, **kwargs...
I need some simple objects that could become more complex later, with many different properties, so i thought to decorator pattern.
I made this looking at Crockford's power constructor and object augmentation:
//add property to object
Object.prototype.addProperty = function(name, func){
for(propertyName in this){
if(property...
I'm trying to generate this html heirarchy in my zend_form display group:
<div class="settings">
<div class="dashed-outline"> //want to add this div
<fieldset disabledefaultdecorators="1" id="fieldset-settings">
<legend>Cards</legend>
</fieldset>
</div>
</div>
This is what I have cur...
Is it possible to create a decorator which can be __init__'d with a set of arguments, then later have methods called with other arguments?
For instance:
from foo import MyDecorator
bar = MyDecorator(debug=True)
@bar.myfunc(a=100)
def spam():
pass
@bar.myotherfunc(x=False)
def eggs():
pass
If this is possible, can you provi...
I'm using log4net, and we have a lot of this in our code:
public class Foo {
private static readonly ILog log = LogManager.GetLogger(typeof(Foo));
....
}
One downside is that it means we're pasting this 10-word section all over, and every now and then somebody forgets to change the class name. The log4net FAQ also mentions th...
I need to be able to add some javascript to all ajax postback responses (PartialViewContext.isAjaxRequest == true) but I am not succeeding with any implementation I try.
I have tried implementing a
PhaseListener
and adding my script using PartialResponseWriter.insert* to add eval blocks, as well as trying to add the script by creatin...
public class Car
{
private string make;
private string model;
public Car(string make, string model)
{
this.make = make;
this.model = model;
}
public virtual void Display()
{
Console.WriteLine("Make: {0}", make);
Console.WriteLine("Model: {0}", model);
}
public string M...
I have a BlockingQueue implementation that's being used in a producer-consumer situation. I would like to decorate this queue so that every object that's taken from it is logged. I know what the straightforward implementation would look like: simply implement BlockingQueue and accept a BlockingQueue in the constructor to which all of the...
Hi,
I am trying to write a base crud controller class that does the
following:
class BaseCrudController:
model = ""
field_validation = {}
template_dir = ""
@expose(self.template_dir)
def new(self, *args, **kwargs)
....
@validate(self.field_validation, error_handler=new)
@expose()
def post(self...
I'd like to decorate a function, using a pattern like this:
def deco(func):
def wrap(*a,**kw):
print "do something"
return func(*a,**kw)
return wrap
The problem is that if the function decorated has a prototype like that:
def function(a,b,c): return
When decorated, the prototype is destroyed by the varargs, ...
I need a custom border that renders a little differently than a normal border. I made a class that inherited from Decorator as follows
class BetterBorder : Decorator
{
protected override Size ArrangeOverride(Size arrangeSize)
{
return arrangeSize;
}
protected override void OnRender(DrawingContext dc)
{
...
I have a bunch of methods with varying signatures. These methods interact with a fragile data connection, so we often use a helper class to perform retries/reconnects, etc. Like so:
MyHelper.PerformCall( () => { doStuffWithData(parameters...) });
And this works fine, but it can make the code a little cluttery. What I would prefer t...
If I do the following
def mydecorator(f):
def wrapper(*args, **kwargs):
f(*args, **kwargs)
wrapper.__doc__ = f.__doc__
wrapper.__name__ = f.__name__
return wrapper
@mydecorator
def myfunction(a,b,c):
'''My docstring'''
pass
And then type help myfunction, I get:
Help on function myfunction in module __...
Help a guy out. Can't seem to get a decorator to work with inheritance. Broke it down to the simplest little example in my scratch workspace. Still can't seem to get it working.
class bar(object):
def __init__(self):
self.val = 4
def setVal(self,x):
self.val = x
def decor(self, func):
def increment...
I try define class decorator. I have problem with __init__ method in decorated class. If __init__ method invokes super the RuntimeError maximum recursion depth exceeded is raised.
Code example:
def decorate(cls):
class NewClass(cls): pass
return NewClass
@decorate
class Foo(object):
def __init__(self, *args, **kwargs):
...
Recently I've gone through an existing code base and refactored a lot of instance attributes to be lazy, ie. not be initialised in the constructor but only upon first read. These attributes do not change over the lifetime of the instance, but they're a real bottleneck to calculate that first time and only really accessed for special case...
How can you decorate a DOM node so that you add an event handler, but within the new handler you can call the previous handler?
...
Generally don't do OO-programming in Python. This project requires it and am running into a bit of trouble. Here's my scratch code for attempting to figure out where it went wrong:
class trial(object):
def output( func, x ):
def ya( self, y ):
return func( self, x ) + y
return ya
def f1( func ):
...
I've been playing around in depth with attempting to write my own version of a memoizing decorator before I go looking at other people's code. It's more of an exercise in fun, honestly. However, in the course of playing around I've found I can't do something I want with decorators.
def addValue( func, val ):
def add( x ):
...