Ignore:
Timestamp:
12/29/08 12:24:05 (5 years ago)
Author:
xi
Message:

Added basic support for Python 3 (Thanks idadesub(at)users(dot)sourceforge(dot)net).

Location:
pyyaml/trunk/lib3
Files:
1 edited
1 copied

Legend:

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

    r314 r328  
    11 
    2 from error import * 
    3  
    4 from tokens import * 
    5 from events import * 
    6 from nodes import * 
    7  
    8 from loader import * 
    9 from dumper import * 
    10  
    11 __version__ = '3.07' 
    12  
    13 try: 
    14     from cyaml import * 
    15     __with_libyaml__ = True 
    16 except ImportError: 
    17     __with_libyaml__ = False 
     2__version__ = '3.08' 
     3__with_libyaml__ = False 
     4 
     5from .error import * 
     6 
     7from .tokens import * 
     8from .events import * 
     9from .nodes import * 
     10 
     11from .loader import * 
     12from .dumper import * 
     13 
     14import io 
    1815 
    1916def scan(stream, Loader=Loader): 
     
    9289    getvalue = None 
    9390    if stream is None: 
    94         try: 
    95             from cStringIO import StringIO 
    96         except ImportError: 
    97             from StringIO import StringIO 
    98         stream = StringIO() 
     91        stream = io.StringIO() 
    9992        getvalue = stream.getvalue 
    10093    dumper = Dumper(stream, canonical=canonical, indent=indent, width=width, 
     
    116109    getvalue = None 
    117110    if stream is None: 
    118         try: 
    119             from cStringIO import StringIO 
    120         except ImportError: 
    121             from StringIO import StringIO 
    122         stream = StringIO() 
     111        stream = io.StringIO() 
    123112        getvalue = stream.getvalue 
    124113    dumper = Dumper(stream, canonical=canonical, indent=indent, width=width, 
     
    152141    getvalue = None 
    153142    if stream is None: 
    154         try: 
    155             from cStringIO import StringIO 
    156         except ImportError: 
    157             from StringIO import StringIO 
    158         stream = StringIO() 
     143        stream = io.StringIO() 
    159144        getvalue = stream.getvalue 
    160145    dumper = Dumper(stream, default_style=default_style, 
     
    260245            cls.yaml_dumper.add_representer(cls, cls.to_yaml) 
    261246 
    262 class YAMLObject(object): 
     247class YAMLObject(metaclass=YAMLObjectMetaclass): 
    263248    """ 
    264249    An object that can dump itself to a YAML stream 
     
    266251    """ 
    267252 
    268     __metaclass__ = YAMLObjectMetaclass 
    269253    __slots__ = ()  # no direct instantiation, so allow immutable subclasses 
    270254 
     
    275259    yaml_flow_style = None 
    276260 
     261    @classmethod 
    277262    def from_yaml(cls, loader, node): 
    278263        """ 
     
    280265        """ 
    281266        return loader.construct_yaml_object(node, cls) 
    282     from_yaml = classmethod(from_yaml) 
    283  
     267 
     268    @classmethod 
    284269    def to_yaml(cls, dumper, data): 
    285270        """ 
     
    288273        return dumper.represent_yaml_object(cls.yaml_tag, data, cls, 
    289274                flow_style=cls.yaml_flow_style) 
    290     to_yaml = classmethod(to_yaml) 
    291  
     275 
Note: See TracChangeset for help on using the changeset viewer.