Ignore:
Timestamp:
05/30/11 00:19:04 (3 years ago)
Author:
xi
Message:

Dropped support for Python 2.3 and 2.4.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pyyaml/trunk/lib/yaml/reader.py

    r323 r380  
    2121 
    2222import codecs, re 
    23  
    24 # Unfortunately, codec functions in Python 2.3 does not support the `finish` 
    25 # arguments, so we have to write our own wrappers. 
    26  
    27 try: 
    28     codecs.utf_8_decode('', 'strict', False) 
    29     from codecs import utf_8_decode, utf_16_le_decode, utf_16_be_decode 
    30  
    31 except TypeError: 
    32  
    33     def utf_16_le_decode(data, errors, finish=False): 
    34         if not finish and len(data) % 2 == 1: 
    35             data = data[:-1] 
    36         return codecs.utf_16_le_decode(data, errors) 
    37  
    38     def utf_16_be_decode(data, errors, finish=False): 
    39         if not finish and len(data) % 2 == 1: 
    40             data = data[:-1] 
    41         return codecs.utf_16_be_decode(data, errors) 
    42  
    43     def utf_8_decode(data, errors, finish=False): 
    44         if not finish: 
    45             # We are trying to remove a possible incomplete multibyte character 
    46             # from the suffix of the data. 
    47             # The first byte of a multi-byte sequence is in the range 0xc0 to 0xfd. 
    48             # All further bytes are in the range 0x80 to 0xbf. 
    49             # UTF-8 encoded UCS characters may be up to six bytes long. 
    50             count = 0 
    51             while count < 5 and count < len(data)   \ 
    52                     and '\x80' <= data[-count-1] <= '\xBF': 
    53                 count -= 1 
    54             if count < 5 and count < len(data)  \ 
    55                     and '\xC0' <= data[-count-1] <= '\xFD': 
    56                 data = data[:-count-1] 
    57         return codecs.utf_8_decode(data, errors) 
    5823 
    5924class ReaderError(YAMLError): 
     
    160125        if not isinstance(self.raw_buffer, unicode): 
    161126            if self.raw_buffer.startswith(codecs.BOM_UTF16_LE): 
    162                 self.raw_decode = utf_16_le_decode 
     127                self.raw_decode = codecs.utf_16_le_decode 
    163128                self.encoding = 'utf-16-le' 
    164129            elif self.raw_buffer.startswith(codecs.BOM_UTF16_BE): 
    165                 self.raw_decode = utf_16_be_decode 
     130                self.raw_decode = codecs.utf_16_be_decode 
    166131                self.encoding = 'utf-16-be' 
    167132            else: 
    168                 self.raw_decode = utf_8_decode 
     133                self.raw_decode = codecs.utf_8_decode 
    169134                self.encoding = 'utf-8' 
    170135        self.update(1) 
Note: See TracChangeset for help on using the changeset viewer.