def _build_rpc_methods(class_, method_list): """Build glorified aliases to raw RPC methods""" for m in method_list: class_name = m.class_name if class_name != class_.__name__: continue if class_name == "RTorrent": caller = lambda self, arg = None, method = m:\ call_method(self, method, bool_to_int(arg)) elif class_name == "Torrent": caller = lambda self, arg = None, method = m:\ call_method(self, method, self.rpc_id, bool_to_int(arg)) elif class_name in ["Tracker", "File"]: caller = lambda self, arg = None, method = m:\ call_method(self, method, self.rpc_id, bool_to_int(arg)) elif class_name == "Peer": caller = lambda self, arg = None, method = m:\ call_method(self, method, self.rpc_id, bool_to_int(arg)) if m.docstring is None: m.docstring = "" #print(m) docstring = """{0} @note: Variable where the result for this method is stored: {1}.{2}""".format( m.docstring, class_name, m.varname) caller.__doc__ = docstring for method_name in [m.method_name] + list(m.aliases): setattr(class_, method_name, caller)
def _build_rpc_methods(class_, method_list): """Build glorified aliases to raw RPC methods""" instance = None if not inspect.isclass(class_): instance = class_ class_ = instance.__class__ for m in method_list: class_name = m.class_name if class_name != class_.__name__: continue if class_name == "RTorrent": caller = lambda self, arg = None, method = m:\ call_method(self, method, bool_to_int(arg)) elif class_name == "Torrent": caller = lambda self, arg = None, method = m:\ call_method(self, method, self.rpc_id, bool_to_int(arg)) elif class_name in ["Tracker", "File"]: caller = lambda self, arg = None, method = m:\ call_method(self, method, self.rpc_id, bool_to_int(arg)) elif class_name == "Peer": caller = lambda self, arg = None, method = m:\ call_method(self, method, self.rpc_id, bool_to_int(arg)) elif class_name == "Group": caller = lambda arg = None, method = m: \ call_method(instance, method, bool_to_int(arg)) if m.docstring is None: m.docstring = "" # print(m) docstring = """{0} @note: Variable where the result for this method is stored: {1}.{2}""".format( m.docstring, class_name, m.varname) caller.__doc__ = docstring for method_name in [m.method_name] + list(m.aliases): if instance is None: setattr(class_, method_name, caller) else: setattr(instance, method_name, caller)
def _build_rpc_methods(class_, method_list): """Build glorified aliases to raw RPC methods.""" instance = None if not inspect.isclass(class_): instance = class_ class_ = instance.__class__ for m in method_list: class_name = m.class_name if class_name != class_.__name__: continue if class_name == 'RTorrent': caller = lambda self, arg = None, method = m:\ call_method(self, method, bool_to_int(arg)) elif class_name == 'Torrent': caller = lambda self, arg = None, method = m:\ call_method(self, method, self.rpc_id, bool_to_int(arg)) elif class_name in ['Tracker', 'File']: caller = lambda self, arg = None, method = m:\ call_method(self, method, self.rpc_id, bool_to_int(arg)) elif class_name == 'Peer': caller = lambda self, arg = None, method = m:\ call_method(self, method, self.rpc_id, bool_to_int(arg)) elif class_name == 'Group': caller = lambda arg = None, method = m: \ call_method(instance, method, bool_to_int(arg)) if m.docstring is None: m.docstring = '' # print(m) docstring = """{0} @note: Variable where the result for this method is stored: {1}.{2}""".format( m.docstring, class_name, m.varname) caller.__doc__ = docstring for method_name in [m.method_name] + list(m.aliases): if instance is None: setattr(class_, method_name, caller) else: setattr(instance, method_name, caller)