<commit_before>import settings
from src.daemons.server.commands.command import BaseCommand
from src.daemons.server.commands.exceptions import CommandError
from src.daemons.server.objects.exceptions import InvalidObjectId
from src.daemons.server.protocols.proxyamp import WhoConnectedCmd, DisconnectSessionsOnObjectCmd


class CmdExamine(BaseCommand):
    """
    Examines an object.
    """

    name = 'examine'
    aliases = ['ex', 'exa']

    def func(self, invoker, parsed_cmd):

        if not parsed_cmd.arguments:
            # No arguments means defaulting to 'here'.
            if not invoker.location:
                # This shouldn't ever happen, but...
                raise CommandError('You appear to be nowhere. Bummer.')

            user_query = 'here'
        else:
            user_query = ' '.join(parsed_cmd.arguments)

        if not user_query:
            raise CommandError('You must specify an object to examine')

        try:
            obj_match = invoker.contextual_object_search(user_query)
        except InvalidObjectId:
            obj_match = None

        if not obj_match:
            raise CommandError('No matching object found')

        appearance = self.get_appearance(obj_match, invoker)

        invoker.emit_to(appearance)

    def get_appearance(self, obj, invoker):
        """
        Checks to see whether the invoker is an admin. If so, admins get
        a very nerdy examine display that shows an object's un-parsed
        name/description, and attributes. If the invoker is a normal player,
        this will simply return the normal description.

        :rtype: str
        :returns: The object's appearance, from the invoker's perspective.
        """

        if invoker.is_admin():
            return self.get_examine_appearance(obj, invoker)
        else:
            return obj.get_appearance(invoker)

    def get_examine_appearance(self, obj, invoker):
        """
        Shows the object as it were examined.
        """

        attributes_str = ' Parent: %s (%s)\n' % (obj.parent, obj.base_type)

        if self.aliases:
            attributes_str += ' Aliases: %s\n' % ', '.join(self.aliases)

        if obj.location:
            attributes_str += ' Location: %s\n' % obj.get_appearance_name(invoker)

        if obj.zone:
            attributes_str += ' Zone: %s\n' % obj.zone.get_appearance_name(invoker)

        attributes_str += ' Description: %s\n' % obj.description<commit_msg>Correct the rendering of location on examine.<commit_after>import settings
from src.daemons.server.commands.command import BaseCommand
from src.daemons.server.commands.exceptions import CommandError
from src.daemons.server.objects.exceptions import InvalidObjectId
from src.daemons.server.protocols.proxyamp import WhoConnectedCmd, DisconnectSessionsOnObjectCmd


class CmdExamine(BaseCommand):
    """
    Examines an object.
    """

    name = 'examine'
    aliases = ['ex', 'exa']

    def func(self, invoker, parsed_cmd):

        if not parsed_cmd.arguments:
            # No arguments means defaulting to 'here'.
            if not invoker.location:
                # This shouldn't ever happen, but...
                raise CommandError('You appear to be nowhere. Bummer.')

            user_query = 'here'
        else:
            user_query = ' '.join(parsed_cmd.arguments)

        if not user_query:
            raise CommandError('You must specify an object to examine')

        try:
            obj_match = invoker.contextual_object_search(user_query)
        except InvalidObjectId:
            obj_match = None

        if not obj_match:
            raise CommandError('No matching object found')

        appearance = self.get_appearance(obj_match, invoker)

        invoker.emit_to(appearance)

    def get_appearance(self, obj, invoker):
        """
        Checks to see whether the invoker is an admin. If so, admins get
        a very nerdy examine display that shows an object's un-parsed
        name/description, and attributes. If the invoker is a normal player,
        this will simply return the normal description.

        :rtype: str
        :returns: The object's appearance, from the invoker's perspective.
        """

        if invoker.is_admin():
            return self.get_examine_appearance(obj, invoker)
        else:
            return obj.get_appearance(invoker)

    def get_examine_appearance(self, obj, invoker):
        """
        Shows the object as it were examined.
        """

        attributes_str = ' Parent: %s (%s)\n' % (obj.parent, obj.base_type)

        if self.aliases:
            attributes_str += ' Aliases: %s\n' % ', '.join(self.aliases)

        if obj.location:
            attributes_str += ' Location: %s\n' % obj.location.get_appearance_name(invoker)

        if obj.zone:
            attributes_str += ' Zone: %s\n' % obj.zone.get_appearance_name(invoker)

        attributes_str += ' Description: %s\n' % obj.description
{'fraction_non_alphanumeric': 0.09004643650312942, 'fraction_numerical': 0.0, 'mean_word_length': 2.381569965870307, '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': '7193731', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1378, 'n_words': 391}