'Handle encoding of line.
Can be overridden by subclasses to change encoding behaviour.'

def encode(self, line):

    try:
        return line.encode(self.encoding)
    except UnicodeError:
        logger.warning(u'Stopping    actor    due    to    encode    problem,    data    supplied    by    client    was    not    valid    %s', self.encoding)
        self.stop()
