> So you would like to force users to write e.g.
> 
> def uu(input,errors='strict',filename='<data>',mode=0666):
>     from cStringIO import StringIO
>     from binascii import b2a_uu
>     # using str() because of cStringIO's Unicode undesired Unicode
> behavior.
>     infile = StringIO(str(input))
>     outfile = StringIO()
>     read = infile.read
>     write = outfile.write
> 
>     # Encode
>     write('begin %o %s\n' % (mode & 0777, filename))
>     chunk = read(45)
>     while chunk:
>         write(b2a_uu(chunk))
>         chunk = read(45)
>     write(' \nend\n')
> 
>     return outfile.getvalue()
> 
> (this is adapted Py2 code taken from the uu codec)

No. I would just use uu.encode instead, which already does the loop,
and everything else. So if I really wanted a string-to-string
conversion, I would do

  infile = StringIO(input)
  outfile = StringIO()
  uu.encode(infile, outfile)
  output = outfile.getvalue()

More likely, I have file-like objects already, in which case I won't
need to create StringIO objects.

Regards,
Martin
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to