Python callback inside class

I register a pysvn.Client.callback_get_login callback , but I want my callback to be defined under my class, as a method, and then a global function.

So in my class I want to have something like:

self.client = pysvn.Client() self.client.callback_get_login = self.get_login 

instead:

 self.client = pysvn.Client() self.client.callback_get_login = get_login 

But in the first fragment I get an error:

 pysvn._pysvn_2_7.ClientError: unhandled exception in callback_get_login 

Is there a way to assign a callback inside the class?

+4
source share
1 answer

I ran into the same problem and solved it by creating a closure for my login function:

 class DummyClient: def __init__(self): def callback_get_login(realm, username, may_save): name = raw_input("Enter your svn login : ") password = getpass.getpass("Enter your svn password :") return True, name, password, False self.client.callback_get_login = callback_get_login 
+6
source

Source: https://habr.com/ru/post/1385858/


All Articles