Changeset 333 for pyyaml/trunk/lib

Show
Ignore:
Timestamp:
12/29/08 23:02:04 (3 years ago)
Author:
xi
Message:

Handle the encoding of input and output streams in a uniform way.

Location:
pyyaml/trunk/lib/yaml
Files:
3 modified

Legend:

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

    r314 r333  
    9292    getvalue = None 
    9393    if stream is None: 
    94         try: 
    95             from cStringIO import StringIO 
    96         except ImportError: 
    97             from StringIO import StringIO 
     94        from StringIO import StringIO 
    9895        stream = StringIO() 
    9996        getvalue = stream.getvalue 
     
    116113    getvalue = None 
    117114    if stream is None: 
    118         try: 
     115        if encoding is None: 
     116            from StringIO import StringIO 
     117        else: 
    119118            from cStringIO import StringIO 
    120         except ImportError: 
    121             from StringIO import StringIO 
    122119        stream = StringIO() 
    123120        getvalue = stream.getvalue 
     
    152149    getvalue = None 
    153150    if stream is None: 
    154         try: 
     151        if encoding is None: 
     152            from StringIO import StringIO 
     153        else: 
    155154            from cStringIO import StringIO 
    156         except ImportError: 
    157             from StringIO import StringIO 
    158155        stream = StringIO() 
    159156        getvalue = stream.getvalue 
  • pyyaml/trunk/lib/yaml/cyaml.py

    r223 r333  
    4242            version=None, tags=None): 
    4343        CEmitter.__init__(self, stream, canonical=canonical, 
    44                 indent=indent, width=width, 
     44                indent=indent, width=width, encoding=encoding, 
    4545                allow_unicode=allow_unicode, line_break=line_break, 
    4646                explicit_start=explicit_start, explicit_end=explicit_end, 
     
    5959            version=None, tags=None): 
    6060        CEmitter.__init__(self, stream, canonical=canonical, 
    61                 indent=indent, width=width, 
     61                indent=indent, width=width, encoding=encoding, 
    6262                allow_unicode=allow_unicode, line_break=line_break, 
    6363                explicit_start=explicit_start, explicit_end=explicit_end, 
     
    7676            version=None, tags=None): 
    7777        CEmitter.__init__(self, stream, canonical=canonical, 
    78                 indent=indent, width=width, 
     78                indent=indent, width=width, encoding=encoding, 
    7979                allow_unicode=allow_unicode, line_break=line_break, 
    8080                explicit_start=explicit_start, explicit_end=explicit_end, 
  • pyyaml/trunk/lib/yaml/emitter.py

    r328 r333  
    155155    def expect_stream_start(self): 
    156156        if isinstance(self.event, StreamStartEvent): 
    157             if self.event.encoding: 
     157            if self.event.encoding and not getattr(self.stream, 'encoding', None): 
    158158                self.encoding = self.event.encoding 
    159159            self.write_stream_start()