def _GetFrom(self, requested):
        """Validates that the from JID is valid.

    The JID uses the display-app-id for all apps to simulate a common case
    in production (alias === display-app-id).

    Args:
      requested: The requested from JID.

    Returns:
      string, The from JID.

    Raises:
      xmpp.InvalidJidError if the requested JID is invalid.
    """

        full_appid = os.environ.get('APPLICATION_ID')
        partition, domain_name, display_app_id = (
            app_identity.app_identity._ParseFullAppId(full_appid))
        if requested == None or requested == '':
            return display_app_id + '@appspot.com/bot'

        node, domain, resource = ('', '', '')
        at = requested.find('@')
        if at == -1:
            self.log('Invalid From JID: No \'@\' character found. JID: %s',
                     requested)
            raise xmpp.InvalidJidError()

        node = requested[:at]
        rest = requested[at + 1:]

        if rest.find('@') > -1:
            self.log('Invalid From JID: Second \'@\' character found. JID: %s',
                     requested)
            raise xmpp.InvalidJidError()

        slash = rest.find('/')
        if slash == -1:
            domain = rest
            resource = 'bot'
        else:
            domain = rest[:slash]
            resource = rest[slash + 1:]

        if resource.find('/') > -1:
            self.log('Invalid From JID: Second \'/\' character found. JID: %s',
                     requested)
            raise xmpp.InvalidJidError()

        if domain == 'appspot.com' and node == display_app_id:
            return node + '@' + domain + '/' + resource
        elif domain == display_app_id + '.appspotchat.com':
            return node + '@' + domain + '/' + resource

        self.log(
            'Invalid From JID: Must be [email protected][/resource] or '
            '[email protected][/resource]. JID: %s', requested)
        raise xmpp.InvalidJidError()
    def _GetFrom(self, requested):
        """Validates that the from JID is valid.

    Args:
      requested: The requested from JID.

    Returns:
      string, The from JID.

    Raises:
      xmpp.InvalidJidError if the requested JID is invalid.
    """

        appid = os.environ.get('APPLICATION_ID', '')
        if requested == None or requested == '':
            return appid + '@appspot.com/bot'

        node, domain, resource = ('', '', '')
        at = requested.find('@')
        if at == -1:
            self.log('Invalid From JID: No \'@\' character found. JID: %s',
                     requested)
            raise xmpp.InvalidJidError()

        node = requested[:at]
        rest = requested[at + 1:]

        if rest.find('@') > -1:
            self.log('Invalid From JID: Second \'@\' character found. JID: %s',
                     requested)
            raise xmpp.InvalidJidError()

        slash = rest.find('/')
        if slash == -1:
            domain = rest
            resource = 'bot'
        else:
            domain = rest[:slash]
            resource = rest[slash + 1:]

        if resource.find('/') > -1:
            self.log('Invalid From JID: Second \'/\' character found. JID: %s',
                     requested)
            raise xmpp.InvalidJidError()

        if domain == 'appspot.com' and node == appid:
            return node + '@' + domain + '/' + resource
        elif domain == appid + '.appspotchat.com':
            return node + '@' + domain + '/' + resource

        self.log(
            'Invalid From JID: Must be [email protected][/resource] or '
            '[email protected][/resource]. JID: %s', requested)
        raise xmpp.InvalidJidError()