code: def read_rdf(sources, infmt):
      
      rdf = Graph()
  
      for source in sources:
          if isinstance(source, Graph):
              for triple in source:
                  rdf.add(triple)
              continue
  
          if source == '-':
              f = sys.stdin
          else:
              f = open(source, 'r')
  
          if infmt:
              fmt = infmt
          else:
              # determine format based on file extension
              fmt = 'xml'  # default
              if source.endswith('n3'):
                  fmt = 'n3'
              if source.endswith('ttl'):
                  fmt = 'n3'
              if source.endswith('nt'):
                  fmt = 'nt'
  
          logging.debug("Parsing input file %s (format: %s)", source, fmt)
          rdf.parse(f, format=fmt)
  
      return rdf
docs: Read a list of RDF files and/or RDF graphs. May raise an Exception.