decorator

Python Sphinx autodoc and decorated members

I am attempting to use Sphinx to document my Python class. I do so using autodoc: .. autoclass:: Bus :members: While it correctly fetches the docstrings for my methods, those that are decorated: @checkStale def open(self): """ Some docs. """ # Code with @checkStale being def checkStale(f)...

Passing state when using decorators (formencode) in pylons

I've met the same problem as this page: http://www.mail-archive.com/[email protected]/msg14292.html This is the main content from there: I am using formencode to validate my forms, and I've stumbled upon a problem. When using tha validator inside the controller action, I call to_python() and I can pass the sta...

Create decorator that can see current class method

Can you create a decorator inside a class that will see the classes methods and variables? The decorator here doesnt see: self.longcondition() class Foo: def __init__(self, name): self.name = name # decorator that will see the self.longcondition ??? class canRun(object): def __init__(self, f): ...

Extracting a DIV's content using Sitemesh Decorators

I would like to know how I can extract the content of a specific DIV using decorators, instead of using <decorator:body /> which will fetch all the content inside the <body> tag. ...

Pattern matching using decorators

I want to define a specific URL pattern using Sitemesh decorators.xml. I want to define a decorator that matches all URLs ending with "/story/_NUMBER_" to be targetted by the decorator. I tried: <decorator name="customMain" page="customMain.jsp"> <pattern>/story/[0-9]+</pattern> </decorator> But this does not work.. Do regu...

How can I programmatically change the argspec of a function in a python decorator?

Given a function: def func(f1, kw='default'): pass bare_argspec = inspect.getargspec(func) @decorator def func2(f1, kw='default'): pass decorated_argspec = inspect.getargspec(func2) How can I create a decorator such that bare_argspec == decorated_argspec? (As to why, the framework that calls the decorated function does argsp...

Populate a checkbox when using a viewScript decorator in Zend Form

I have a zend_form with a checkbox: $horz = new Zend_Form_Element_Checkbox('horizontal'); $horz->setLabel('Display horizontally?'); $horz->setDecorators(array(array('ViewScript', array('viewScript' => 'partials/forms/checkbox.phtml')))); My custom viewScript checkbox.phtml looks like this: <?php $name = $this->element->getName(); ...

Python decorators that are part of a base class cannot be used to decorate member functions in inherited classes

First time poster, long time reader, so bear with me: Python decorators are fun to use, but I appear to have hit a wall due to the way arguments are passed to decorators. Here I have a decorator defined as part of a base class (the decorator will access class members hence it will require the self parameter). class SubSystem(object): ...

decorator inside class & decorated classmethod without 'self' gives strange results

Example code: # -*- coding: utf-8 -*- from functools import wraps class MyClass(object): def __init__(self): pass #decorator inside class def call(f): @wraps(f) def wrapper(*args): print 'Wrapper: ', args return wrapper #decorated 'method' without self @call def myfunc(a): pass c = MyClass() c....

Sitemesh, periodic refresh duplicates header and footer (Struts2 action)

I am using sitemesh defined jsp in decorator xml which needs to be refresh for every min. After refresh the page is duplicating header and footer. I am using jQuery setInterval for refresh every min and given action name in load with div. Can someone please help what are configuration changes I need to do for header footer not to dup...

PHP Decorator Writer Script

I am starting to use decorators in PHP more often these days to modify an object's behavior at run-time. My problem is primarily one of laziness, we have many legacy classes with tons of methods and the thought of having to re-write/override all of them for each decorator class makes me sad. Does anyone know of a command line utility t...

A problem when using the decorator design pattern

We are currently using the decorator design pattern to perform some caching. So we have a bunch of classes that look something like this: interface IComponent { object Operation(); object AnotherOperation(); } public ConcreteComponentA : IComponent { public object Operation() { return new object(); } public object Anoth...

Python function local name binding from an outer scope

I need a way to "inject" names into a function from an outer code block, so they are accessible locally and they don't need to be specifically handled by the function's code (defined as function parameters, loaded from *args etc.) The simplified scenario: providing a framework within which the users are able to define (with as little sy...

How to handle 'this' reference in decorator pattern

I have a problem in a class of mine that uses the decorator pattern. The problem arises when the inner object uses the "this" reference in calls to other objects. This causes all calls from the object that received the "this" reference to be made directly to the inner object, without going through the outer first. What is the usual wa...

How to build a python decorator with optional parameters ?

I would like to make a decorator which could be used with or without a parameter : Something like this : class d(object): def __init__(self,msg='my default message'): self.msg=msg def __call__(self,fn): def newfn(): print self.msg return fn() return newfn @d('T...

Java: automatic memoization

I have a few functions in my code where it makes much sense (seems even mandatory) to use memoization. I don't want to implement that manually for every function separately. Is there some way (for example like in Python) I can just use an annotation or do something else so I get this automatically on those functions where I want it? ...

Developing an API layer. Need some advice and feedback about usage of Decorator pattern.

Hi, I am developing an api layer for my application. I have designed a structure and need some advice/feedback for it. You can find the basic implementation of the structure at the bottom. Here are my requirements for the structure: Response from API commands may need to be formatted in different formats (JSON,XML,etc.) Some API com...

Decorating a String in Java

Suppose I want to use the Decorator pattern to add functionality to the java.lang.String class. (Just for example, to add a toRussian() method.) String is a final class. Is the following the only way to do it? class DecoratedString implements Serializable, CharSequence, Comparable<DecoratedString> { private final String str; ...

In .Net, how do I decorate a class with an intellisense tip?

I want to be able to decorate classes and methods with the text that intellisense shows when you are instantiating the class or accessing a field. For example, I want to give usage instructions. I can't find the appropriate decoration for this. How do I do it? ...

Getting local variables of function

Hi, I'm trying to get a local variable from a decorator. An example: def needs_privilege(privilege, project=None): """Check whether the logged-in user is authorised based on the given privilege @type privilege: Privilege object, id, or str @param privilege: The requested privilege""" def validate(func, self, *args...