Changeset 3864:4eedd449a256 in livinglogic.python.xist

Show
Ignore:
Timestamp:
09/30/09 15:34:51 (10 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Fix reset() for incremental codecs.

If encoding has been changed during parsing it now gets reset to it's proper
inital value.

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/ll/xml_codec.py

    r3863 r3864  
    8383    def __init__(self, errors="strict", encoding=None): 
    8484        self.decoder = None 
    85         self.encoding = encoding 
     85        self._initial_encoding = self.encoding = encoding 
    8686        codecs.IncrementalDecoder.__init__(self, errors) 
    8787        self._errors = errors # Store ``errors`` somewhere else, because we have to hide it in a property 
     
    127127    def reset(self): 
    128128        codecs.IncrementalDecoder.reset(self) 
     129        self.encoding = self._initial_encoding 
    129130        self.decoder = None 
    130131        self.buffer = "" 
     
    145146    def __init__(self, errors="strict", encoding=None): 
    146147        self.encoder = None 
    147         self.encoding = encoding 
     148        self._initial_encoding = self.encoding = encoding 
    148149        codecs.IncrementalEncoder.__init__(self, errors) 
    149150        self._errors = errors # Store ``errors`` somewhere else, because we have to hide it in a property 
     
    185186    def reset(self): 
    186187        codecs.IncrementalEncoder.reset(self) 
     188        self.encoding = self._initial_encoding 
    187189        self.encoder = None 
    188190        self.buffer = u"" 
  • test/test_xml_codec.py

    r3720 r3864  
    163163        assert "".join(id.iterdecode(input.encode(encoding))) == input.replace("'x'", repr(encoding)) 
    164164 
     165    id = codecs.getincrementaldecoder("xml")(encoding="ascii") 
     166    assert id.decode("<?xml version='1.0' encoding='utf-16'?>") == "<?xml version='1.0' encoding='ascii'?>" 
     167 
    165168    # Autodetectable encodings 
    166169    yield checkauto, "utf-8-sig"