def search(self, query, pos=0): """Search function for OpenSearch compliant website. If a template exists, a search will be executed immediately using the search template, Otherwise, given the site URL, a template will attempt to be discovered. Parameters: * query (puppy.model.Query) * pos (int) Returns: * results (puppy.model.Response) Raises: * urllib2.URLError """ if self.template: # template exists, use it to search search_url = self.template.replace( '{searchTerms}', urllib2.quote(query.search_terms)) if (pos != 0): search_url = search_url.replace('{start}', urllib2.quote(pos)) else: pass try: response = urllib2.urlopen(search_url).read() if self.results and self.xml: return Response.parse_feed(response) elif not self.results and self.xml: return Response.parse_xml_suggestions(response) elif not self.results and not self.xml: return Response.parse_json_suggestions(response) except urllib2.URLError, e: print "Opensearch for {0} failed".format(self.url)
def search(self, query, pos=0): """Search function for OpenSearch compliant website. If a template exists, a search will be executed immediately using the search template, Otherwise, given the site URL, a template will attempt to be discovered. Parameters: * query (puppy.model.Query) * pos (int) Returns: * results (puppy.model.Response) Raises: * urllib2.URLError """ if self.template: # template exists, use it to search search_url = self.template.replace("{searchTerms}", urllib2.quote(query.search_terms)) if pos != 0: search_url = search_url.replace("{start}", urllib2.quote(pos)) else: pass try: response = urllib2.urlopen(search_url).read() if self.results and self.xml: return Response.parse_feed(response) elif not self.results and self.xml: return Response.parse_xml_suggestions(response) elif not self.results and not self.xml: return Response.parse_json_suggestions(response) except urllib2.URLError, e: print "Opensearch for {0} failed".format(self.url)