コード例 #1
0
def _get_examples():
	names_and_bytes = None

	# z is the zip file containing the examples
	z = None
	if app_in_jar.startedFromJar():
		# App started from JAR; attempt to acquire through java.lang.Class.getResourceAsStream()
		stream = Column.getResourceAsStream('/mallard_examples.zip')

		if stream is not None:
			# Convert to cStringIO; FileUtil.wrap does not seem to work well with ZipFile
			fbytes = StringUtil.fromBytes(FileUtil.readBytes(stream))
			f = cStringIO.StringIO(fbytes)
			try:
				z = zipfile.ZipFile(f, 'r')
			except zipfile.BadZipfile:
				pass

	# App was not started from JAR, or loading failed; see if the ZIP file can be found in the file system
	if z is None:
		if os.path.isfile('mallard_examples.zip'):
			try:
				z = zipfile.ZipFile('mallard_examples.zip', 'r')
			except zipfile.BadZipfile:
				pass


	if z is not None:
		names_and_bytes = []
		infos = z.infolist()
		for info in infos:
			if info.filename.lower().endswith('.page'):
				names_and_bytes.append((info.filename, z.read(info)))
	return names_and_bytes
コード例 #2
0
 def _reader():
     return FileUtil.readBytes(jar)