[Python-Dev] XML codec?

Walter Dörwald walter at livinglogic.de
Mon Nov 12 10:53:54 CET 2007


Martin v. Löwis wrote:
>>  > In case it isn't clear - this is exactly my view also.
>>
>> But is there an API to do it?  As MAL points out that API would have
>> to return not an encoding, but a pair of an encoding and the rewound
>> stream.  
> 
> The API wouldn't operate on streams. Instead, you pass a string, and
> it either returns the detected encoding, or an information telling that
> it needs more data. No streams.

But in many cases you read the data out of a stream and pass it to an
incremental XML parser. So if you're transcoding the input (either
because the XML parser can't handle the encoding in question or because
there's an external encoding specified, but it's not possible to pass
that to the parser), a codec makes the most sense.

>> For non-seekable, non-peekable streams (if any), what you'd
>> need would be a stream that consisted of a concatenation of the
>> buffered data used for detection and the continuation of the stream.
> 
> The application would read data out of the stream, and pass it to
> the detection. It then can process it in whatever manner it meant to
> process it in the first place.

Servus,
   Walter


More information about the Python-Dev mailing list