<commit_before>#!/usr/bin/env python

#This is free and unencumbered software released into the public domain.
#
#Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
#software, either in source code form or as a compiled binary, for any purpose,
#commercial or non-commercial, and by any means.
#
#In jurisdictions that recognize copyright laws, the author or authors of this
#software dedicate any and all copyright interest in the software to the public
#domain. We make this dedication for the benefit of the public at large and to
#the detriment of our heirs and successors. We intend this dedication to be an
#overt act of relinquishment in perpetuity of all present and future rights to
#this software under copyright law.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
#ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
#WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
#For more information, please refer to <https://unlicense.org/>

"""
Provides a system for the model part of the model-view-presenter paradigm.

For a safe model system, every model should follow the following rules:
- All data must be private inside a class (with field names starting with two
  underscores).
- All functions that change the data must have the ``setter`` decorator.
"""

from functools import wraps #To retain the documentation and name of the wrapped functions by these decorators.
from inspect import getargspec #Getting the number of arguments of a function, and setting up listeners for every member.
from weakref import WeakKeyDictionary,WeakSet #To automatically remove listeners and signallers if their class instances are removed.

from Luna.Logger import warning

def model(originalClass):
	"""
	.. function:: model(originalClass)
	Modifies a class such that it becomes part of the model.

	This adds signals for each of the class' members, and a ``listenTo`` method.
	Using the ``listenTo`` method, a different function can be registered to be
	called every time a certain member changes. This is intended to be used by a
	viewer to update its view of the model towards the user.

	:param originalClass: The class to turn into a part of the model.<commit_msg>Update model documentation<commit_after>#!/usr/bin/env python

#This is free and unencumbered software released into the public domain.
#
#Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
#software, either in source code form or as a compiled binary, for any purpose,
#commercial or non-commercial, and by any means.
#
#In jurisdictions that recognize copyright laws, the author or authors of this
#software dedicate any and all copyright interest in the software to the public
#domain. We make this dedication for the benefit of the public at large and to
#the detriment of our heirs and successors. We intend this dedication to be an
#overt act of relinquishment in perpetuity of all present and future rights to
#this software under copyright law.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
#ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
#WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
#For more information, please refer to <https://unlicense.org/>

"""
Provides a system for the model part of the model-view-presenter paradigm.

To use the model system properly, the following code changes are required:
- Give all classes that are part of the model the ``@model`` decorator.
- To let the view update whenever the model is changed, call the ``listenTo``
  function of the model. Supply the member of the model that contains the data,
  and a reference to the function in the view that will update the view.
- The listening functions of the view must have no parameters other than
  ``self``. Otherwise they can't be called by the signalling system.
"""

from functools import wraps #To retain the documentation and name of the wrapped functions by these decorators.
from inspect import getargspec #Getting the number of arguments of a function, and setting up listeners for every member.
from weakref import WeakKeyDictionary,WeakSet #To automatically remove listeners and signallers if their class instances are removed.

from Luna.Logger import warning

def model(originalClass):
	"""
	.. function:: model(originalClass)
	Modifies a class such that it becomes part of the model.

	This adds signals for each of the class' members, and a ``listenTo`` method.
	Using the ``listenTo`` method, a different function can be registered to be
	called every time a certain member changes. This is intended to be used by a
	viewer to update its view of the model towards the user.

	:param originalClass: The class to turn into a part of the model.
{'fraction_non_alphanumeric': 0.050738356683074595, 'fraction_numerical': 0.0, 'mean_word_length': 4.59047619047619, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1298216', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1267, 'n_words': 814}