Changeset 135


Ignore:
Timestamp:
04/12/06 18:26:41 (9 years ago)
Author:
xi
Message:

Fix allow_unicode (ticket:3).

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

Legend:

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

    r133 r135  
    6868def dump_all(natives, writer=None, Emitter=Emitter, 
    6969        Serializer=Serializer, Representer=Representer, 
    70         encoding=None, line_break=None, canonical=None, 
     70        encoding='utf-8', line_break=None, canonical=None, 
    7171        indent=None, width=None, allow_unicode=None): 
    7272    if writer is None: 
     
    9292def safe_dump_all(natives, writer=None, Emitter=Emitter, 
    9393        Serializer=Serializer, Representer=SafeRepresenter, 
    94         encoding=None, line_break=None, canonical=None, 
     94        encoding='utf-8', line_break=None, canonical=None, 
    9595        indent=None, width=None, allow_unicode=None): 
    9696    return dump_all(natives, writer, Emitter, Serializer, Representer, 
  • pyyaml/trunk/lib/yaml/representer.py

    r133 r135  
    120120 
    121121    def represent_str(self, native): 
     122        encoding = None 
    122123        try: 
    123             native.encode('ascii') 
    124             ascii = True 
    125         except (UnicodeDecodeError, UnicodeEncodeError): 
    126             ascii = False 
    127         if ascii: 
     124            unicode(native, 'ascii') 
     125            encoding = 'ascii' 
     126        except UnicodeDecodeError: 
     127            try: 
     128                unicode(native, 'utf-8') 
     129                encoding = 'utf-8' 
     130            except UnicodeDecodeError: 
     131                pass 
     132        if encoding: 
    128133            return self.represent_scalar(u'tag:yaml.org,2002:str', 
    129                     unicode(native, 'ascii')) 
     134                    unicode(native, encoding)) 
    130135        else: 
    131136            return self.represent_scalar(u'tag:yaml.org,2002:binary', 
  • pyyaml/trunk/lib/yaml/serializer.py

    r133 r135  
    2020        self.last_anchor_id = 0 
    2121        self.closed = None 
    22         self.open(encoding, line_break, canonical, indent, width) 
     22        self.open(encoding, line_break, canonical, indent, width, allow_unicode) 
    2323 
    2424    def open(self, encoding=None, line_break=None, canonical=None, 
Note: See TracChangeset for help on using the changeset viewer.