Example #1
0
 def _or_throw(self):
     if self.expt:
         raise exceptions.HTTPError("700 Exception", self.expt)
     if self.result.status_code >= 300:
         raise exceptions.HTTPError("{} {}".format(self.result.status_code,
                                                   self.result.reason))
     return self.result
Example #2
0
 def one(self, *args, **kargs):
     self.reraise()
     if not self.data:
         raise exceptions.HTTPError("410 Maybe Gone")
     elif len(self.data) != 1:
         raise exceptions.HTTPError("409 Conflict")
     return self.data[0]
Example #3
0
 def fetch(self, cache=None, cache_if=(200, ), one=False):
     self.reraise()
     self.cache(cache, cache_if)
     if one:
         if len(self.data) == 0:
             raise exceptions.HTTPError("410 Partial Not Found")
         if len(self.data) != 1:
             raise exceptions.HTTPError("409 Conflict")
         if isinstance(self.data, dict):
             return self.data.popitem()[1]
         return self.data[0]
     return self.data
Example #4
0
 def one(self, cache=None, cache_if=(200, ), timeout=None):
     try:
         res = self._cached_result or self.dispatch(timeout=timeout,
                                                    reraise=True)
     except (PGIntegrityError, sqlite3.IntegrityError):
         raise exceptions.HTTPError("409 Conflict")
     return res.one(cache or self._cache_timeout, cache_if)
Example #5
0
 def reraise(self):
     if self.status != NORMAL:
         self.__response.raise_for_status()
     if self.status_code >= 300:
         raise exceptions.HTTPError(
             "502 Bad Gateway", "upstream server respond as {} {}".format(
                 self.status_code, self.reason))
     return self
Example #6
0
 def fetch(self, cache=None, cache_if=(200, ), one=False):
     self.reraise()
     cache and self.cache(cache, cache_if)
     try:
         if one:
             return self.data[0]
         return self.data
     except IndexError:
         raise exceptions.HTTPError("404 Not Found")
Example #7
0
 def reraise(self):
     if self.status_code >= 300:
         try:
             self.__response.expt
         except AttributeError:
             # redircting to HTTPError
             raise exceptions.HTTPError("%d %s" %
                                        (self.status_code, self.reason))
         else:
             self.__response.raise_for_status()
     return self
Example #8
0
 def one(self, cache=None, cache_if=(200, )):
     try:
         return self.fetch(cache, cache_if, True)
     except (PGIntegrityError, sqlite3.IntegrityError):
         # primary or unique index error
         raise exceptions.HTTPError("409 Conflict")
Example #9
0
 def one (self, *args, **kargs):
     try: 
         return self.data [0]
     except IndexError:
         raise exceptions.HTTPError ("404 Not Found")
Example #10
0
 def _or_throw (self, func, timeout, cache):
     if self.result.status != 3:        
         raise exceptions.HTTPError ("502 Bad Gateway", sys.exc_info ())
     return self.result
Example #11
0
 def throw(self, status, why=""):
     raise exceptions.HTTPError(status, why)