def _query(self): """Internal method to execute the query. Returns the output of the C{urllib2.urlopen} method of the standard Python library @return: tuples with the raw request plus the expected format. @raise QueryBadFormed: If the C{HTTP return code} is C{400}. @raise Unauthorized: If the C{HTTP return code} is C{401}. @raise EndPointNotFound: If the C{HTTP return code} is C{404}. @raise EndPointInternalError: If the C{HTTP return code} is C{500}. """ request = self._createRequest() try: if self.timeout: response = urlopener(request, timeout=self.timeout) else: response = urlopener(request) return response, self.returnFormat except urllib2.HTTPError, e: if e.code == 400: raise QueryBadFormed(e.read()) elif e.code == 404: raise EndPointNotFound(e.read()) elif e.code == 401: raise Unauthorized(e.read()) elif e.code == 500: raise EndPointInternalError(e.read()) else: raise e
def _query(self): """Internal method to execute the query. Returns the output of the C{urllib2.urlopen} method of the standard Python library @return: tuples with the raw request plus the expected format """ if (self.timeout): socket.setdefaulttimeout(self.timeout) request = self._createRequest() try: response = urlopener(request) return response, self.returnFormat except urllib2.HTTPError, e: if e.code == 400: raise QueryBadFormed(e.read()) elif e.code == 404: raise EndPointNotFound(e.read()) elif e.code == 500: raise EndPointInternalError(e.read()) else: raise e