parameters: (configuration)
return_statement: return obj
docstring: Create an object from a dict
      The dict must contains a 'class' or 'klass' key with the class path of the class we want to create
      It can contains also an 'args' key with a dictionary of arguments to pass to the constructor
docstring_summary: Create an object from a dict
      The dict must contains a 'class' or 'klass' key with the class path of the class we want to create
      It can contains also an 'args' key with a dictionary of arguments to pass to the constructor
docstring_tokens: Create an object from a dict The dict must contains a class or klass key with the class path of the class we want to create It can contains also an args key with a dictionary of arguments to pass to the constructor
function: def create_object(configuration):
      """
      Create an object from a dict
      The dict must contains a 'class' or 'klass' key with the class path of the class we want to create
      It can contains also an 'args' key with a dictionary of arguments to pass to the constructor
      """
      log = logging.getLogger(__name__)
      class_path = configuration.get('class') or configuration.get('klass')
      if class_path is None:
          log.warning('impossible to build object, class_path is empty')
          raise KeyError(
              'impossible to build a StreetNetwork, missing mandatory field in configuration: class or klass'
          )
  
      kwargs = configuration.get('args', {})
  
      try:
          if '.' not in class_path:
              log.warning('impossible to build object {}, wrongly formated class'.format(class_path))
              raise ConfigException(class_path)
  
          module_path, name = class_path.rsplit('.', 1)
          module = import_module(module_path)
          attr = getattr(module, name)
      except AttributeError as e:
          log.warning('impossible to build object {} : {}'.format(class_path, e))
          raise ConfigException(class_path)
      except ImportError:
          log.exception('impossible to build object {}, cannot find class'.format(class_path))
          raise ConfigException(class_path)
  
      try:
          obj = attr(**kwargs)  # call to the contructor, with all the args
      except TypeError as e:
          log.warning('impossible to build object {}, wrong arguments: {}'.format(class_path, e.message))
          raise ConfigException(class_path)
  
      return obj
function_tokens: def create_object ( configuration ) : log = logging . getLogger ( __name__ ) class_path = configuration . get ( 'class' ) or configuration . get ( 'klass' ) if class_path is None : log . warning ( 'impossible to build object, class_path is empty' ) raise KeyError ( 'impossible to build a StreetNetwork, missing mandatory field in configuration: class or klass' ) kwargs = configuration . get ( 'args' , { } ) try : if '.' not in class_path : log . warning ( 'impossible to build object {}, wrongly formated class' . format ( class_path ) ) raise ConfigException ( class_path ) module_path , name = class_path . rsplit ( '.' , 1 ) module = import_module ( module_path ) attr = getattr ( module , name ) except AttributeError as e : log . warning ( 'impossible to build object {} : {}' . format ( class_path , e ) ) raise ConfigException ( class_path ) except ImportError : log . exception ( 'impossible to build object {}, cannot find class' . format ( class_path ) ) raise ConfigException ( class_path ) try : obj = attr ( * * kwargs ) # call to the contructor, with all the args except TypeError as e : log . warning ( 'impossible to build object {}, wrong arguments: {}' . format ( class_path , e . message ) ) raise ConfigException ( class_path ) return obj