|
List Info
Thread: derive class from Client
|
|
| derive class from Client |

|
2007-07-04 05:05:38 |
Hi all,
my intention is do derive a subclass from the Client class
and add
some custum non-standard functionality (filters for listings
etc.).
What I tried is:
#######<file pytest.py>########
import pysvn
class ExtClient(pysvn.Client):
pass
###############################
however, this gives me the following error:
###############################
Traceback (most recent call last):
File "pytest.py", line 3, in <module>
class ExtClient(pysvn.Client):
TypeError: Error when calling the metaclass bases
function() argument 1 must be code, not str
###############################
Ho can I derive classes from Client?
thanks in advance for any hint,
clemens
------------------------------------------------------------
---------
To unsubscribe, e-mail: users-unsubscribe pysvn.tigris.org
For additional commands, e-mail: users-help pysvn.tigris.org
|
|
| Re: derive class from Client |

|
2007-07-04 11:46:43 |
|
It's difficult as the class is written in C++ (btw, pysvn.Class() is a function that returns an object of type pysvn._class - that's why you're getting the errors about needing different function arguments). As far as I can figure out the only way to really do it is something like below.
Cheers,
Stephen
class Client: """ A wrapper around a pysvn client. This creates a client and wraps calls to its functions. """ client = None
def __init__(self): """ Create a pysvn client and use it """ def get_login(realm, username, may_save): user = "me"
log.debug("setting get_login with username %s" % user) return True, user, "", False
c = pysvn.Client() c.callback_get_login = get_login
c.set_store_passwords(False) c.set_auth_cache(False)
#Using self.__dict__[] to avoid calling setattr in recursive death self.__dict__["client"] = c
def is_url(self, url):
"""Override the default is_url which just tells you if the url looks sane. This tries to get info on the file... """ try: self.client.info2
(url) return True except pysvn.ClientError: return False def __setattr__(self, name, val): """ This special method is called when setting a value that isn't found
elsewhere. It sets the same named value of the pysvn client """ #BE CAREFUL - assigning class-scope variables anywhere in this class #causes instant setattr recursion death
setattr(self.client, name, val)
def __getattr__(self, name): """ This special method is called when something isn't found in the class normally. It returns the named attribute of the pysvn client this class
is wrapping. """ return getattr(self.client, name)
On 7/4/07, Clemens Hermann < list_subversion clhe.de">
list_subversion clhe.de> wrote:Hi all,
my intention is do derive a subclass from the Client class and add
some custum non-standard functionality (filters for listings etc.).
What I tried is:
#######<file pytest.py>######## import pysvn
class ExtClient(pysvn.Client): pass ###############################
however, this gives me the following error:
############################### Traceback (most recent call last): File "pytest.py", line 3, in <module> class ExtClient(pysvn.Client
): TypeError: Error when calling the metaclass bases function() argument 1 must be code, not str ################# | |