decorator

django signals using decorators issue

 ̄綄美尐妖づ 提交于 2019-12-11 22:02:11
问题 I have the below given structure in my project -parentDirectory -myModule __init__.py models.py handler.py models.py @register class Student(): number = models.PositiveIntegerNumber(unique=True) name = models.CharField(max_length=64) def post_delete: """some code""" def post_save: """some code""" @register class Course(SomeBaseModel): code = models.CharField(unique=True) teacher = models.CharField(max_length=64) SomeBaseModel has post_delete and post_save functions defined in it. handler.py

Using decorated OutputStream/InputStream fields in your class

感情迁移 提交于 2019-12-11 19:28:56
问题 This question may seem a little trivial at first, but I am experiencing odd OutOfMemory problems since I began implementing this. After looking through the Java Heap Dumps, I know the memory leak is related to the ObjectOutputStream variable. Without further ado, here is the code: In my constructor, I am setting up field variables that will hold my Input/Output Stream variables. Along with it, I am creating two other sets of variables for when I am specifically doing IO on custom objects and

Clarification on why decorator only called once

佐手、 提交于 2019-12-11 17:57:34
问题 I'm confused about this code I got from here: import functools def singleton(cls): """Make a class a Singleton class (only one instance)""" @functools.wraps(cls) def wrapper_singleton(*args, **kwargs): if not wrapper_singleton.instance: wrapper_singleton.instance = cls(*args, **kwargs) return wrapper_singleton.instance print('****') wrapper_singleton.instance = None return wrapper_singleton @singleton class TheOne: pass Why doesn't wrapper_singleton.instance = None set the instance to none

python apply decorator to every method in a class without inspect

守給你的承諾、 提交于 2019-12-11 17:48:03
问题 Slightly modifying the answer from Applying python decorators to methods in a class, it is possible to apply a decorator to every method in a class. Is there any way to do this without the inspect module? I've been trying to accomplish this using metaclasses and modifying __getattribute__ but I keep getting infinite recursion. From How is the __getattribute__ method used?, this can be fixed in normal classes using object.__getattribute__(self, name). Is there anything equivalent for

Babel - decorator of decorated class properties is called before instantiating class

十年热恋 提交于 2019-12-11 17:32:41
问题 Excuse me for creating a new question, I was not able to find a question addressing this matter. I am having difficulties testing my dependency injection using mocha and experimental es6+ decorators transpiled using babel. The class property decorator is being called before it should've been. injection.test.js (mocha test, using --require babel-register ) import * as DependencyInjection from '../build/decorators/DependencyInjection'; @DependencyInjection.Injectable(service => service.injected

How can a function grab decorator attached to the function inside

三世轮回 提交于 2019-12-11 17:16:33
问题 I have two decorators as timeout and retry, and I have two functions, one of them has timeout and the other one has retry, like this: @timeout(seconds=1) def func_inner(timeout): time.sleep(timeout) @retry(count=2, message="Failed command after {timeout} seconds") def func(timeout): func_inner(timeout) func(timeout=3) The thing is that when func_inner throw timeout error because of timeout decorator, I want func() to know it has an attr as timeout , and we do retry for this error and show the

Python Decorator for GAE Web-Service Security Check

蓝咒 提交于 2019-12-11 15:23:51
问题 In this post, Nick suggested a decoartor: Python/WebApp Google App Engine - testing for user/pass in the headers I'm writing an API to expose potentially dozens of methods as web-services, so the decorator sounds like a great idea. I tried to start coding one based on this sample: http://groups.google.com/group/google-appengine/browse_thread/thread/ac51cc32196d62f8/aa6ccd47f217cb9a?lnk=gst&q=timeout#aa6ccd47f217cb9a I need it compatible with Python 2.5 to run under Google App Engine (GAE).

Android - Can't Apply Decorator Pattern on Activities?

荒凉一梦 提交于 2019-12-11 15:01:56
问题 I would like to be able to dynamically build an Activity that has a few of the capabilities that we have (such as prevent scrolling, monitors internet connectivity, prevent orientation change, etc.). We don't want to have to create an abstract BaseActivity that contains all possible properties and abstract methods for all capabilities. We would have a lot of empty function implementations in subclasses of BaseActivity who only need to actually implement a few of those functions. Worse yet, if

Can I make a keyed service for AutoFac based on the type of the Open Generic

流过昼夜 提交于 2019-12-11 13:52:12
问题 I would like to make a keyedService based on the T for my Open Generic ICommandHandler. I would like to register a ConsultatCommandHanlder keyed service when the ICommandHandler has a T that inherits from ConsultantCommand Any idea how to do it? Or if it is even possible? I am new to AutoFac and am struggling. I am presently registering CommandHandler like this: //Register All Command Handlers builder.RegisterAssemblyTypes(assemblies) .As( t => t.GetInterfaces() .Where(a => a.IsClosedTypeOf

Why is my decorator breaking for this Flask-Login endpoint?

若如初见. 提交于 2019-12-11 13:03:26
问题 I've figured out how to make Flask-Login authenticate a user based on an LDAP lookup. Now I'd like to add some authorization to the mix - that is, only allow access to certain endpoints if a user has both logged in and belongs to the right groups. I'm not sure if this is the right way to do it, but I thought I could just add a decoration to an endpoint: @app.route('/top_secret') @authorize @login_required def top_secret(): return render_template("top_secret.html") and (for now) make a