List Info

Thread: derive class from Client




derive class from Client
user name
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-unsubscribepysvn.tigris.org
For additional commands, e-mail: users-helppysvn.tigris.org


Re: derive class from Client
user name
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:
&nbsp; &nbsp; "&quot;"
&nbsp; &nbsp; A wrapper around a pysvn client. This creates a client and wraps calls to
 &nbsp;  its functions.
 &nbsp;  "&quot;"
&nbsp; &nbsp; client = None
&nbsp; &nbsp; def __init__(self):
 ; &nbsp; &nbsp; &nbsp; "&quot;"
&nbsp; &nbsp;   ;  Create a pysvn client and use it
 &nbsp;   ; &nbsp; "&quot;"
&nbsp; &nbsp;   ;  def get_login(realm, username, may_save):
 &nbsp; &nbsp; &nbsp; &nbsp;   ; user = "me&quot;
&nbsp; &nbsp; &nbsp; &nbsp;   ;  log.debug("setting get_login with username %s" % user)
&nbsp; &nbsp; &nbsp; &nbsp;   ;  return True, user, "&quot;, False

&nbsp; &nbsp; &nbsp;   c = pysvn.Client()
   ; &nbsp; &nbsp; c.callback_get_login = get_login
  ; &nbsp; &nbsp;  c.set_store_passwords(False)
&nbsp;   ; &nbsp;  c.set_auth_cache(False)

 &nbsp;   ; &nbsp; #Using self.__dict__[] to avoid calling setattr in recursive death
&nbsp; &nbsp; &nbsp; &nbsp; self.__dict__["client"] = c

 &nbsp;  def is_url(self, url):
&nbsp; &nbsp;   ;  "&quot;"Override the default is_url which just tells you if the url looks
&nbsp; &nbsp; &nbsp; &nbsp; sane. This tries to get info on the file...
&nbsp; &nbsp;   ;  "&quot;"
&nbsp; &nbsp;   ;  try:
 ; &nbsp; &nbsp; &nbsp; &nbsp;   self.client.info2 (url)
 &nbsp;   ; &nbsp; &nbsp; &nbsp; return True
 ; &nbsp; &nbsp; &nbsp; except pysvn.ClientError:
&nbsp; &nbsp;   ; &nbsp; &nbsp;  return False
&nbsp; &nbsp; def __setattr__(self, name, val):
&nbsp; &nbsp; &nbsp; &nbsp; "&quot;"
&nbsp; &nbsp;   ;  This special method is called when setting a value that isn't found
&nbsp; &nbsp;   ;  elsewhere. It sets the same named value of the pysvn client
&nbsp; &nbsp; &nbsp;   "&quot;"
&nbsp; &nbsp;   ;  #BE CAREFUL - assigning class-scope variables anywhere in this class
&nbsp; &nbsp; &nbsp; &nbsp; #causes instant setattr recursion death
&nbsp; &nbsp;   ;  setattr(self.client, name, val)

&nbsp; &nbsp; def __getattr__(self, name):&nbsp; &nbsp; &nbsp; &nbsp; "&quot;"
&nbsp; &nbsp;   ;  This special method is called when something isn't found in the class ; &nbsp; &nbsp; &nbsp; normally. It returns the named attribute of the pysvn client this class
&nbsp; &nbsp;   ;  is wrapping.
  ; &nbsp; &nbsp;  "&quot;"
&nbsp; &nbsp;   ;  return getattr(self.client, name)


On 7/4/07, Clemens Hermann < list_subversionclhe.de"> list_subversionclhe.de&gt; 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&gt;########
import pysvn

class ExtClient(pysvn.Client):
 &nbsp;   pass
###############################

however, this gives me the following error:

###############################
Traceback (most recent call last):
&nbsp;  File "pytest.py", line 3, in <module>
   ;  class ExtClient(pysvn.Client ):
TypeError: Error when calling the metaclass bases
&nbsp; &nbsp;  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-unsubscribepysvn.tigris.org">users-unsubscribepysvn.tigris.org
For additional commands, e-mail: users-helppysvn.tigris.org">users-helppysvn.tigris.org


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )