예제 #1
0
def main():
    @handler()
    def respmod(request):
        request.body = b'cool woo'

    pid = os.fork()
    if pid == 0:
        e = asyncio.get_event_loop()
        e.add_signal_handler(SIGINT, lambda *args: os._exit(0))
        run(port=1334)
    else:
        start_client(pid)
예제 #2
0
        if response.endswith(b'FOUND'):
            name = response.split(b':', 1)[1].strip()
            self.future.set_result((True, name))
        else:
            self.future.set_result((False, None))


def clamav_scan(payload):
    future = asyncio.Future()
    if payload:
        scanner = ClamAVProtocol(future, payload)
        asyncio.async(loop.create_connection(lambda: scanner, host='127.0.0.1', port=3310))
    else:
        future.set_result((False, None))
    return future


@handler()
def respmod(request):
    found_virus, name = yield from clamav_scan(request.body_bytes)

    if found_virus:
        return HTTPResponse(body=b"A virus was found: " + name)
    else:
        abort(204)


if __name__ == '__main__':
    run()
예제 #3
0
#!/usr/bin/env python3

from icap import DomainCriteria, handler, run


@handler(DomainCriteria('*google.*'))
def reqmod(request):
    query = request.request_line.query

    if 'q' in query:
        request.request_line.query['q'][0] += ' without my pants'


if __name__ == '__main__':
    run(host='127.0.0.1', port=1334)
예제 #4
0
"""
Example ICAP server that implements YouTube for Schools (http://www.youtube.com/schools)
"""
from icap import run, handler, DomainCriteria

# You must enter your school's YouTube for Schools ID here for this to work.
EDUCATION_ID = ''


@handler(DomainCriteria('youtube.com'))
class YouTubeForSchools:
    def reqmod(self, request):
        request.headers['X-YouTube-Edu-Filter'] = EDUCATION_ID


if __name__ == '__main__':
    run()