PEATSA/WebApp/JobSubmission.py
def GetPDB(pdbCode, dict={}):

	'''Fetches a pdb from the pdb. Returns a stream to the pdb contents.
	
	If dict is provided it contains the key 'stream' on success whose value is the stream.
	On fail it contains two keys 'error' and 'description'''
	
	url = "http://www.rcsb.org//pdb/download/downloadFile.do?fileFormat=pdb&compression=NO&structureId=" + pdbCode
	 
	try:
		#URLLib API changed in 2.6
		if sys.version_info[:2] == (2,5):
			import socket
			socket.setdefaulttimeout(10)
			stream = urllib2.urlopen(url)		
		else:
			stream = urllib2.urlopen(url, None, timeout=10)		

		#Check for an error
		info = stream.info()
		status = info.status
		if status is not "":
			stream = None
			dict['error'] = 'Error status %s' % str(status)
		elif not info.has_key('content-disposition'):
			stream = None
			dict['error'] = 'Request for %s returned nothing' % pdbCode
		else:
			lines = stream.readlines()
			string = "".join(lines)
			stream = StringIO.StringIO(string)
			dict['stream'] = stream
	except urllib2.HTTPError, data:
		dict['error'] = 'Unable to retrive structure for pdb code %s from the Protein Data Bank. ' % pdbCode
		dict['description'] = 'Reason: %s' % data
		stream = None
	except urllib2.URLError, data:
		dict['error'] = 'Unable to retrive structure for pdb code %s from the Protein Data Bank. ' % pdbCode
		dict['description'] = 'Reason: %s' % data.reason
		stream = None
	except Exception, data:
		dict['error'] = 'Unable to retrive structure for pdb code %s from the Protein Data Bank. ' % pdbCode
		dict['description'] = 'Reason: Encountered unexpected exception %s' % data
		stream = None
	
	return stream
Fetches a pdb from the pdb. Returns a stream to the pdb contents.
	
	If dict is provided it contains the key 'stream' on success whose value is the stream.
	On fail it contains two keys 'error' and 'description
Fetches a pdb from the pdb. Returns a stream to the pdb contents.
If dict is provided it contains the key 'stream' on success whose value is the stream.
On fail it contains two keys 'error' and 'description
Fetches a pdb from the pdb . Returns a stream to the pdb contents . If dict is provided it contains the key ' stream ' on success whose value is the stream . On fail it contains two keys ' error ' and ' description
def GetPDB(pdbCode, dict={}):
	url = "http://www.rcsb.org//pdb/download/downloadFile.do?fileFormat=pdb&compression=NO&structureId=" + pdbCode
	try:
		if sys.version_info[:2] == (2,5):
			import socket
			socket.setdefaulttimeout(10)
			stream = urllib2.urlopen(url)		
		else:
			stream = urllib2.urlopen(url, None, timeout=10)		
		info = stream.info()
		status = info.status
		if status is not "":
			stream = None
			dict['error'] = 'Error status %s' % str(status)
		elif not info.has_key('content-disposition'):
			stream = None
			dict['error'] = 'Request for %s returned nothing' % pdbCode
		else:
			lines = stream.readlines()
			string = "".join(lines)
			stream = StringIO.StringIO(string)
			dict['stream'] = stream
	except urllib2.HTTPError, data:
		dict['error'] = 'Unable to retrive structure for pdb code %s from the Protein Data Bank. ' % pdbCode
		dict['description'] = 'Reason: %s' % data
		stream = None
	except urllib2.URLError, data:
		dict['error'] = 'Unable to retrive structure for pdb code %s from the Protein Data Bank. ' % pdbCode
		dict['description'] = 'Reason: %s' % data.reason
		stream = None
	except Exception, data:
		dict['error'] = 'Unable to retrive structure for pdb code %s from the Protein Data Bank. ' % pdbCode
		dict['description'] = 'Reason: Encountered unexpected exception %s' % data
		stream = None
	return stream
def GetPDB ( pdbCode , dict = { } ) : url = "http://www.rcsb.org//pdb/download/downloadFile.do?fileFormat=pdb&compression=NO&structureId=" + pdbCode try : if sys . version_info [ : 2 ] == ( 2 , 5 ) : import socket socket . setdefaulttimeout ( 10 ) stream = urllib2 . urlopen ( url ) else : stream = urllib2 . urlopen ( url , None , timeout = 10 ) info = stream . info ( ) status = info . status if status is not "" : stream = None dict [ 'error' ] = 'Error status %s' % str ( status ) elif not info . has_key ( 'content-disposition' ) : stream = None dict [ 'error' ] = 'Request for %s returned nothing' % pdbCode else : lines = stream . readlines ( ) string = "" . join ( lines ) stream = StringIO . StringIO ( string ) dict [ 'stream' ] = stream except urllib2 . HTTPError , data : dict [ 'error' ] = 'Unable to retrive structure for pdb code %s from the Protein Data Bank. ' % pdbCode dict [ 'description' ] = 'Reason: %s' % data stream = None except urllib2 . URLError , data : dict [ 'error' ] = 'Unable to retrive structure for pdb code %s from the Protein Data Bank. ' % pdbCode dict [ 'description' ] = 'Reason: %s' % data . reason stream = None except Exception , data : dict [ 'error' ] = 'Unable to retrive structure for pdb code %s from the Protein Data Bank. ' % pdbCode dict [ 'description' ] = 'Reason: Encountered unexpected exception %s' % data stream = None return stream
Fetches a pdb from the pdb.
Fetches a pdb from the pdb .
'''Fetches a pdb from the pdb. Returns a stream to the pdb contents.
	
	If dict is provided it contains the key 'stream' on success whose value is the stream.
	On fail it contains two keys 'error' and 'description''' #URLLib API changed in 2.6 #Check for an error
pdbCode
dict