Example #1
0
 def MysqlRead(self, tank=1, contenttype='html'):
     """Reads form the Mysql db"""
     try:
         record = model.Tank.FromPrimary(self.connection, int(tank))
         if contenttype != 'html':
             return uweb3.Response(record, content_type=contenttype)
         return record
     except uweb3.model.NotExistError:
         return uweb3.Response('No such tank',
                               httpcode=404,
                               content_type='text/plain')
Example #2
0
 def SqliteRead(self, fish=1):
     """Reads form the SQLite db"""
     try:
         return model.Fish.FromPrimary(self.connection, int(fish))
     except uweb3.model.NotExistError:
         return uweb3.Response('No such fish',
                               httpcode=404,
                               content_type='text/plain')
Example #3
0
 def wrapper(*args, **kwargs):
     pageresult = f(*args, **kwargs) or {}
     if not isinstance(pageresult, uweb3.Response):
         return uweb3.Response(pageresult, content_type=content_type)
     if isinstance(pageresult, uweb3.Response):
         pageresult.content_type = content_type
     args[0].req.content_type = content_type
     return pageresult
Example #4
0
  def XSRFInvalidToken(self):
    """Returns an error message regarding an incorrect XSRF token."""
    errorpage = templateparser.FileTemplate(os.path.join(
        os.path.dirname(__file__), 'http_403.html'))
    error = """Your browser did not send us the correct token, any token at all, or a timed out token.
    Because of this we cannot allow you to perform this action at this time. Please refresh the previous page and try again."""

    return uweb3.Response(content=errorpage.Parse(error=error),
        httpcode=403, headers=self.req.response.headers)
Example #5
0
 def TextArgumentReflect(self, numeric, string, optional="test"):
     """Returns the url arguments as parsed by the router."""
     return uweb3.Response((numeric, string, optional),
                           content_type='text/plain')
Example #6
0
 def Delete(self):
     """Returns the delete string as text"""
     return uweb3.Response('delete done', content_type='text/plain')
Example #7
0
 def Put(self):
     """Returns the put data as text"""
     return uweb3.Response(self.put.getfirst('key', 'invalid'),
                           content_type='text/plain')
Example #8
0
 def Post(self):
     """Returns the posted data as json"""
     return uweb3.Response(uweb3.JSONsafestring(
         json.dumps(self.post, cls=uweb3.JsonEncoder)),
                           content_type='application/json')
Example #9
0
 def ReturnJson(self):
     """Returns a json page"""
     return uweb3.Response({'message': 'Hello, World!'},
                           content_type='application/json')
Example #10
0
 def ReturnJsonString(self):
     """Returns a string, escaped by the json handler to become a json safe tring instead."""
     return uweb3.Response('{"message": "Hello, World!"}',
                           content_type='application/json')
Example #11
0
 def XSRFInvalidToken(self, command):
   """Returns an error message regarding an incorrect XSRF token."""
   page_data = self.parser.Parse('403.html', error=command,
                                 **self.CommonBlocks('Invalid XSRF token'))
   return uweb3.Response(content=page_data, httpcode=403)