[Python-3000] Reimplementing TextIOWrapper in C?
Brett Cannon
brett at python.org
Fri Dec 28 23:41:27 CET 2007
On Dec 28, 2007 12:56 PM, Alexandre Vassalotti <alexandre at peadrop.com> wrote:
> On Dec 28, 2007 2:47 PM, Brett Cannon <brett at python.org> wrote:
> > No specific hints, but why do you feel you must implement the whole
> > thing in C? Can't you just import 'io' in your StringIO code and make
> > calls into the Python code?
> >
>
> Honestly, I didn't really consider this as a possibility, since
> TextIOWrapper only accepts bytes buffer, as far as I know. The other
> obstacle is newline conversion has a fair amount of state that needs
> to be managed at the API level.
>
> But, I thinking two better solutions. Could I add a "switch" to
> TextIOWrapper to disable the encoding/decoding process for a unicode
> buffer? Then, I could wrap my StringIO with TextIOWrapper without
> adding any huge overhead.
I have no clue about this.
> Otherwise, could I simply subclass my
> StringIO and write the newlines conversion facilities in Python?
>
Definitely. Nothing says C re-implementations have to be a complete
replacement. Just do the performance-critical stuff in C and
everything else can just be Python code. It's easier to write and
maintain.
-Brett
More information about the Python-3000
mailing list