array(4) { "httpcode"=> int(413) "code"=> int(-2) "message"=> string(192) "<html><head> <title>413 Request Entity Too Large</title></head><body bgcolor="white"> <center> <h1>413 Request Entity Too Large</h1> </center> <hr> <center>nginx</center></body></html>" "data"=> array(0) { }}小于40m 同一个代码就没问题 $arr = Cosapi::upload_slice($tempFile, $bucketName,$targetFile, null, 200000);
使用装饰器,维护附加回调列表的类,再加上从C#借用的概念,我得出了如下结论:
class delegate(object):
def __init__(self, func):
self.callbacks = []
self.basefunc = func
def __iadd__(self, func):
if callable(func):
self.__isub__(func)
self.callbacks.append(func)
return self
def callback(self, func):
if callable(func):
self.__isub__(func)
self.callbacks.append(func)
return func
def __isub__(self, func):
try:
self.callbacks.remove(func)
except ValueError:
pass
return self
def __call__(self, *args, **kwargs):
result = self.basefunc(*args, **kwargs)
for func in self.callbacks:
newresult = func(result)
result = result if newresult is None else newresult
return result
用@delegate
允许其他功能“附加”到它。
@delegate
def intfactory(num):
return int(num)
函数可以添加到委托+=
(和删除-=
)。你也可以用装饰funcname.callback
来添加一个回调函数。
@intfactory.callback
def notify(num):
print "notify:", num
def increment(num):
return num+1
intfactory += increment
intfactory += lambda num: num * 2
print intfactory(3) # outputs 8
class C(object):
_oncreate = []
def __new__(cls):
return reduce(lambda x, y: y(x), cls._oncreate, super(C, cls).__new__(cls))
@classmethod
def oncreate(cls, func):
cls._oncreate.append(func)
c = C()
print hasattr(c, 'spew')
@C.oncreate
def spew(obj):
obj.spew = 42
return obj
c = C()
print c.spew
相似问题