source: mauRepo/HPFos/trunk/src/markup/opensearch/os_engine.py @ 8352

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/HPFos/trunk/src/markup/opensearch/os_engine.py@8352
Revision 8352, 2.1 KB checked in by mnagni, 9 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1'''
2Created on 24 May 2012
3
4@author: kusanagi
5'''
6
7import mimetypes
8from markup.opensearch.query import QueryTag
9from markup.opensearch.os_engine_helper import OSEngineHelper
10if not mimetypes.inited:
11    mimetypes.init()
12    if not mimetypes.types_map.has_key('.atom'):
13        mimetypes.add_type('application/atom+xml', '.atom')
14    if not mimetypes.types_map.has_key('.opensearchdescription'):       
15        mimetypes.add_type('application/opensearchdescription+xml', '.opensearchdescription')
16
17def get_mimetype(extension):
18    return mimetypes.types_map[('.%s') % (extension)] 
19
20class OSEngine(object):
21    '''
22    classdocs
23    '''
24
25    def __init__(self, osRequest, ospath, osEngineHelper = OSEngineHelper()):
26        '''
27        Constructor
28            @param osRequest: an OSREquest instance
29            @param ospath: the URL where the OpenSearch service is hosted
30            @param osEngineHelper:
31        '''
32        self.osRequest = osRequest
33        self.ospath = ospath
34        self.osEngineHelper = osEngineHelper               
35       
36    def doSearch(self, mimetype, params_values, **kwargs):
37        response = None
38        for item in self.osRequest.responses:
39            if item.extension == mimetype:
40                response = item
41        if response:
42            kwargs['params_values'] = params_values
43            queries = QueryTag.queryWithRoleRequest(mimetype, self.osRequest.query.params_model, params_values)
44            return response.generateResponse(self.osRequest.query.doSearch(**kwargs), [queries], self.ospath, **kwargs)
45        return None               
46   
47    '''
48    def generateURLPath(self, ospath):
49        """
50            Generate the proper URL path, before the parameters, for the Opensearch:URL tag.
51            This method is supposed to be overridden by classes extending OSREsponse           
52            @param ospath: same value of OSEngine.path
53            @return the default implementation return ospath.
54        """
55        return ospath
56    '''   
57   
58    def getDescription(self, ospath):
59        reqDoc = self.osRequest.getDescription(ospath)
60        self.osEngineHelper.additionalDescription(reqDoc)
61        return reqDoc
Note: See TracBrowser for help on using the repository browser.