<commit_before>#!/usr/bin/env python3

import os
import stat
import sys
import time

import varlink

service = varlink.Service(
    vendor='Varlink',
    product='Varlink Examples',
    version='1',
    interface_dir=os.path.dirname(__file__)
)


class ActionFailed(varlink.VarlinkError):
    def __init__(self, reason):
        varlink.VarlinkError.__init__(self,
                                      {'error': 'org.varlink.example.more.ActionFailed',
                                       'parameters': {'field': reason}})


@service.interface('org.varlink.example.more')
class Example:
    def TestMore(self, n, _more=True):
        try:
            if not _more:
                yield varlink.InvalidParameter('more')

            yield {'state': {'start': True}, '_continues': True}

            for i in range(0, n):
                yield {'state': {'progress': int(i * 100 / n)}, '_continues': True}
                time.sleep(1)

            yield {'state': {'progress': 100}, '_continues': True}

            yield {'state': {'end': True}, '_continues': False}
        except Exception as error:
            print("ERROR", error, file=sys.stderr)

    def Ping(self, ping):
        return {'pong': ping}

    def StopServing(self):
        print("Server ends.")
        sys.exit(0)


if len(sys.argv) < 2:
    print('missing address parameter')
    sys.exit(1)

listen_fd = None

try:
    if stat.S_ISSOCK(os.fstat(3).st_mode):
        listen_fd = 3
except OSError:
    pass

with varlink.SimpleServer(service) as s:
    print("Listening on", sys.argv[1])
    try:
        s.serve(sys.argv[1], listen_fd=listen_fd)
    except KeyboardInterrupt:
        pass
<commit_msg>server-simple.py: yield an empty answer to StopServing<commit_after>#!/usr/bin/env python3

import os
import stat
import sys
import time

import varlink

service = varlink.Service(
    vendor='Varlink',
    product='Varlink Examples',
    version='1',
    interface_dir=os.path.dirname(__file__)
)


class ActionFailed(varlink.VarlinkError):
    def __init__(self, reason):
        varlink.VarlinkError.__init__(self,
                                      {'error': 'org.varlink.example.more.ActionFailed',
                                       'parameters': {'field': reason}})


@service.interface('org.varlink.example.more')
class Example:
    def TestMore(self, n, _more=True):
        try:
            if not _more:
                yield varlink.InvalidParameter('more')

            yield {'state': {'start': True}, '_continues': True}

            for i in range(0, n):
                yield {'state': {'progress': int(i * 100 / n)}, '_continues': True}
                time.sleep(1)

            yield {'state': {'progress': 100}, '_continues': True}

            yield {'state': {'end': True}, '_continues': False}
        except Exception as error:
            print("ERROR", error, file=sys.stderr)

    def Ping(self, ping):
        return {'pong': ping}

    def StopServing(self):
        yield {}
        print("Server ends.")
        sys.exit(0)


if len(sys.argv) < 2:
    print('missing address parameter')
    sys.exit(1)

listen_fd = None

try:
    if stat.S_ISSOCK(os.fstat(3).st_mode):
        listen_fd = 3
except OSError:
    pass

with varlink.SimpleServer(service) as s:
    print("Listening on", sys.argv[1])
    try:
        s.serve(sys.argv[1], listen_fd=listen_fd)
    except KeyboardInterrupt:
        pass
sys.exit(0)

{'fraction_non_alphanumeric': 0.1346153846153846, 'fraction_numerical': 0.010198135198135198, 'mean_word_length': 2.304138594802695, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '87207', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1026, 'n_words': 254}