Commit 72132f93 authored by nextime's avatar nextime

Moved ConvenienceCaller here

parent c810fe2d
...@@ -31,8 +31,37 @@ except: ...@@ -31,8 +31,37 @@ except:
import md5 import md5
import sha1 import sha1
class ConvenienceCaller(object):
"""
This metaclass build and abstraction of an object instance so
that other objects can call it as it is a module, and permit
to the original object to setup a specific callback
to the caller so it can manage the calls originated by the caller
with local methods
"""
def __init__(self, callerfunc):
"""
@params callerfunc: function/method to be used as callback
inside the original class of the abstract object
"""
self.callerfunc=callerfunc
def __getattribute__(self, name):
"""
This do the magic, transforming every called method in a call
to the callerfunction of the original object
This method isn't intended to be called directly!
"""
callerfunc = object.__getattribute__(self, 'callerfunc')
return callerfunc(name)
from ConfigParser import SafeConfigParser from ConfigParser import SafeConfigParser
def revlist(l): l.reverse(); return l def revlist(l): l.reverse(); return l
class FakeObject(object): class FakeObject(object):
......
...@@ -132,6 +132,17 @@ class HTTPPageGetter(client.HTTPPageGetter): ...@@ -132,6 +132,17 @@ class HTTPPageGetter(client.HTTPPageGetter):
self.transport.loseConnection() self.transport.loseConnection()
def handleStatus_401(self):
self.handleStatusDefault()
self.factory.noPage(
failure.Failure(
error.Error(self.status,self.message,None)
)
)
self.quietLoss = 0
self.transport.loseConnection()
def handleStatus_301(self): def handleStatus_301(self):
l = self.headers.get('location') l = self.headers.get('location')
if not l: if not l:
...@@ -250,6 +261,7 @@ class HTTPClientFactory(client.HTTPClientFactory): ...@@ -250,6 +261,7 @@ class HTTPClientFactory(client.HTTPClientFactory):
res=(page, self.uniqueid) res=(page, self.uniqueid)
self.deferred.callback(res) self.deferred.callback(res)
def gotHeaders(self, headers): def gotHeaders(self, headers):
if self.headerscb and callable(self.headerscb): if self.headerscb and callable(self.headerscb):
self.headerscb(headers) self.headerscb(headers)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment