Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(4)  |  Call(2)  |  Derive(0)  |  Import(2)
Open a PDS data file source (flexibly).

This method generalizes the standard open() function call.
The *source* may be a file-like object, a file, a URL, or a string.

        def open_pds(source):
	"""Open a PDS data file source (flexibly).
	
	This method generalizes the standard open() function call.
	The *source* may be a file-like object, a file, a URL, or a string.
	"""
	# if isinstance(source, file):
	# 	return source
	if hasattr(source, "read"):
		# sys.stderr.write("Identified a file-like object by read() method existence\n")
		return source

	try:
		# For universal newlines -- i.e. newlines are automatically converted to "\n", use mode "U".
		# For preserved newlines -- e.g. "\r", "\r\n", "\n", use mode "rb".
		# PDS style newlines are "\r\n", however, http://pds.jpl.nasa.gov/documents/qs/sample_image.lbl uses "\n".
		# Check if hasattr(open, 'newlines') to verify that universal newline support is enabeled.
		f = open(source, "rb")
		return f
	except (IOError, OSError):
		# sys.stderr.write("Could not open source\n")
		raise
	else:
		# sys.stderr.write("Opened source\n")
		# Re-raise to catch something hairy.
		raise
	finally:
		pass
		# sys.stderr.write("Closing previously opened file\n")
		# f.close()
		
	if isinstance(source, str):
		try:
			import cStringIO as StringIO
		except ImportError:
			import StringIO
		else:
			# sys.stderr.write("Making a file-like object from string source\n")
			return StringIO.StringIO(str(source))
        


src/p/y/pypds-RyanBalfanz-PyPDS-1.0.1/pds/imageextractor.py   PyPDS(Download)
import Image
 
from core.common import open_pds
from core.parser import Parser
from core.extractorbase import ExtractorBase, ExtractorError
		"""
		p = Parser()
		f = open_pds(source)
		if self.log: self.log.debug("Parsing '%s'" % (source))
		self.labels = p.parse(f)

src/p/y/PyPDS-HEAD/pds/imageextractor.py   PyPDS(Download)
import ImageMath
 
from core.common import open_pds
from core.parser import Parser
from core.extractorbase import ExtractorBase, ExtractorError
		"""
		p = Parser()
		f = open_pds(source)
		if self.log: self.log.debug("Parsing '%s'" % (source))
		self.labels = p.parse(f)