def canhandlerequest(self): """We can handle the request if it's for a file ending with .thtml.""" canhandle = FileHandler.canhandlerequest(self) and self.getselector().endswith(".tal") if not canhandle: return 0 self.talbasename = self.getselector()[:-4] self.allowpythonpath = 1 if self.config.has_option('handlers.tal.TALFileHandler', 'allowpythonpath'): self.allowpythonpath = self.config.getboolean('handlers.tal.TALFileHandler', 'allowpythonpath') return 1
def canhandlerequest(self): """We can handle the request if it's for a file ending with .thtml.""" canhandle = FileHandler.canhandlerequest( self) and self.getselector().endswith(".tal") if not canhandle: return False self.talbasename = self.getselector()[:-4] self.allowpythonpath = 1 if self.config.has_option("handlers.tal.TALFileHandler", "allowpythonpath"): self.allowpythonpath = self.config.getboolean( "handlers.tal.TALFileHandler", "allowpythonpath") return True
def test_file_handler(self): handler = FileHandler( self.selector, "", self.protocol, self.config, self.stat_result, self.vfs ) self.assertTrue(handler.canhandlerequest()) self.assertFalse(handler.isdir()) entry = handler.getentry() self.assertEqual(entry.mimetype, "text/plain") self.assertEqual(entry.type, "0") wfile = io.BytesIO() handler.write(wfile) data = wfile.getvalue().decode() self.assertEqual(data, "Test\n")
def test_file_handler_non_utf8(self): self.selector = b"/\xAE.txt".decode(errors="surrogateescape") handler = FileHandler( self.selector, "", self.protocol, self.config, self.stat_result, self.vfs ) self.assertTrue(handler.canhandlerequest()) self.assertFalse(handler.isdir()) entry = handler.getentry() self.assertEqual(entry.mimetype, "text/plain") self.assertEqual(entry.type, "0") wfile = io.BytesIO() handler.write(wfile) data = wfile.getvalue() self.assertEqual(data, b"Hello, \xAE!")
def canhandlerequest(self): if FileHandler.canhandlerequest(self): mimetype, encoding = mimetypes.guess_type(self.selector) return mimetype == 'text/html' else: return 0
def canhandlerequest(self): if FileHandler.canhandlerequest(self): mimetype, encoding = mimetypes.guess_type(self.selector) return mimetype == 'text/html' else: return 0