apache_conf python上下文?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了apache_conf python上下文?相关的知识,希望对你有一定的参考价值。
from functools import wraps
def print_method_name(f):
@wraps(f)
def decorated(*args, **kwargs):
print("enter function: {0}, {1}, {2}".format(f.__name__, args, kwargs))
return f(*args, **kwargs)
return decorated
class Settings(object):
_singleton = {}
# attributes with defaults
__attrs__ = ('timeout', 'verbose')
@print_method_name
def __init__(self, **kwargs):
super(Settings, self).__init__()
self.__dict__ = self._singleton
@print_method_name
def __call__(self, *args, **kwargs):
# new instance of class to call
r = self.__class__()
# cache previous settings for __exit__
r.__cache = self.__dict__.copy()
map(self.__cache.setdefault, self.__attrs__)
# set new settings
self.__dict__.update(*args, **kwargs)
return r
@print_method_name
def __enter__(self):
pass
@print_method_name
def __exit__(self, *args):
# restore cached copy
self.__dict__.update(self.__cache.copy())
del self.__cache
@print_method_name
def __getattribute__(self, key):
if key in object.__getattribute__(self, '__attrs__'):
try:
return object.__getattribute__(self, key)
except AttributeError:
return None
return object.__getattribute__(self, key)
settings = Settings()
以上是关于apache_conf python上下文?的主要内容,如果未能解决你的问题,请参考以下文章
apache_conf python,vim,IDE
apache_conf [配置]的Python读取INI
apache_conf 用于生成htaccess密码的Python脚本
apache_conf [Python,Flask]与doctests一起运行测试用例
apache_conf 如何通过Python脚本发送附带文本文件的电子邮件?
apache_conf 基于SublimeText的Monokai配色方案,深入突出Python IDLE的主题