Package Bio :: Package WWW :: Module SCOP
[hide private]
[frames] | no frames]

Source Code for Module Bio.WWW.SCOP

 1  # Copyright 2000 by Jeffrey Chang.  All rights reserved. 
 2  # This code is part of the Biopython distribution and governed by its 
 3  # license.  Please see the LICENSE file that should have been included 
 4  # as part of this package. 
 5   
 6  """ 
 7  Provides code to access SCOP over the WWW.  The main SCOP web page 
 8  is available at: 
 9  http://scop.mrc-lmb.cam.ac.uk/scop/ 
10   
11  Functions: 
12  search       Access the main CGI script. 
13  _open 
14   
15  """ 
16  import string 
17  import urllib 
18   
19  from Bio import File 
20   
21 -def search(pdb=None, key=None, sid=None, disp=None, dir=None, loc=None, 22 cgi='http://scop.mrc-lmb.cam.ac.uk/scop/search.cgi', **keywds):
23 """search(pdb=None, key=None, sid=None, disp=None, dir=None, loc=None, 24 cgi='http://scop.mrc-lmb.cam.ac.uk/scop/search.cgi', **keywds) 25 26 Access search.cgi and return a handle to the results. See the 27 online help file for an explanation of the parameters: 28 http://scop.mrc-lmb.cam.ac.uk/scop/help.html 29 30 Raises an IOError if there's a network error. 31 32 """ 33 params = {'pdb' : pdb, 'key' : key, 'sid' : sid, 'disp' : disp, 34 'dir' : dir, 'loc' : loc} 35 variables = {} 36 for k in params.keys(): 37 if params[k] is not None: 38 variables[k] = params[k] 39 variables.update(keywds) 40 return _open(cgi, variables)
41
42 -def _open(cgi, params={}, get=1):
43 """_open(cgi, params={}, get=1) -> UndoHandle 44 45 Open a handle to SCOP. cgi is the URL for the cgi script to access. 46 params is a dictionary with the options to pass to it. get is a boolean 47 that describes whether a GET should be used. Does some 48 simple error checking, and will raise an IOError if it encounters one. 49 50 """ 51 # Open a handle to SCOP. 52 options = urllib.urlencode(params) 53 if get: # do a GET 54 fullcgi = cgi 55 if options: 56 fullcgi = "%s?%s" % (cgi, options) 57 handle = urllib.urlopen(fullcgi) 58 else: # do a POST 59 handle = urllib.urlopen(cgi, options) 60 61 # Wrap the handle inside an UndoHandle. 62 uhandle = File.UndoHandle(handle) 63 # Should I check for 404? timeout? etc? 64 return uhandle
65