Exemplo n.º 1
0
 def _get_cookies(self):
     if not hasattr(self, '_cookies'):
         c = self.environ.get('HTTP_COOKIE', '')
         if not ispy3k:
             c = to_bytes(c)
         self._cookies = parse_cookie(c)
     return self._cookies
Exemplo n.º 2
0
 def _get_cookies(self):
     if not hasattr(self, '_cookies'):
         c = self.environ.get('HTTP_COOKIE', '')
         if not ispy3k:
             c = to_bytes(c)
         self._cookies = parse_cookie(c)
     return self._cookies
Exemplo n.º 3
0
 def testbytes(self):
     s = Deferred()
     elem = w('div', s)
     text = elem.render()
     self.assertFalse(text.called)
     uv = chr(678) + chr(679)
     c = to_bytes(uv)
     s.callback(c)
     self.assertTrue(text.called)
     text = text.result
     self.assertEqual(text, '<div>%s</div>' % uv)
Exemplo n.º 4
0
 def testbytes(self):
     s = Deferred()
     elem = w('div', s)
     text = elem.render()
     self.assertFalse(text.called)
     uv = chr(678) + chr(679)
     c = to_bytes(uv)
     s.callback(c)
     self.assertTrue(text.called)
     text = text.result
     self.assertEqual(text, '<div>%s</div>' % uv)
Exemplo n.º 5
0
def profile(request, callback, Response):
    tmp = tempfile.mktemp()
    out = Stream()
    prof = profiler.Profile()
    response = prof.runcall(callback)
    prof.dump_stats(tmp)
    stats = pstats.Stats(tmp, stream=out)
    #stats.strip_dirs()          # Must happen prior to sort_stats
    stats.sort_stats('time', 'calls')
    stats.print_stats()
    stats_str = out.getvalue()
    os.unlink(tmp)
    stats_str = stats_str.split('\n')
    headers = '\n'.join(make_header(stats_str[:4]))
    data = data_stream(stats_str[6:],100)
    tables = make_stat_table(request, data)
    w = Widget(cn = 'profiler')
    w.add(Widget('div', headers, cn = 'legend'))
    w.add(tabs(tables))
    content = w.render(request)
    return to_bytes('\n'.join(html_doc_stream(request, content, 200)))
Exemplo n.º 6
0
def profile(request, callback, Response):
    tmp = tempfile.mktemp()
    out = Stream()
    prof = profiler.Profile()
    response = prof.runcall(callback)
    prof.dump_stats(tmp)
    stats = pstats.Stats(tmp, stream=out)
    #stats.strip_dirs()          # Must happen prior to sort_stats
    stats.sort_stats('time', 'calls')
    stats.print_stats()
    stats_str = out.getvalue()
    os.unlink(tmp)
    stats_str = stats_str.split('\n')
    headers = '\n'.join(make_header(stats_str[:4]))
    data = data_stream(stats_str[6:], 100)
    tables = make_stat_table(request, data)
    w = Widget(cn='profiler')
    w.add(Widget('div', headers, cn='legend'))
    w.add(tabs(tables))
    content = w.render(request)
    return to_bytes('\n'.join(html_doc_stream(request, content, 200)))
Exemplo n.º 7
0
 def response(self, request):
     '''Generate the Response'''
     self.content_type, response = request.content_type, None
     if not request.exc_info:
         try:
             if request.method not in request.methods():
                 raise HttpException(status=405)
             perm = maybe_async(request.has_permission())
             while is_async(perm):
                 yield None
                 perm = maybe_async(perm)
             if is_failure(perm):
                 request.exc_info = perm.trace
             elif not perm:
                 raise PermissionDenied()
             else:
                 content = request.view(request)
         except Exception as e:
             request.exc_info = sys.exc_info()
     if request.exc_info is None:
         content = self.safe_render(request, content)
         while is_async(content):
             yield
             content = self.safe_render(request, content)
         if is_failure(content):
             request.exc_info = content.trace
             content = b''
         elif isinstance(content, WsgiResponse):
             response = content
     # Response not yet available, build it from content or exc_info
     if response is None:
         response = Response(content_type=self.content_type,
                             encoding=request.encoding)
         if request.exc_info is not None:
             content = self.website.handle_error(request, response)
         if response.content_type == 'text/html' and not request.is_xhr:
             content = '\n'.join(html_doc_stream(request, content,
                                                 response.status_code))
         response.content = (to_bytes(content, response.encoding),)
     yield self.cache(request, response)
Exemplo n.º 8
0
 def response(self, request):
     '''Generate the Response'''
     self.content_type, response = request.content_type, None
     if not request.exc_info:
         try:
             if request.method not in request.methods():
                 raise HttpException(status=405)
             perm = maybe_async(request.has_permission())
             while is_async(perm):
                 yield None
                 perm = maybe_async(perm)
             if is_failure(perm):
                 request.exc_info = perm.trace
             elif not perm:
                 raise PermissionDenied()
             else:
                 content = request.view(request)
         except Exception as e:
             request.exc_info = sys.exc_info()
     if request.exc_info is None:
         content = self.safe_render(request, content)
         while is_async(content):
             yield
             content = self.safe_render(request, content)
         if is_failure(content):
             request.exc_info = content.trace
             content = b''
         elif isinstance(content, WsgiResponse):
             response = content
     # Response not yet available, build it from content or exc_info
     if response is None:
         response = Response(content_type=self.content_type,
                             encoding=request.encoding)
         if request.exc_info is not None:
             content = self.website.handle_error(request, response)
         if response.content_type == 'text/html' and not request.is_xhr:
             content = '\n'.join(
                 html_doc_stream(request, content, response.status_code))
         response.content = (to_bytes(content, response.encoding), )
     yield self.cache(request, response)