GnuCash  5.6-150-g038405b370+
Public Member Functions | Properties
python.function_class.ClassFromFunctions Class Reference
Inheritance diagram for python.function_class.ClassFromFunctions:

Public Member Functions

def __new__ (cls, args, kargs)
 
def __init__ (self, args, kargs)
 
def get_instance (self)
 
def add_method (cls, function_name, method_name)
 Add the function, method_name to this class as a method named name. More...
 
def ya_add_classmethod (cls, function_name, method_name)
 Add the function, method_name to this class as a classmethod named name. More...
 
def ya_add_method (cls, function_name, method_name)
 Add the function, method_name to this class as a method named name. More...
 
def add_methods_with_prefix (cls, prefix, exclude=[])
 
def add_constructor_and_methods_with_prefix (cls, prefix, constructor, exclude=[])
 
def decorate_functions (cls, decorator, args)
 
def decorate_method (cls, decorator, method_name, args, kargs)
 decorate method method_name of class cls with decorator decorator More...
 

Properties

 instance = property(get_instance)
 

Detailed Description

Inherit this class to give yourself a python class that wraps a set of
functions that together constitute the methods of the class.

The method functions must all have as a first argument an object
holding the instance data. There must also be a function that
returns a new instance of the class, the constructor.

Your subclass must define
_module - The module where the method functions, including the
constructor can be found
_new_instance - The name of a function that serves as a constructor,
returning the instance data.

To access the instance data, use the read-only property instance.

To add some functions from _module as methods, call classmethods like
add_method and add_methods_with_prefix.

Definition at line 31 of file function_class.py.

Constructor & Destructor Documentation

◆ __init__()

def python.function_class.ClassFromFunctions.__init__ (   self,
  args,
  kargs 
)
Construct a new instance, using either the function
self._module[self._new_instance] or using existing instance
data. (specified with the keyword argument, instance)

if instance argument is None it will be ignored and the
constructor will be called to get a new instance

Pass the arguments that should be passed on to
self._module[self._new_instance]. Any arguments of that
are instances of ClassFromFunctions will be switched with the instance
data. (by calling the .instance property)

Definition at line 57 of file function_class.py.

57  def __init__(self, *args, **kargs):
58  """Construct a new instance, using either the function
59  self._module[self._new_instance] or using existing instance
60  data. (specified with the keyword argument, instance)
61 
62  if instance argument is None it will be ignored and the
63  constructor will be called to get a new instance
64 
65  Pass the arguments that should be passed on to
66  self._module[self._new_instance]. Any arguments of that
67  are instances of ClassFromFunctions will be switched with the instance
68  data. (by calling the .instance property)
69  """
70  if INSTANCE_ARGUMENT in kargs and kargs[INSTANCE_ARGUMENT] is not None:
71  self.__instance = kargs[INSTANCE_ARGUMENT]
72  else:
73  self.__instance = getattr(self._module, self._new_instance)(
74  *process_list_convert_to_instance(args),
75  **process_dict_convert_to_instance(kargs))
76 

Member Function Documentation

◆ add_constructor_and_methods_with_prefix()

def python.function_class.ClassFromFunctions.add_constructor_and_methods_with_prefix (   cls,
  prefix,
  constructor,
  exclude = [] 
)
Add a group of functions with the same prefix, and set the
_new_instance attribute to prefix + constructor. Don't add methods
in array exclude.

Definition at line 196 of file function_class.py.

196  def add_constructor_and_methods_with_prefix(cls, prefix, constructor, exclude=[]):
197  """Add a group of functions with the same prefix, and set the
198  _new_instance attribute to prefix + constructor. Don't add methods
199  in array exclude.
200  """
201  cls.add_methods_with_prefix(prefix, exclude=exclude)
202  cls._new_instance = prefix + constructor
203 

◆ add_method()

def python.function_class.ClassFromFunctions.add_method (   cls,
  function_name,
  method_name 
)

Add the function, method_name to this class as a method named name.

arguments:

Parameters
clsClass: class to add methods to
function_namestring: name of the function to add
method_namestring: name of the method that function will be called

function will be wrapped by method_function

Definition at line 89 of file function_class.py.

89  def add_method(cls, function_name, method_name):
90  """! Add the function, method_name to this class as a method named name
91 
92  arguments:
93  @param cls Class: class to add methods to
94  @param function_name string: name of the function to add
95  @param method_name string: name of the method that function will be called
96 
97  function will be wrapped by method_function"""
98 
99  def method_function(self, *meth_func_args, **meth_func_kargs):
100  """! wrapper method for function
101 
102  arguments:
103  @param self: FunctionClass instance. Will be turned to its instance property.
104  @param *meth_func_args: arguments to be passed to function. All FunctionClass
105  objects will be turned to their respective instances.
106  @param **meth_func_kargs: keyword arguments to be passed to function. All
107  FunctionClass objects will be turned to their respective instances."""
108  return getattr(self._module, function_name)(
109  self.instance,
110  *process_list_convert_to_instance(meth_func_args),
111  **process_dict_convert_to_instance(meth_func_kargs)
112  )
113 
114  setattr(cls, method_name, method_function)
115  setattr(method_function, "__name__", method_name)
116  return method_function
117 

◆ add_methods_with_prefix()

