Exemple #1
0
def readcf(fp, fname, parseFunc, accumFunc, errObj):
	fp = contread.fromfile(fp)
	while 1:
		try:
			res = fp.readcontline_ex()
			if not res:
				break
			lineno, line = res
		except contread.StartingContinuedLine:
			raise errObj, "%s: first line is a continuation" % \
			      (fname,)
		except EnvironmentError, e:
			raise errObj, "IO error reading %s: %s" % \
			      (fname, str(e))
		if line[-1] == '\n':
			line = line[:-1]
		try:
			r = parseFunc(line, lineno)
			if accumFunc:
				accumFunc(r)
		except errObj, e:
			raise errObj, "error parsing %s line %d: %s" % \
			      (fname, lineno, str(e))
def openstring(string):
	fp = StringIO.StringIO(string)
	return contread.fromfile(fp)
	def testDidClose(self):
		"""Did closing the contread file close the underlying file object?"""
		fp = StringIO.StringIO("abc")
		contread.fromfile(fp).close()
		self.assertEqual(fp.closed, 1)