예제 #1
0
 def app(self):
     return Blocker(upstream_app,
                    domains=[{
                        "domain": "giraffe.com",
                        "template": "disallow_access.html.jinja2",
                        "status": 400
                    }, {
                        "domain": "birds.com",
                        "template": "could_not_process.html.jinja2",
                        "status": 451
                    }])
예제 #2
0
파일: blocker_test.py 프로젝트: xlee/via
    def test_it_ignores_invalid_lines_in_blocklist(self, tmp_path):
        blocklist_path = str(tmp_path / "test-blocklist.txt")
        blocklist_content = """
timewaster.com blocked
invalid-line
foo bar baz

# This is a comment
"""
        _write_file(blocklist_path, blocklist_content)
        app = Blocker(upstream_app, blocklist_path)
        client = Client(app, Response)

        resp = client.get("/timewaster.com")
        assert "cannot be annotated" in resp.data
예제 #3
0
파일: blocker_test.py 프로젝트: xlee/via
    def test_it_reads_blocklist_from_file(self, file_open, tmp_path):
        blocklist_path = str(tmp_path / "test-blocklist.txt")
        _write_file(blocklist_path, "timewaster.com blocked")

        app = Blocker(upstream_app, blocklist_path)
        client = Client(app, Response)

        # The blocklist should be fetched when the app is instantiated.
        file_open.assert_called_with(blocklist_path)

        # Fetch a site that is blocked in the custom blocklist.
        resp = client.get("/timewaster.com")
        assert "cannot be annotated" in resp.data

        # Fetch a site that is not blocked in the custom blocklist,
        resp = client.get("/youtube.com")
        assert UPSTREAM_CONTENT in resp.data
예제 #4
0
파일: blocker_test.py 프로젝트: xlee/via
    def test_it_rereads_blocklist_if_mtime_changes(self, client, file_open,
                                                   tmp_path):
        blocklist_path = str(tmp_path / "test-blocklist.txt")
        _write_file(blocklist_path, "", mtime=1000)
        app = Blocker(upstream_app, blocklist_path)
        client = Client(app, Response)

        # An initial request should not re-read the blocklist file,
        # as the mtime is unchanged.
        file_open.reset_mock()

        resp = client.get("/timewaster.com")

        file_open.assert_not_called()
        assert UPSTREAM_CONTENT in resp.data

        # Simulate a change in content and mtime of the blocklist file, which
        # should cause it to be re-read on the next request.
        _write_file(blocklist_path, "timewaster.com blocked", mtime=2000)

        resp = client.get("/timewaster.com")

        file_open.assert_called_with(blocklist_path)
        assert "cannot be annotated" in resp.data
예제 #5
0
파일: app.py 프로젝트: BEASTMODE2629/via
def app(environ, start_response):
    embed_url = os.environ.get("H_EMBED_URL", "https://hypothes.is/embed.js")

    template_params = environ.get("pywb.template_params", {})
    template_params["h_embed_url"] = embed_url
    environ["pywb.template_params"] = template_params

    return pywb.apps.wayback.application(environ, start_response)


