<commit_before>"""This module hides the gory details of async'ly interacting
with the nonce store to determine if a mac key identifier plus
nonce combination has been previously used."""

import logging

import tornadoasyncmemcache as memcache


_logger = logging.getLogger("AUTHSERVER.%s" % __name__)


"""```nonce_store``` is a collection of host+port strings
that point to the memcached cluster that implements the
nonce store."""
nonce_store = None


class AsyncNonceChecker(object):
    """Wraps the gory details of async'ing confirming that a
    nonce + mac_key_identifer pair isn't known to the nonce
    store (which is a memcached cluster)."""

    _ccs = None

    def __init__(self, mac_key_identifier, nonce):
        object.__init__(self)

        self._mac_key_identifier = mac_key_identifier
        self._nonce = nonce

    def fetch(self, callback):
        """Make an async request to the nonce store to
        determine if ```nonce``` has been used for
        ```mac_key_identifier```. If ```nonce``` has **not**
        been used for ```mac_key_identifier``` then
        asyc'ly ask the monce store to record that ```nonce```
        should now be considered used for ```mac_key_identifier```.
        Once all this is done, call ```callback``` with the
        results. ```callback``` is assumed to be a callable that
        takes a single boolean argument that is True if
        ```nonce``` has not been used by ```mac_key_identifier```
        and otherwise False."""
        try:
            if self.__class__._ccs is None:
                _logger.info(
                    "Creating 'memcache.ClientPool()' for cluster '%s'",
                    nonce_store)
                self.__class__._ccs = memcache.ClientPool(
                    nonce_store,
                    maxclients=100)

            self._callback = callback

            self._key = "%s-%s" % (self._mac_key_identifier, self._nonce)
            _logger.info("Asking for nonce key '%s'", self._key)<commit_msg>A start at a real set of unit tests for the auth server's async_nonce_checker module. Dave.<commit_after>"""This module hides the gory details of async'ly interacting
with the nonce store to determine if a mac key identifier plus
nonce combination has been previously used."""

import logging

import tornadoasyncmemcache


nonce_store = ['localhost:11211']


_logger = logging.getLogger("AUTHSERVER.%s" % __name__)


"""```nonce_store``` is a collection of host+port strings
that point to the memcached cluster that implements the
nonce store."""
nonce_store = None


class AsyncNonceChecker(object):
    """Wraps the gory details of async'ing confirming that a
    nonce + mac_key_identifer pair isn't known to the nonce
    store (which is a memcached cluster)."""

    _ccs = None

    def __init__(self, mac_key_identifier, nonce):
        object.__init__(self)

        self._mac_key_identifier = mac_key_identifier
        self._nonce = nonce

    def fetch(self, callback):
        """Make an async request to the nonce store to
        determine if ```nonce``` has been used for
        ```mac_key_identifier```. If ```nonce``` has **not**
        been used for ```mac_key_identifier``` then
        asyc'ly ask the monce store to record that ```nonce```
        should now be considered used for ```mac_key_identifier```.
        Once all this is done, call ```callback``` with the
        results. ```callback``` is assumed to be a callable that
        takes a single boolean argument that is True if
        ```nonce``` has not been used by ```mac_key_identifier```
        and otherwise False."""
        try:
            if self.__class__._ccs is None:
                _logger.info(
                    "Creating 'tornadoasyncmemcache.ClientPool()' for cluster '%s'",
                    nonce_store)
                self.__class__._ccs = tornadoasyncmemcache.ClientPool(
                    nonce_store,
                    maxclients=100)

            self._callback = callback

            self._key = "%s-%s" % (self._mac_key_identifier, self._nonce)
            _logger.info("Asking for nonce key '%s'", self._key)
{'fraction_non_alphanumeric': 0.09584741670690487, 'fraction_numerical': 0.002655721873491067, 'mean_word_length': 2.65666372462489, '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': '4803802', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1130, 'n_words': 418}