Changeset 328 for pyyaml/trunk/lib3/yaml/__init__.py
- Timestamp:
- 12/29/08 12:24:05 (4 years ago)
- Location:
- pyyaml/trunk/lib3
- Files:
-
- 1 edited
- 1 copied
-
. (copied) (copied from pyyaml/trunk/lib)
-
yaml/__init__.py (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pyyaml/trunk/lib3/yaml/__init__.py
r314 r328 1 1 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 5 from .error import * 6 7 from .tokens import * 8 from .events import * 9 from .nodes import * 10 11 from .loader import * 12 from .dumper import * 13 14 import io 18 15 19 16 def scan(stream, Loader=Loader): … … 92 89 getvalue = None 93 90 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() 99 92 getvalue = stream.getvalue 100 93 dumper = Dumper(stream, canonical=canonical, indent=indent, width=width, … … 116 109 getvalue = None 117 110 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() 123 112 getvalue = stream.getvalue 124 113 dumper = Dumper(stream, canonical=canonical, indent=indent, width=width, … … 152 141 getvalue = None 153 142 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() 159 144 getvalue = stream.getvalue 160 145 dumper = Dumper(stream, default_style=default_style, … … 260 245 cls.yaml_dumper.add_representer(cls, cls.to_yaml) 261 246 262 class YAMLObject( object):247 class YAMLObject(metaclass=YAMLObjectMetaclass): 263 248 """ 264 249 An object that can dump itself to a YAML stream … … 266 251 """ 267 252 268 __metaclass__ = YAMLObjectMetaclass269 253 __slots__ = () # no direct instantiation, so allow immutable subclasses 270 254 … … 275 259 yaml_flow_style = None 276 260 261 @classmethod 277 262 def from_yaml(cls, loader, node): 278 263 """ … … 280 265 """ 281 266 return loader.construct_yaml_object(node, cls) 282 from_yaml = classmethod(from_yaml) 283 267 268 @classmethod 284 269 def to_yaml(cls, dumper, data): 285 270 """ … … 288 273 return dumper.represent_yaml_object(cls.yaml_tag, data, cls, 289 274 flow_style=cls.yaml_flow_style) 290 to_yaml = classmethod(to_yaml) 291 275
Note: See TracChangeset
for help on using the changeset viewer.
