Beispiel #1
0
 def requestStarted(self, rq):
     if bytes(rq.requestMethod()) != b'GET':
         rq.fail(rq.RequestDenied)
         return
     url = rq.requestUrl()
     if url.host() != FAKE_HOST or url.scheme() != FAKE_PROTOCOL:
         rq.fail(rq.UrlNotFound)
         return
     name = url.path()[1:]
     try:
         c = current_container()
         if not c.has_name(name):
             rq.fail(rq.UrlNotFound)
             return
         mime_type = c.mime_map.get(name, 'application/octet-stream')
         if mime_type in OEB_DOCS:
             mime_type = XHTML_MIME
             self.requests[name].append((mime_type, rq))
             QTimer.singleShot(0, self.check_for_parse)
         else:
             data = get_data(name)
             if isinstance(data, unicode_type):
                 data = data.encode('utf-8')
             mime_type = {
                 # Prevent warning in console about mimetype of fonts
                 'application/vnd.ms-opentype': 'application/x-font-ttf',
                 'application/x-font-truetype': 'application/x-font-ttf',
                 'application/font-sfnt': 'application/x-font-ttf',
             }.get(mime_type, mime_type)
             send_reply(rq, mime_type, data)
     except Exception:
         import traceback
         traceback.print_exc()
         rq.fail(rq.RequestFailed)
Beispiel #2
0
 def requestStarted(self, rq):
     if bytes(rq.requestMethod()) != b'GET':
         return self.fail_request(rq, QWebEngineUrlRequestJob.Error.RequestDenied)
     url = rq.requestUrl()
     host = url.host()
     if host not in self.allowed_hosts:
         return self.fail_request(rq)
     q = parse_qs(url.query())
     if not q:
         return self.fail_request(rq)
     mt = q.get('mime-type', ('text/plain',))[0]
     data = q.get('data', ('',))[0].encode('utf-8')
     send_reply(rq, mt, data)
Beispiel #3
0
    def check_for_parse(self):
        remove = []
        for name, requests in iteritems(self.requests):
            data = parse_worker.get_data(name)
            if data is not None:
                if not isinstance(data, bytes):
                    data = data.encode('utf-8')
                for mime_type, rq in requests:
                    send_reply(rq, mime_type, data)
                remove.append(name)
        for name in remove:
            del self.requests[name]

        if self.requests:
            return QTimer.singleShot(10, self.check_for_parse)