decorator

Subselects in Oracle Query

Hi, could anyone tell me if it makes a difference to Oracle 10g whether I use: SELECT col1 FROM myTable WHERE col2 = 'someval' AND col3 = "someotherval" or SELECT col1 FROM SELECT col1, col2, col3 FROM ( SELECT * FROM myTable ) WHERE col2 = 'someval' ) WHERE col3 = "someotherval" According to the explain plan, the...

Python decorators and class methods and evaluation -- django memoize

I have a working memoize decorator which uses Django's cache backend to remember the result of a function for a certain amount of time. I am specifically applying this to a class method. My decorator looks like: def memoize(prefix='mysite', timeout=300, keygenfunc=None): # MUST SPECIFY A KEYGENFUNC(args, kwargs) WHICH MUST RETURN A ST...

combining decorator and state pattern in java - question about OO design

I am in the middle of solving a problem where I think it's best suited for a decorator and a state pattern. The high level setting is something like a sandwich maker and dispenser, where I have a set amount of ingredients and a few different types of sadnwiches i can make. Each ingedient has a cost associated with it. The client would be...

When is it appropriate to create a Decorator for an object, and when is it appropriate to rewrite your object to allow Strategies to be applied?

For example, suppose I have a Product class that I can add to a shopping cart. I may want to be able to package it together with another item when it is also in the cart and add a 15% discount. Should the product class be decorated with a new subclass allowing deals, or should product class be redesigned to allow the cart attach a price...

Se4t Escaping for Zend_Form element description to false

I'm having some trouble dealing with this. This is inside my Zend_Form: $about = $this->addElement('textarea', 'about', array( 'label' => 'About:', 'description' => 'some <strong>description</strong>', 'required' => false, 'filters' => array('StringTrim'), 'validator...

Understanding UML of DoFactory Design Pattern - Decorator

I am trying to understand UML diagram describing Decorator Pattern at link below http://www.dofactory.com/Patterns/PatternDecorator.aspx I don't understand why there is a "Aggregation" relation between Decorator and Component. I believe it should be composition as Decorator cannot exist without the base component. ...

python metaclasses vs class decorators

what are the main differences ? is there something i can do with one method but not with the other one ? ...

Python Decorator Problem with Docstrings

I have a problem using docstrings with decorators. Given the following example: def decorator(f): def _decorator(): print 'decorator active' f() return _decorator @decorator def foo(): '''the magic foo function''' print 'this is function foo' help(foo) Now the help doesn't show me the docstring of foo...

Should logging reside within a class who's primary purpose is not logging?

This is more of a theoretical question. Should logging reside within a class who's primary purpose is not logging? Here is a simple interface for anything that will preform a calculation on a number. public interface ICalculation { public int calculate(int number); } Here is an implementation of the ICalculation interface that...

Faking method attributes in PHP?

Is it possible to use the equivalent for .NET method attributes in PHP, or in some way simulate these? Context We have an in-house URL routing class that we like a lot. The way it works today is that we first have to register all the routes with a central route manager, like so: $oRouteManager->RegisterRoute('admin/test/', array('CAdm...

JavaScript decorators HOWTO?

Hi all, I need to decorate a 3rd party function that I can't modify so I will need to decorate it in any way. I found that in Prototype there is something to do it easily [1]. Is there any alternative to that in jQuery or in plain JavaScript? [1] http://api.prototypejs.org/language/function.html#wrap-instance%5Fmethod ...

Adding an argument to a decorator

I have this decorator, used to decorate a django view when I do not want the view to be executed if the share argument is True (handled by middleware) class no_share(object): def __init__(self, view): self.view = view def __call__(self, request, *args, **kwargs): """Don't let them in if it's shared""" i...

Subclassing a final class; or, a Degenerate Decorator

I have a number of different representations of the same kind of object; let's call it a Thing. "Thing" is a marker interface. ThingFormat0, ThingFormat1, ThingFormat2 etc. are all JavaBeans that implement Thing. (Because they are JavaBeans, a JSON marshaller automatically converts them to and from JSON automatically.) ThingFormat1 h...

Inheritance in Python Such That All Base Functions Are Called

Basically, what I want is to do this: class B: def fn(self): print 'B' class A: def fn(self): print 'A' @extendInherit class C(A,B): pass c=C() c.fn() And have the output be A B How would I implement the extendInherit decorator? ...

Decorators in Ruby (migrating from Python)

Hi. I'm spending today learning Ruby from a Python perspective. One thing I have completely failed to grapple with is an equivalent of decorators. To pare things down I'm trying to replicate a trivial Python decorator: #! /usr/bin/env python import math def document(f): def wrap(x): print "I am going to square", x ...

deleter decorator using Property in Python

Howdy, I'm playing around with property in Python and I was wondering how this @propertyName.deleter decorator works. I'm probably missing something, I could not find clear answers by Google. What I would like to achieve is when this deleter behavior is called, I can trigger other actions (e.g: using my 3d application SDK). For now j...

Is it possible to extract SCRIPT tags using SiteMesh?

I have custom JSP tags that generate some HTML content, along with some javascript functions that get called by this HTML code. In the current implementation, the SCRIPT tags are created just above the HTML code. To avoid modifying the existing code base, I want to pull up these scripts inside the HEAD section of the page using SiteMes...

How to register decorated objects in Dependency Injection frameworks (PicoContainer) ?

Hi, I want to wrap a number of classes implementing the Job interface with a JobEnabledDecorator object that determines whether or not it executes. I am having trouble figuring out how to configure this in PicoContainer, so that it knows to create the Job implementation objects with a JobEnabledDecorator wrapping them. Is this possi...

how can i use '@' by myself function like '@staticmethod'.

the next is my code,it can print 'xxx', but run wrong at last: def a(object): print 'xxx' @a def b(): return 'bbb' b() In your answers, please try to use code examples rather than text, because my English is not very good. Thank you. ...

How can I pass a variable in a decorator to function's argument in a decorated function?

Hello, I am in progress to learn Python. Hopefully someone points me to correct way. This is what I'd like to do below: def decorate(function): def wrap_function(*args, **kwargs): str = 'Hello!' # This is what I want return function(*args, **kwargs) return wrap_function @decorate def print_message(): # I'd ...