Пример #1
0
 def parse_import(self, dom):
     file = dom.getAttribute('file')
     if file != '':
         try:
             XmlConfig(file=file)
         except Exception as e:
             st = cStringIO.StringIO()
             traceback.print_exc(file=st)
             raise Exception("Error in parsing file %s:\n%s\n%s" %
                             (file, str(e), st.getvalue()))
     module_name = dom.getAttribute('module')
     data_file = dom.getAttribute('data_file')
     if data_file != '' and module_name != '':
         try:
             pkg_resources = __import__('pkg_resources')
         except ImportError as ie:
             raise Exception("File %s tried to import a data file, which requires" \
                 " the setuptools package.  The import failed; is it installed?" % \
                     file)
         filename = pkg_resources.resource_filename(module_name, data_file)
         try:
             XmlConfig(file=filename)
         except Exception as e:
             st = cStringIO.StringIO()
             traceback.print_exc(file=st)
             raise Exception("Error in parsing file %s:\n%s\n%s" % \
                 (filename, str(e), st.getvalue()))
     elif module_name != '':
         text_node = dom.firstChild
         module = import_module(module_name)
         if text_node != None and text_node.nodeType == text_node.TEXT_NODE:
             text = str(text_node.data).strip()
             objnames = text.split(',')
             for objname in objnames:
                 objname = objname.strip()
                 if objname == '*':
                     for name in module.__dict__:
                         self.globals[name] = getattr(module, name)
                 else:
                     self.globals[objname] = getattr(module, objname)
         else:
             self.globals[module_name] = module
Пример #2
0
 def parse_import(self, dom):
     file = dom.getAttribute("file")
     if file != "":
         try:
             XmlConfig(file=file)
         except Exception as e:
             st = cStringIO.StringIO()
             traceback.print_exc(file=st)
             raise Exception("Error in parsing file %s:\n%s\n%s" % (file, str(e), st.getvalue()))
     module_name = dom.getAttribute("module")
     data_file = dom.getAttribute("data_file")
     if data_file != "" and module_name != "":
         try:
             pkg_resources = __import__("pkg_resources")
         except ImportError as ie:
             raise Exception(
                 "File %s tried to import a data file, which requires"
                 " the setuptools package.  The import failed; is it installed?" % file
             )
         filename = pkg_resources.resource_filename(module_name, data_file)
         try:
             XmlConfig(file=filename)
         except Exception as e:
             st = cStringIO.StringIO()
             traceback.print_exc(file=st)
             raise Exception("Error in parsing file %s:\n%s\n%s" % (filename, str(e), st.getvalue()))
     elif module_name != "":
         text_node = dom.firstChild
         module = import_module(module_name)
         if text_node != None and text_node.nodeType == text_node.TEXT_NODE:
             text = str(text_node.data).strip()
             objnames = text.split(",")
             for objname in objnames:
                 objname = objname.strip()
                 if objname == "*":
                     for name in module.__dict__:
                         self.globals[name] = getattr(module, name)
                 else:
                     self.globals[objname] = getattr(module, objname)
         else:
             self.globals[module_name] = module
Пример #3
0
        pkg_resources = __import__('pkg_resources')
      except ImportError, ie:
        raise Exception("File %s tried to import a data file, which requires" \
            " the setuptools package.  The import failed; is it installed?" % \
                file)
      filename = pkg_resources.resource_filename(module_name, data_file)
      try:
          XmlConfig(file=filename)
      except Exception, e:
          st = cStringIO.StringIO()
          traceback.print_exc( file=st )
          raise Exception("Error in parsing file %s:\n%s\n%s" % \
              (filename, str(e), st.getvalue()))
    elif module_name != '':
      text_node = dom.firstChild
      module = import_module( module_name )
      if text_node != None and text_node.nodeType == text_node.TEXT_NODE: 
        text = str(text_node.data).strip()
        objnames = text.split(',')
        for objname in objnames:
          objname = objname.strip()
          if objname == '*':
            for name in module.__dict__:
              self.globals[name] = getattr(module,name)
          else:
            self.globals[objname] = getattr(module,objname)
      else:
        self.globals[module_name] = module

  def parse_class( self, dom ):
    class_name = dom.getAttribute('type')