Modify ↓
Ticket #166 (closed enhancement: wontfix)
PyYAML should use libyaml if libyaml available
| Reported by: | sgwong | Owned by: | xi |
|---|---|---|---|
| Priority: | normal | Component: | pyyaml |
| Severity: | normal | Keywords: | |
| Cc: |
Description (last modified by xi) (diff)
Currently PyYAML only use python implementation although the libyaml available. The following simple changes on __init__.py should do: (I'm not sure whats the use of __with_libyaml__)
__version__ = '3.09' try: from cyaml import * __with_libyaml__ = True Loader = CLoader Dumper = CDumper except ImportError: __with_libyaml__ = False
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

You could use __with_libyaml__ to check whether libyaml bindings are available or not. For instance,
import yaml if yaml.__with_libyaml__: data = yaml.load(input, Loader=yaml.CLoader) else: data = yaml.load(input)The pure-Python and libyaml-based emitters may emit valid, but slightly different representations of the same document, therefore, to make the output deterministic regardless of whether libyaml is available or not, PyYAML always uses pure-Python parser and emitter by default.