Is it a good practice to use decorator to convert all Unicode strings to binary strings?
Question: Recently I wrote a little script to connect to servers via telnet (for some
reason all the specific programs refused to connect). The program was this:

    
    
    import telnetlib
    tn = telnetlib.Telnet('www.google.com',80)
    tn.write('GET / HTTP/1.0\n')
    tn.write('Host: www.google.com\n')
    tn.write('User-agent: Chrome\n\n')
    out = tn.read_all()
    print(out)
    

It worked perfectly in Python 2.x. But then I started using it in Python 3.x
and encounter the problem, which was that all the strings as of Python 3.x are
Unicode objects. So I started thinking how I can remedy it and came out with a
solution using a decorator.

Actually I could have put `b` before every string (there were only few of
them). But I wanted to do it as if it were a huge code snippet (just for
training and using good code practice).

The solution with a decorator is the following:

    
    
    def to_binary(f):
        def wrapper(self, *args):
            s,*args = args
            s = s.encode() #this line performs conversion to binary string
            return f(self, s, *args)
        return wrapper
    
    telnetlib.Telnet.write = to_binary(telnetlib.Telnet.write)
    

My question is:

Is this a good solution to be used in the projects in the future by me? Or I
had better prepend every string in `tn.write` with `b`, or maybe even use
something else?


Answer: It's a terrible solution, if for no other reason than it duplicates what one
of the classes in the
[`codecs`](http://docs.python.org/py3k/library/codecs.html#streamwriter-
objects) module does.

