def str_to_application_class(self, an_app_key): """a configman compatible str_to_* converter""" try: app_class = str_to_python_object(self.apps[an_app_key]) except KeyError: app_class = str_to_python_object(an_app_key) try: self.application_defaults = DotDict( app_class.get_application_defaults()) except AttributeError: # no get_application_defaults, skip this step pass return app_class
def str_to_application_class(self, an_app_key): """a configman compatible str_to_* converter""" try: app_class = str_to_python_object(self.apps[an_app_key]) except KeyError: app_class = str_to_python_object(an_app_key) try: self.application_defaults = DotDict( app_class.get_application_defaults() ) except AttributeError: # no get_application_defaults, skip this step pass return app_class
def __init__( self, name, function, secret=False, ): self.name = name if isinstance(function, basestring): self.function = str_to_python_object(function) else: self.function = function self.value = None self.secret = secret
def __init__( self, name, function, secret=False, ): self.name = name if isinstance(function, (six.binary_type, six.text_type)): self.function = str_to_python_object(function) else: self.function = function self.value = None self.secret = secret
def __init__( self, name, default=None, doc=None, from_string_converter=None, to_string_converter=None, value=None, short_form=None, exclude_from_print_conf=False, exclude_from_dump_conf=False, is_argument=False, likely_to_be_changed=False, not_for_definition=False, reference_value_from=None, secret=False, has_changed=False, foreign_data=None, ): self.name = name self.short_form = short_form self.default = default if isinstance(doc, basestring): doc = doc.strip() self.doc = doc if from_string_converter is None: if default is not None: # take a qualified guess from the default value from_string_converter = self._deduce_converter(default) if isinstance(from_string_converter, basestring): from_string_converter = str_to_python_object(from_string_converter) self.from_string_converter = from_string_converter # if this is not set, the type is used in converters.py to attempt # the conversion self.to_string_converter = to_string_converter if value is None: value = default self.value = value self.is_argument = is_argument self.exclude_from_print_conf = exclude_from_print_conf self.exclude_from_dump_conf = exclude_from_dump_conf self.likely_to_be_changed = likely_to_be_changed self.not_for_definition = not_for_definition self.reference_value_from = reference_value_from self.secret = secret self.has_changed = has_changed self.foreign_data = foreign_data
def __init__( self, name, default=None, doc=None, from_string_converter=None, to_string_converter=None, value=None, short_form=None, exclude_from_print_conf=False, exclude_from_dump_conf=False, is_argument=False, likely_to_be_changed=False, not_for_definition=False, reference_value_from=None, secret=False, has_changed=False, foreign_data=None, ): self.name = name self.short_form = short_form self.default = default if isinstance(doc, (six.binary_type, six.text_type)): doc = to_str(doc).strip() self.doc = doc if from_string_converter is None: if default is not None: # take a qualified guess from the default value from_string_converter = self._deduce_converter(default) if isinstance(from_string_converter, (six.binary_type, six.text_type)): from_string_converter = str_to_python_object(from_string_converter) self.from_string_converter = from_string_converter # if this is not set, the type is used in converters.py to attempt # the conversion self.to_string_converter = to_string_converter if value is None: value = default self.value = value self.is_argument = is_argument self.exclude_from_print_conf = exclude_from_print_conf self.exclude_from_dump_conf = exclude_from_dump_conf self.likely_to_be_changed = likely_to_be_changed self.not_for_definition = not_for_definition self.reference_value_from = reference_value_from self.secret = secret self.has_changed = has_changed self.foreign_data = foreign_data
def config_filename_from_commandline(config_manager): command_line_value_source = for_getopt.ValueSource(for_getopt.getopt, config_manager) values = command_line_value_source.get_values(config_manager, ignore_mismatches=True) try: config_file_name = values['admin.conf'] except KeyError: return None if not os.path.isfile(config_file_name): # its not a file, is it a python path? try: config_object = str_to_python_object(config_file_name) return config_object except CannotConvertError: # ok give up, it's not a file nor a module path raise IOError(config_file_name) return config_file_name
def config_filename_from_commandline(config_manager): command_line_value_source = for_getopt.ValueSource( for_getopt.getopt, config_manager ) values = command_line_value_source.get_values( config_manager, ignore_mismatches=True ) try: config_file_name = values['admin.conf'] except KeyError: return None if not os.path.isfile(config_file_name): # its not a file, is it a python path? try: config_object = str_to_python_object(config_file_name) return config_object except CannotConvertError: # ok give up, it's not a file nor a module path raise IOError(config_file_name) return config_file_name
def test_str_to_python_object_nothing(self): self.assertEqual(converters.str_to_python_object(''), None)