<commit_before>import tornado.ioloop, tornado.web

from astral.api.handlers.base import BaseHandler
from astral.models.node import Node
from astral.api.client import NodesAPI

import logging
log = logging.getLogger(__name__)


class NodeHandler(BaseHandler):
    def delete(self, node_uuid=None):
        """Remove the requesting node from the list of known nodes,
        unregistering the from the network.
        """

        if not node_uuid or node_uuid == Node.me().uuid:
            log.info("Shutting down because of request from %s",
                    self.request.remote_ip)
            tornado.ioloop.IOLoop.instance().stop()
            return

        node = Node.get_by(uuid=node_uuid)
        closest_supernode = Node.closest_supernode()
        if closest_supernode:
            log.info("Notifying closest supernode %s that %s was deleted",
                    closest_supernode, node)
            NodesAPI(closest_supernode.absolute_url()).unregister(node)
        if node == Node.me().primary_supernode:
            # TODO this should work, but there should be a more direct way to
            # re-do the supernode registration. maybe move the
            # register_with_supernode method to the Node model.
            from astral.node.bootstrap import BootstrapThread
            BootstrapThread().start()

        node.delete()

    def get(self, node_uuid=None):
        if not node_uuid:
            node = Node.get_by(uuid=Node.me().uuid)<commit_msg>Move another TODO to lighthouse.<commit_after>import tornado.ioloop, tornado.web

from astral.api.handlers.base import BaseHandler
from astral.models.node import Node
from astral.api.client import NodesAPI

import logging
log = logging.getLogger(__name__)


class NodeHandler(BaseHandler):
    def delete(self, node_uuid=None):
        """Remove the requesting node from the list of known nodes,
        unregistering the from the network.
        """

        if not node_uuid or node_uuid == Node.me().uuid:
            log.info("Shutting down because of request from %s",
                    self.request.remote_ip)
            tornado.ioloop.IOLoop.instance().stop()
            return

        node = Node.get_by(uuid=node_uuid)
        closest_supernode = Node.closest_supernode()
        if closest_supernode:
            log.info("Notifying closest supernode %s that %s was deleted",
                    closest_supernode, node)
            NodesAPI(closest_supernode.absolute_url()).unregister(node)
        if node == Node.me().primary_supernode:
            # [LH #151] this should work, but there should be a more direct way
            # to re-do the supernode registration. maybe move the
            # register_with_supernode method to the Node model.
            from astral.node.bootstrap import BootstrapThread
            BootstrapThread().start()

        node.delete()

    def get(self, node_uuid=None):
        if not node_uuid:
            node = Node.get_by(uuid=Node.me().uuid)
{'fraction_non_alphanumeric': 0.08383635144198524, 'fraction_numerical': 0.001006036217303823, 'mean_word_length': 2.4485549132947977, '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': '1331780', 'n_tokens_mistral': 826, 'n_tokens_neox': 798, 'n_words': 234}