application = RequestHeaderSanitiser(app)
application = ResponseHeaderSanitiser(application)
application = Blocker(
    application,
    checkmate_host=os.environ["CHECKMATE_URL"],
    api_key=os.environ["CHECKMATE_API_KEY"],
)
application = UserAgentDecorator(application, "Hypothesis-Via")
application = ConfigExtractor(application)
application = wsgi.DispatcherMiddleware(
    application,
    {
        "/favicon.ico": static.Cling("static/favicon.ico"),
        "/robots.txt": static.Cling("static/robots.txt"),
        "/static": static.Cling("static/"),
        "/static/__pywb": static.Cling(resource_filename("pywb", "static/")),
        "/static/__shared/viewer/web/viewer.html": redirect_old_viewer,
        "/h": redirect_strip_matched_path,
        "/_status": status_endpoint,
    },
예제 #6
0
 def blocker(self, application):
     return Blocker(application,
                    checkmate_host="http://checkmate.example.com")
예제 #7
0
파일: app.py 프로젝트: liyuandan11/via
    return redirect(path, code=301)


def app(environ, start_response):
    embed_url = os.environ.get("H_EMBED_URL", "https://hypothes.is/embed.js")

    template_params = environ.get("pywb.template_params", {})
    template_params["h_embed_url"] = embed_url
    environ["pywb.template_params"] = template_params

    return pywb.apps.wayback.application(environ, start_response)


application = RequestHeaderSanitiser(app)
application = ResponseHeaderSanitiser(application)
application = Blocker(application, checkmate_host=os.environ["CHECKMATE_URL"])
application = UserAgentDecorator(application, "Hypothesis-Via")
application = ConfigExtractor(application)
application = wsgi.DispatcherMiddleware(
    application,
    {
        "/favicon.ico": static.Cling("static/favicon.ico"),
        "/robots.txt": static.Cling("static/robots.txt"),
        "/static": static.Cling("static/"),
        "/static/__pywb": static.Cling(resource_filename("pywb", "static/")),
        "/static/__shared/viewer/web/viewer.html": redirect_old_viewer,
        "/h": redirect_strip_matched_path,
    },
)
application = newrelic.agent.WSGIApplicationWrapper(application, name="proxy")
예제 #8
0
파일: app.py 프로젝트: xlee/via
    template_params = environ.get("pywb.template_params", {})
    template_params["h_embed_url"] = embed_url
    environ["pywb.template_params"] = template_params

    return pywb.apps.wayback.application(environ, start_response)


blocker_kwargs = {}
blocklist_path = os.environ.get("BLOCKLIST_PATH")
if blocklist_path:
    blocker_kwargs["blocklist_path"] = blocklist_path

application = RequestHeaderSanitiser(app)
application = ResponseHeaderSanitiser(application)
application = Blocker(application, **blocker_kwargs)
application = UserAgentDecorator(application, "Hypothesis-Via")
application = ConfigExtractor(application)
application = wsgi.DispatcherMiddleware(
    application,
    {
        "/favicon.ico": static.Cling("static/favicon.ico"),
        "/robots.txt": static.Cling("static/robots.txt"),
        "/static": static.Cling("static/"),
        "/static/__pywb": static.Cling(resource_filename("pywb", "static/")),
        "/static/__shared/viewer/web/viewer.html": redirect_old_viewer,
        "/h": redirect_strip_matched_path,
    },
)
application = newrelic.agent.WSGIApplicationWrapper(application, name="proxy")
예제 #9
0
파일: blocker_test.py 프로젝트: xlee/via
 def app(self):
     return Blocker(upstream_app)
예제 #10
0
파일: app.py 프로젝트: SenseTW/via
        self.application = application

    def __call__(self, environ, start_response):
        host_to_replace = "www.facebook.com"
        host_replacing = "m.facebook.com"
        start = environ["PATH_INFO"].find(host_to_replace)
        if start == 8 or start == 9:
            path = environ["PATH_INFO"]
            path = path[:start] + host_replacing + \
                path[start + len(host_to_replace):]
            start_response('302 Found', [('Location', path)])
            return ['1']
        return self.application(environ, start_response)


application = RequestHeaderSanitiser(app)
application = ResponseHeaderSanitiser(application)
application = Blocker(application)
application = UserAgentDecorator(application, 'Hypothesis-Via')
application = FacebookRedirector(application)
application = ConfigExtractor(application)
application = wsgi.DispatcherMiddleware(
    application, {
        '/favicon.ico': static.Cling('static/favicon.ico'),
        '/robots.txt': static.Cling('static/robots.txt'),
        '/static': static.Cling('static/'),
        '/static/__pywb': static.Cling(resource_filename('pywb', 'static/')),
        '/static/__shared/viewer/web/viewer.html': redirect_old_viewer,
        '/h': redirect_strip_matched_path,
    })
예제 #11
0
 def blocker(self, application):
     return Blocker(
         application,
         checkmate_host="http://checkmate.example.com",
         api_key="test_api_key",
     )
예제 #12
0
 def app(self):
     return Blocker(upstream_app,
                    prefixes=['/giraffe', '/birds/duck'],
                    template='your eyes are protected')