コード例 #1
0
def render():
    req_url = request.args.get('url')
    if not req_url:
        return build_error_response(message="Error! No page specified!")
    req_url = request.args.get('url')

    version = request.args.get('version')
    ignore_cache = request.args.get("nocache")

    filterstate = get_filter_state_for_url(req_url)

    try:
        if version == "None":
            version = None
        else:
            version = ast.literal_eval(version)
    except ValueError:
        return build_error_response(
            message="Error! Historical version number must be an integer!")

    if version and ignore_cache:
        return build_error_response(
            message="Error! Cannot render a historical version with nocache!")

    if version:
        rid, tid = version

        print("Historical row id: ", rid, tid)

        ctbl = version_table(db.WebPages)

        rows = g.session.query(ctbl.c.title, ctbl.c.content) \
         .filter(ctbl.c.id == rid)                        \
         .filter(ctbl.c.transaction_id == tid)            \
         .all()

        if rows:
            row = rows.pop()
            title, content = row
            content = utilities.replace_links(content)
            cachestate = "Historical version: %s" % (version, )
    else:
        title, content, cachestate = WebMirror.API.getPage(
            req_url, ignore_cache=ignore_cache, version=version)

    # print("Render-Version: ", version, type(version))
    # print("Rendering with nocache=", ignore_cache)
    # print("Return:", cachestate)
    response = jsonify(
        title=title,
        contents=content,
        cachestate=cachestate,
        filterstate=filterstate,
        req_url=req_url,
    )
    return set_cache_control_headers(response)
コード例 #2
0
    def getContent(self, relink_replace):
        """
		At this point, we have the page content, but we need to
		replace the url/resource keys with the proper paths
		so that the page will render properly
		"""
        assert self.fetched

        content = self.job.content
        if content and relink_replace:
            content = utilities.replace_links(content)
        return content
コード例 #3
0
    def processRaw(self,
                   content,
                   mimetype='text/html',
                   starturl='http://www.example.org'):

        # Abuse the fact that functions (including lambda) are fully formed objects
        job = lambda: None

        job.url = self.url
        job.starturl = "http://www.example.org"
        job.distance = common.database.MAX_DISTANCE - 2
        fetcher = self.archiver.fetcher(self.archiver.ruleset,
                                        target_url=job.url,
                                        start_url=job.starturl,
                                        db_sess=self.archiver.db_sess,
                                        job=job,
                                        cookie_lock=False)
        print(fetcher)
        ret = fetcher.dispatchContent(content, "None", "text/html")
        content = ret['contents']
        content = utilities.replace_links(content)
        return content
コード例 #4
0
def view_rendered():
    req_url = request.args.get('url')
    if not req_url:
        return render_template('error.html',
                               title='Error',
                               message="Error! No page specified!")

    req_url = request.args.get('url')
    version = request.args.get('version')
    ignore_cache = request.args.get("nocache")

    filterstate = get_filter_state_for_url(req_url)

    try:
        if version == "None" or version is None:
            version = None
        else:
            version = ast.literal_eval(version)
    except ValueError:
        traceback.print_exc()
        return render_template(
            'error.html',
            title='Error',
            message="Error! Historical version number must be an integer!")

    if version and ignore_cache:
        return render_template(
            'error.html',
            title='Error',
            message="Error! Cannot render a historical version with nocache!")

    if version:
        rid, tid = version

        print("Historical row id: ", rid, tid)

        ctbl = version_table(db.WebPages.__table__)

        rows = g.session.query(ctbl.c.title, ctbl.c.content) \
         .filter(ctbl.c.id == rid)                        \
         .filter(ctbl.c.transaction_id == tid)            \
         .all()

        if rows:
            row = rows.pop()
            title, content = row
            content = utilities.replace_links(content)
            cachestate = "Historical version: %s" % (version, )
    else:
        title, content, cachestate = WebMirror.API.getPage(
            req_url, ignore_cache=ignore_cache, version=version)

    response = make_response(
        render_template(
            'view-rendered.html',
            req_url=req_url,
            version=version,
            title=title,
            contents=content,
            cachestate=cachestate,
            filterstate=filterstate,
        ))
    return set_cache_control_headers(response, allow_inline=True)