<commit_before>
import unittest
import paasmaker
import colander
import logging

# From http://stackoverflow.com/questions/452969/does-python-have-an-equivalent-to-java-class-forname
def get_class( kls ):
	parts = kls.split('.')
	module = ".".join(parts[:-1])
	m = __import__( module )
	for comp in parts[1:]:
		m = getattr(m, comp)
	return m

class PluginMixin(object):
	def get_options_schema(self):
		raise NotImplementedError("You must implement get_options_schema")
	def get_parameters_schema(self):
		raise NotImplementedError("You must implement get_parameters_schema")

	def __init__(self, configuration, options, parameters, logger = None):
		self.configuration = configuration
		self.raw_options = options
		self.raw_parameters = parameters

		if not logger:
			self.logger = logging.getLogger('paasmaker.plugin.' + self.__class__.__name__)
			self.logger.addHandler(logging.NullHandler())
		else:
			self.logger = logger

	def check_options(self):
		try:
			# Validate.
			options_schema = self.get_options_schema()
			self.options = options_schema.deserialize(self.raw_options)
			# And flatten.
			self.options_flat = options_schema.flatten(self.options)
		except colander.Invalid, ex:
			# Raise another exception that encapsulates more context.
			# In future this can be used to print a nicer report.
			# Because the default output is rather confusing...!
			raise paasmaker.common.configuration.InvalidConfigurationException(ex, '', self.raw_options)

	def check_parameters(self):
		try:
			# Validate.
			parameters_schema = self.get_parameters_schema()
			self.parameters = parameters_schema.deserialize(self.raw_parameters)
			# And flatten.
			self.parameters_flat = parameters_schema.flatten(self.parameters)
		except colander.Invalid, ex:
			# Raise another exception that encapsulates more context.
			# In future this can be used to print a nicer report.
			# Because the default output is rather confusing...!
			raise paasmaker.common.configuration.InvalidConfigurationException(ex, '', self.raw_parameters)

	def get_flat_option(self, key):
		return self.options_flat[key]
	def get_flat_parameter(self, key):<commit_msg>Rearranged code in the plugin mixin to make it a bit clearer.<commit_after>
import unittest
import paasmaker
import colander
import logging

# From http://stackoverflow.com/questions/452969/does-python-have-an-equivalent-to-java-class-forname
def get_class( kls ):
	parts = kls.split('.')
	module = ".".join(parts[:-1])
	m = __import__( module )
	for comp in parts[1:]:
		m = getattr(m, comp)
	return m

class PluginMixin(object):
	def __init__(self, configuration, options, parameters, logger = None):
		self.configuration = configuration
		self.raw_options = options
		self.raw_parameters = parameters

		if not logger:
			self.logger = logging.getLogger('paasmaker.plugin.' + self.__class__.__name__)
			self.logger.addHandler(logging.NullHandler())
		else:
			self.logger = logger

	def get_options_schema(self):
		raise NotImplementedError("You must implement get_options_schema")
	def get_parameters_schema(self):
		raise NotImplementedError("You must implement get_parameters_schema")

	def check_options(self):
		try:
			# Validate.
			options_schema = self.get_options_schema()
			self.options = options_schema.deserialize(self.raw_options)
			# And flatten.
			self.options_flat = options_schema.flatten(self.options)
		except colander.Invalid, ex:
			# Raise another exception that encapsulates more context.
			# In future this can be used to print a nicer report.
			# Because the default output is rather confusing...!
			raise paasmaker.common.configuration.InvalidConfigurationException(ex, '', self.raw_options)

	def check_parameters(self):
		try:
			# Validate.
			parameters_schema = self.get_parameters_schema()
			self.parameters = parameters_schema.deserialize(self.raw_parameters)
			# And flatten.
			self.parameters_flat = parameters_schema.flatten(self.parameters)
		except colander.Invalid, ex:
			# Raise another exception that encapsulates more context.
			# In future this can be used to print a nicer report.
			# Because the default output is rather confusing...!
			raise paasmaker.common.configuration.InvalidConfigurationException(ex, '', self.raw_parameters)

	def get_flat_option(self, key):
		return self.options_flat[key]
	def get_flat_parameter(self, key):
{'fraction_non_alphanumeric': 0.09595029912563277, 'fraction_numerical': 0.0036815462494247586, 'mean_word_length': 4.7272727272727275, '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': '5866919', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1276, 'n_words': 336}