Exemplo n.º 1
0
 def signedOn(self):
     for channel in settings.CHANNELS:
         # If channel is more than one item tuple, second value is password
         if len(channel) > 1:
             self.join(encodings.from_unicode(channel[0]),
                       encodings.from_unicode(channel[1]))
         else:
             self.join(encodings.from_unicode(channel[0]))
     smokesignal.emit('signon', self)
Exemplo n.º 2
0
 def signedOn(self):
     for channel in settings.CHANNELS:
         # If channel is more than one item tuple, second value is password
         if len(channel) > 1:
             self.join(encodings.from_unicode(channel[0]),
                       encodings.from_unicode(channel[1]))
         else:
             self.join(encodings.from_unicode(channel[0]))
     smokesignal.emit('signon', self)
Exemplo n.º 3
0
 def signedOn(self):
     """
     Called when the client has successfully signed on to IRC. Establishes automatically
     joining channels. Sends the ``signon`` signal (see :ref:`plugins.signals`)
     """
     for channel in settings.CHANNELS:
         # If channel is more than one item tuple, second value is password
         if len(channel) > 1:
             self.join(encodings.from_unicode(channel[0]), encodings.from_unicode(channel[1]))
         else:
             self.join(encodings.from_unicode(channel[0]))
     smokesignal.emit("signon", self)
Exemplo n.º 4
0
    def _parse_argstr(self, argstr):
        """
        Parse an argument string for this command. If COMMAND_ARGS_SHLEX is set to False,
        then naive whitespace splitting is performed on the argument string. If not, a more robust
        ``shlex.split()`` is performed. For example, given the message::

            helga foo bar "baz qux"

        the former would produce arguments::

            ['bar', '"baz', 'qux"']

        while the latter would produce::

            ['bar', 'baz qux']

        """
        if self.shlex or settings.COMMAND_ARGS_SHLEX:
            argv = shlex.split(from_unicode(argstr.strip()))
        else:
            argv = argstr.strip().split(' ')

        return map(to_unicode, argv)
Exemplo n.º 5
0
    def _parse_argstr(self, argstr):
        """
        Parse an argument string for this command. If COMMAND_ARGS_SHLEX is set to False,
        then naive whitespace splitting is performed on the argument string. If not, a more robust
        ``shlex.split()`` is performed. For example, given the message::

            helga foo bar "baz qux"

        the former would produce arguments::

            ['bar', '"baz', 'qux"']

        while the latter would produce::

            ['bar', 'baz qux']

        """
        if self.shlex or settings.COMMAND_ARGS_SHLEX:
            argv = shlex.split(from_unicode(argstr.strip()))
        else:
            argv = argstr.strip().split(' ')

        return map(to_unicode, argv)
Exemplo n.º 6
0
    def render(self, request):
        """
        Renders a response for an incoming request. Handles finding and dispatching the route
        matching the incoming request path. Any response string generated will be explicitly
        encoded as a UTF-8 byte string.

        If no route patch matches the incoming request, a 404 is returned.

        If a route is found, but the request uses a method that the route handler does not
        support, a 405 is returned.

        :param request: The incoming HTTP request, ``twisted.web.http.Request``
        :returns: a string with the HTTP response content
        """
        request.setHeader('Server', 'helga')
        for pat, route in self.routes.iteritems():
            match = re.match(pat, request.path)
            if match:
                break
        else:
            request.setResponseCode(404)
            return '404 Not Found'

        # Ensure that this route handles the request method
        methods, fn = route
        if request.method.upper() not in methods:
            request.setResponseCode(405)
            return '405 Method Not Allowed'

        # Handle raised HttpErrors
        try:
            # Explicitly return a byte string. Twisted expects this
            return from_unicode(
                fn(request, self.chat_client, **match.groupdict()))
        except HttpError as e:
            request.setResponseCode(int(e.status))
            return e.message or e.response
Exemplo n.º 7
0
    def render(self, request):
        """
        Renders a response for an incoming request. Handles finding and dispatching the route
        matching the incoming request path. Any response string generated will be explicitly
        encoded as a UTF-8 byte string.

        If no route patch matches the incoming request, a 404 is returned.

        If a route is found, but the request uses a method that the route handler does not
        support, a 405 is returned.

        :param request: The incoming HTTP request, ``twisted.web.http.Request``
        :returns: a string with the HTTP response content
        """
        request.setHeader('Server', 'helga')
        for pat, route in self.routes.iteritems():
            match = re.match(pat, request.path)
            if match:
                break
        else:
            request.setResponseCode(404)
            return '404 Not Found'

        # Ensure that this route handles the request method
        methods, fn = route
        if request.method.upper() not in methods:
            request.setResponseCode(405)
            return '405 Method Not Allowed'

        # Handle raised HttpErrors
        try:
            # Explicitly return a byte string. Twisted expects this
            return from_unicode(fn(request, self.irc_client, **match.groupdict()))
        except HttpError as e:
            request.setResponseCode(e.status)
            return e.message or e.response
Exemplo n.º 8
0
def test_from_unicode_with_byte_string():
    bytes = '\xe2\x98\x83'
    retval = from_unicode(bytes)
    assert bytes == retval
    assert isinstance(retval, str)
Exemplo n.º 9
0
def test_from_unicode_with_unicode_string():
    snowman = u'☃'
    bytes = '\xe2\x98\x83'
    retval = from_unicode(snowman)
    assert bytes == retval
    assert isinstance(retval, str)
Exemplo n.º 10
0
def test_from_unicode_with_byte_string():
    bytes = '\xe2\x98\x83'
    retval = from_unicode(bytes)
    assert bytes == retval
    assert isinstance(retval, str)
Exemplo n.º 11
0
def test_from_unicode_with_unicode_string():
    snowman = u'☃'
    bytes = '\xe2\x98\x83'
    retval = from_unicode(snowman)
    assert bytes == retval
    assert isinstance(retval, str)