<commit_before># encoding: utf-8

"""Marrow Schema base class definitions.

These are the most frequently used base classes provided by Marrow Schema.
"""

# ## Imports

from __future__ import unicode_literals

from warnings import warn
from inspect import isroutine
from collections import OrderedDict as odict
from .meta import Element


# ## Class Definitions

class Container(Element):
	"""The underlying machinery for handling class instantiation for schema elements whose primary purpose is
	containing other schema elements, i.e. Document, Record, CompoundWidget, etc.
	
	Association of declarative attribute names (at class construction time) is handled by the Element metaclass.
	
	Container subclasses have one additional magical property:
	
	* ``inst.__data__``
	  Primary instance data storage for all DataAttribute subclass instances.  Equivalent to ``_data`` from MongoEngine.
	"""
	
	__store__ = dict
	
	def __init__(self, *args, **kw):
		"""Process arguments and assign values to instance attributes at class instantiation time.
		
		Basically defining ``__init__`` so you don't have to.
		
		You can extend this to support validation during instantiation, or to process additional programmatic
		arguments.
		"""
		
		# Inherit behaviour from Element, notably we want to track our instantiation sequence.
		super(Container, self).__init__()
		
		# Do the heavy lifting of merging positional and keyword arguments.
		arguments = self._process_arguments(args, kw)
		
		# Prepare the attribute value warehouse for this instance.
		self.__data__ = self.__store__()
		
		# Assign valid attributes.
		for name, value in arguments.items():
			setattr(self, name, value)
	
	def _process_arguments(self, args, kw):
		"""Map positional to keyword arguments, identify invalid assignments, and return the result.
		
		This is likely generic enough to be useful as a standalone utility function, and goes to a fair amount of
		effort to ensure raised exceptions are as Python-like as possible.
		"""<commit_msg>Protections, comments.<commit_after># encoding: utf-8

"""Marrow Schema base class definitions.

These are the most frequently used base classes provided by Marrow Schema.
"""

# ## Imports

from __future__ import unicode_literals

from warnings import warn
from inspect import isroutine
from collections import OrderedDict as odict, MutableMapping
from .meta import Element


# ## Class Definitions

class Container(Element):
	"""The underlying machinery for handling class instantiation for schema elements whose primary purpose is
	containing other schema elements, i.e. Document, Record, CompoundWidget, etc.
	
	Association of declarative attribute names (at class construction time) is handled by the Element metaclass.
	
	Container subclasses have one additional magical property:
	
	* ``inst.__data__``
	  Primary instance data storage for all DataAttribute subclass instances.  Equivalent to ``_data`` from MongoEngine.
	"""
	
	__store__ = dict  # The callable used to produce a new self.__data__ instance. Should result in a MutableMapping.
	
	def __init__(self, *args, **kw):
		"""Process arguments and assign values to instance attributes at class instantiation time.
		
		Basically defining ``__init__`` so you don't have to.
		
		You can extend this to support validation during instantiation, or to process additional programmatic
		arguments.
		"""
		
		# Inherit behaviour from Element, notably we want to track our instantiation sequence.
		super(Container, self).__init__()
		
		# Do the heavy lifting of merging positional and keyword arguments.
		arguments = self._process_arguments(args, kw)
		
		# Prepare the attribute value warehouse for this instance.
		self.__data__ = self.__store__()
		
		assert isinstance(self.__data__, MutableMapping), "Data storage attribute __data__ must be a mutable mapping."
		
		# Assign valid attributes.
		for name, value in arguments.items():
			setattr(self, name, value)
	
	def _process_arguments(self, args, kw):
		"""Map positional to keyword arguments, identify invalid assignments, and return the result.
		
		This is likely generic enough to be useful as a standalone utility function, and goes to a fair amount of
		effort to ensure raised exceptions are as Python-like as possible.
		"""
{'fraction_non_alphanumeric': 0.06349578256794752, 'fraction_numerical': 0.00046860356138706655, 'mean_word_length': 4.403797468354431, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '1656462', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1018, 'n_words': 512}