+ self.wview.connect('resource-load-started', self.log_resources)
+
+ if html:
+ self.wview.load_html(html, uri)
+ else:
+ self.wview.load_uri(uri)
+
+ def close(self, window, event):
+ self.closed = True
+ Gtk.main_quit()
+
+ def log_resources(self, webview, resource, request):
+ if self.verbose > 1:
+ print('[REQUEST] %s for resource %s' % (request.get_http_method() or 'Request', resource.get_uri()), file=stderr)
+ if self.verbose > 2:
+ resource.connect('finished', self.log_resource_details, request)
+
+ def log_resource_details(self, resource, request):
+ m = request.get_http_method() or 'Request'
+ uri = resource.get_uri()
+ rs = resource.get_response()
+ h = rs.get_http_headers() if rs else None
+ if h:
+ ct, cl = h.get_content_type(), h.get_content_length()
+ content_type, charset = ct[0], ct.params.get('charset')
+ content_details = '%d bytes of %s%s for ' % (cl, content_type, ('; charset='+charset) if charset else '')
+ print('[RECEIVE] %sresource %s %s' % (content_details if h else '', m, uri), file=stderr)
+
+ def log_resource_text(self, resource, result, content_type, charset=None, show_headers=None):
+ data = resource.get_data_finish(result)
+ content_details = '%d bytes of %s%s for ' % (len(data), content_type, ('; charset='+charset) if charset else '')
+ print('[DATA ] %sresource %s' % (content_details, resource.get_uri()), file=stderr)
+ if show_headers:
+ for h,v in show_headers.items():
+ print('%s: %s' % (h, v), file=stderr)
+ print(file=stderr)
+ if charset or content_type.startswith('text/'):
+ print(data.decode(charset or 'utf-8'), file=stderr)