def python.function_class.ClassFromFunctions.add_methods_with_prefix (   cls,
  prefix,
  exclude = [] 
)
Add a group of functions with the same prefix, exclude methods
in array exclude.

Definition at line 185 of file function_class.py.

185  def add_methods_with_prefix(cls, prefix, exclude=[]):
186  """Add a group of functions with the same prefix, exclude methods
187  in array exclude.
188  """
189  for function_name, function_value, after_prefix in \
190  extract_attributes_with_prefix(cls._module, prefix):
191 
192  if not (function_name in exclude):
193  cls.add_method(function_name, after_prefix)
194 

◆ decorate_method()

def python.function_class.ClassFromFunctions.decorate_method (   cls,
  decorator,
  method_name,
  args,
  kargs 
)

decorate method method_name of class cls with decorator decorator

in difference to decorate_functions() this allows to provide additional arguments for the decorator function.

arguments:

Parameters
clsclass
decoratorfunction to decorate method
method_namename of method to decorate (string)
*argspositional arguments for decorator
**kargskeyword arguments for decorator

Definition at line 211 of file function_class.py.

211  def decorate_method(cls, decorator, method_name, *args, **kargs):
212  """! decorate method method_name of class cls with decorator decorator
213 
214  in difference to decorate_functions() this allows to provide additional
215  arguments for the decorator function.
216 
217  arguments:
218  @param cls: class
219  @param decorator: function to decorate method
220  @param method_name: name of method to decorate (string)
221  @param *args: positional arguments for decorator
222  @param **kargs: keyword arguments for decorator"""
223  setattr(cls, method_name,
224  decorator(getattr(cls, method_name), *args, **kargs))
225 

◆ get_instance()

def python.function_class.ClassFromFunctions.get_instance (   self)
Get the instance data.

You can also call the instance property

Definition at line 77 of file function_class.py.

77  def get_instance(self):
78  """Get the instance data.
79 
80  You can also call the instance property
81  """
82  return self.__instance
83 

◆ ya_add_classmethod()

def python.function_class.ClassFromFunctions.ya_add_classmethod (   cls,
  function_name,
  method_name 
)

Add the function, method_name to this class as a classmethod named name.

Taken from function_class and modified from add_method() to add classmethod instead of method and not to turn self argument to self.instance.

arguments:

Parameters
clsClass: class to add methods to
function_namestring: name of the function to add
method_namestring: name of the classmethod that function will be called

function will be wrapped by method_function

Definition at line 119 of file function_class.py.

119  def ya_add_classmethod(cls, function_name, method_name):
120  """! Add the function, method_name to this class as a classmethod named name
121 
122  Taken from function_class and modified from add_method() to add classmethod
123  instead of method and not to turn self argument to self.instance.
124 
125  arguments:
126  @param cls Class: class to add methods to
127  @param function_name string: name of the function to add
128  @param method_name string: name of the classmethod that function will be called
129 
130  function will be wrapped by method_function"""
131 
132  def method_function(self, *meth_func_args, **meth_func_kargs):
133  """! wrapper method for function
134 
135  arguments:
136  @param self: FunctionClass instance.
137  @param *meth_func_args: arguments to be passed to function. All FunctionClass
138  objects will be turned to their respective instances.
139  @param **meth_func_kargs: keyword arguments to be passed to function. All
140  FunctionClass objects will be turned to their respective instances."""
141  return getattr(self._module, function_name)(
142  self,
143  *process_list_convert_to_instance(meth_func_args),
144  **process_dict_convert_to_instance(meth_func_kargs)
145  )
146 
147  setattr(cls, method_name, classmethod(method_function))
148  setattr(method_function, "__name__", method_name)
149  return method_function
150 

◆ ya_add_method()

def python.function_class.ClassFromFunctions.ya_add_method (   cls,
  function_name,
  method_name 
)

Add the function, method_name to this class as a method named name.

Taken from function_class. Modified to not turn self to self.instance as add_method() does.

arguments:

Parameters
clsClass: class to add methods to
function_namestring: name of the function to add
method_namestring: name of the method that function will be called

function will be wrapped by method_function

Definition at line 152 of file function_class.py.

152  def ya_add_method(cls, function_name, method_name):
153  """! Add the function, method_name to this class as a method named name
154 
155  Taken from function_class. Modified to not turn self to self.instance
156  as add_method() does.
157 
158  arguments:
159  @param cls Class: class to add methods to
160  @param function_name string: name of the function to add
161  @param method_name string: name of the method that function will be called
162 
163  function will be wrapped by method_function"""
164 
165  def method_function(self, *meth_func_args, **meth_func_kargs):
166  """! wrapper method for function
167 
168  arguments:
169  @param self: FunctionClass instance.
170  @param *meth_func_args: arguments to be passed to function. All FunctionClass
171  objects will be turned to their respective instances.
172  @param **meth_func_kargs: keyword arguments to be passed to function. All
173  FunctionClass objects will be turned to their respective instances."""
174  return getattr(self._module, function_name)(
175  self,
176  *process_list_convert_to_instance(meth_func_args),
177  **process_dict_convert_to_instance(meth_func_kargs)
178  )
179 
180  setattr(cls, method_name, method_function)
181  setattr(method_function, "__name__", method_name)
182  return method_function
183 

The documentation for this class was generated from the following file: