<commit_before># This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from snorky.services.base import RPCService, RPCError, rpc_command
from snorky.services.datasync.managers.dealer import DealerManager
from snorky.services.datasync.managers.subscription import SubscriptionManager
from snorky.services.datasync.subscription import \
        Subscription, SubscriptionItem
from snorky.services.datasync.delta import \
        InsertionDelta, UpdateDelta, DeletionDelta
from snorky.timeout import TornadoTimeoutFactory
from snorky.log import snorky_log
from snorky.types import is_string
import functools


class DataSyncBackend(RPCService):
    def __init__(self, name, frontend, timeout_interval=120,
                 timeout_factory=None):
        super(DataSyncBackend, self).__init__(name)

        self.frontend = frontend
        self.timeout_interval = timeout_interval
        self.timeout_factory = timeout_factory or TornadoTimeoutFactory

    @rpc_command
    def authorizeSubscription(self, req, items):
        """Requests a subscription authorization token.

        :param dict items: Subscription items to be authorized.

            Each item must be a dictionary with two properties: ``dealer`` and
            ``query``.
        """
        obj_items = []
        try:
            for item in items:
                dealer_name = item["dealer"]

                if not is_string(dealer_name):
                    raise RPCError("dealer should be a dealer name")
                elif dealer_name not in self.frontend.dm.dealers_by_name:
                    raise RPCError("No such dealer")

                obj_item = SubscriptionItem(dealer_name, item["query"])
                obj_items.append(obj_item)
        except KeyError:
            raise RPCError("Missing field")

        subscription = Subscription(obj_items, self.frontend)
        token = self.frontend.sm.register_subscription(subscription)
        self.frontend.dm.connect_subscription(subscription)

        subscription._awaited_client_timeout = self.timeout_factory.call_later(
                self.timeout_interval, self.frontend.do_cancel_subscription,
                subscription)
<commit_msg>Indicate missing field<commit_after># This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from snorky.services.base import RPCService, RPCError, rpc_command
from snorky.services.datasync.managers.dealer import DealerManager
from snorky.services.datasync.managers.subscription import SubscriptionManager
from snorky.services.datasync.subscription import \
        Subscription, SubscriptionItem
from snorky.services.datasync.delta import \
        InsertionDelta, UpdateDelta, DeletionDelta
from snorky.timeout import TornadoTimeoutFactory
from snorky.log import snorky_log
from snorky.types import is_string
import functools


class DataSyncBackend(RPCService):
    def __init__(self, name, frontend, timeout_interval=120,
                 timeout_factory=None):
        super(DataSyncBackend, self).__init__(name)

        self.frontend = frontend
        self.timeout_interval = timeout_interval
        self.timeout_factory = timeout_factory or TornadoTimeoutFactory

    @rpc_command
    def authorizeSubscription(self, req, items):
        """Requests a subscription authorization token.

        :param dict items: Subscription items to be authorized.

            Each item must be a dictionary with two properties: ``dealer`` and
            ``query``.
        """
        obj_items = []
        try:
            for item in items:
                dealer_name = item["dealer"]

                if not is_string(dealer_name):
                    raise RPCError("dealer should be a dealer name")
                elif dealer_name not in self.frontend.dm.dealers_by_name:
                    raise RPCError("No such dealer")

                obj_item = SubscriptionItem(dealer_name, item["query"])
                obj_items.append(obj_item)
        except KeyError as field:
            raise RPCError("Missing field %s" % field)

        subscription = Subscription(obj_items, self.frontend)
        token = self.frontend.sm.register_subscription(subscription)
        self.frontend.dm.connect_subscription(subscription)

        subscription._awaited_client_timeout = self.timeout_factory.call_later(
                self.timeout_interval, self.frontend.do_cancel_subscription,
                subscription)

{'fraction_non_alphanumeric': 0.070347473886165, 'fraction_numerical': 0.002984438286079727, 'mean_word_length': 2.8333333333333335, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4920593', 'n_tokens_mistral': 1275, 'n_tokens_neox': 1246, 'n_words': 344}