Commit e9b29f00 authored by SVN-Git Migration's avatar SVN-Git Migration

Imported Upstream version 3.06

parent 718e2ec2
Metadata-Version: 1.0
Name: PyYAML
Version: 3.05
Version: 3.06
Summary: YAML parser and emitter for Python
Home-page: http://pyyaml.org/wiki/PyYAML
Author: Kirill Simonov
Author-email: xi@resolvent.net
License: MIT
Download-URL: http://pyyaml.org/download/pyyaml/PyYAML-3.05.tar.gz
Download-URL: http://pyyaml.org/download/pyyaml/PyYAML-3.06.tar.gz
Description: YAML is a data serialization format designed for human readability and
interaction with scripting languages. PyYAML is a YAML parser and
emitter for Python.
......@@ -19,7 +19,7 @@ Description: YAML is a data serialization format designed for human readability
PyYAML is applicable for a broad range of tasks from complex
configuration files to object serialization and persistance.
Platform: Any
Classifier: Development Status :: 4 - Beta
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
......
......@@ -2,9 +2,16 @@ PyYAML - The next generation YAML parser and emitter for Python.
To install, type 'python setup.py install'.
You may build faster LibYAML based parser and emitter with
'python setup_with_libyaml.py install'.
Then you may use the LibYAML based parser this way:
By default, the setup.py script checks whether LibYAML is installed
and if so, builds and installs LibYAML bindings. To skip the check
and force installation of LibYAML bindings, use the option '--with-libyaml':
'python setup.py --with-libyaml install'. To disable the check and
skip building and installing LibYAML bindings, use '--without-libyaml':
'python setup.py --without-libyaml install'.
When LibYAML bindings are installed, you may use fast LibYAML-based
parser and emitter as follows:
>>> yaml.load(stream, Loader=yaml.CLoader)
>>> yaml.dump(data, Dumper=yaml.CDumper)
......
#
# Examples from the Preview section of the YAML specification
# (http://yaml.org/spec/1.2/#Preview)
#
# Sequence of scalars
---
- Mark McGwire
- Sammy Sosa
- Ken Griffey
# Mapping scalars to scalars
---
hr: 65 # Home runs
avg: 0.278 # Batting average
rbi: 147 # Runs Batted In
# Mapping scalars to sequences
---
american:
- Boston Red Sox
- Detroit Tigers
- New York Yankees
national:
- New York Mets
- Chicago Cubs
- Atlanta Braves
# Sequence of mappings
---
-
name: Mark McGwire
hr: 65
avg: 0.278
-
name: Sammy Sosa
hr: 63
avg: 0.288
# Sequence of sequences
---
- [name , hr, avg ]
- [Mark McGwire, 65, 0.278]
- [Sammy Sosa , 63, 0.288]
# Mapping of mappings
---
Mark McGwire: {hr: 65, avg: 0.278}
Sammy Sosa: {
hr: 63,
avg: 0.288
}
# Two documents in a stream
--- # Ranking of 1998 home runs
- Mark McGwire
- Sammy Sosa
- Ken Griffey
--- # Team ranking
- Chicago Cubs
- St Louis Cardinals
# Documents with the end indicator
---
time: 20:03:20
player: Sammy Sosa
action: strike (miss)
...
---
time: 20:03:47
player: Sammy Sosa
action: grand slam
...
# Comments
---
hr: # 1998 hr ranking
- Mark McGwire
- Sammy Sosa
rbi:
# 1998 rbi ranking
- Sammy Sosa
- Ken Griffey
# Anchors and aliases
---
hr:
- Mark McGwire
# Following node labeled SS
- &SS Sammy Sosa
rbi:
- *SS # Subsequent occurrence
- Ken Griffey
# Mapping between sequences
---
? - Detroit Tigers
- Chicago cubs
:
- 2001-07-23
? [ New York Yankees,
Atlanta Braves ]
: [ 2001-07-02, 2001-08-12,
2001-08-14 ]
# Inline nested mapping
---
# products purchased
- item : Super Hoop
quantity: 1
- item : Basketball
quantity: 4
- item : Big Shoes
quantity: 1
# Literal scalars
--- | # ASCII art
\//||\/||
// || ||__
# Folded scalars
--- >
Mark McGwire's
year was crippled
by a knee injury.
# Preserved indented block in a folded scalar
---
>
Sammy Sosa completed another
fine season with great stats.
63 Home Runs
0.288 Batting Average
What a year!
# Indentation determines scope
---
name: Mark McGwire
accomplishment: >
Mark set a major league
home run record in 1998.
stats: |
65 Home Runs
0.278 Batting Average
# Quoted scalars
---
unicode: "Sosa did fine.\u263A"
control: "\b1998\t1999\t2000\n"
hex esc: "\x0d\x0a is \r\n"
single: '"Howdy!" he cried.'
quoted: ' # not a ''comment''.'
tie-fighter: '|\-*-/|'
# Multi-line flow scalars
---
plain:
This unquoted scalar
spans many lines.
quoted: "So does this
quoted scalar.\n"
# Integers
---
canonical: 12345
decimal: +12_345
sexagesimal: 3:25:45
octal: 014
hexadecimal: 0xC
# Floating point
---
canonical: 1.23015e+3
exponential: 12.3015e+02
sexagesimal: 20:30.15
fixed: 1_230.15
negative infinity: -.inf
not a number: .NaN
# Miscellaneous
---
null: ~
true: boolean
false: boolean
string: '12345'
# Timestamps
---
canonical: 2001-12-15T02:59:43.1Z
iso8601: 2001-12-14t21:59:43.10-05:00
spaced: 2001-12-14 21:59:43.10 -5
date: 2002-12-14
# Various explicit tags
---
not-date: !!str 2002-04-28
picture: !!binary |
R0lGODlhDAAMAIQAAP//9/X
17unp5WZmZgAAAOfn515eXv
Pz7Y6OjuDg4J+fn5OTk6enp
56enmleECcgggoBADs=
application specific tag: !something |
The semantics of the tag
above may be different for
different documents.
# Global tags
%TAG ! tag:clarkevans.com,2002:
--- !shape
# Use the ! handle for presenting
# tag:clarkevans.com,2002:circle
- !circle
center: &ORIGIN {x: 73, y: 129}
radius: 7
- !line
start: *ORIGIN
finish: { x: 89, y: 102 }
- !label
start: *ORIGIN
color: 0xFFEEBB
text: Pretty vector drawing.
# Unordered sets
--- !!set
# sets are represented as a
# mapping where each key is
# associated with the empty string
? Mark McGwire
? Sammy Sosa
? Ken Griff
# Ordered mappings
--- !!omap
# ordered maps are represented as
# a sequence of mappings, with
# each mapping having one key
- Mark McGwire: 65
- Sammy Sosa: 63
- Ken Griffy: 58
# Full length example
--- !<tag:clarkevans.com,2002:invoice>
invoice: 34843
date : 2001-01-23
bill-to: &id001
given : Chris
family : Dumars
address:
lines: |
458 Walkman Dr.
Suite #292
city : Royal Oak
state : MI
postal : 48046
ship-to: *id001
product:
- sku : BL394D
quantity : 4
description : Basketball
price : 450.00
- sku : BL4438H
quantity : 1
description : Super Hoop
price : 2392.00
tax : 251.42
total: 4443.52
comments:
Late afternoon is best.
Backup contact is Nancy
Billsmer @ 338-4338.
# Another full-length example
---
Time: 2001-11-23 15:01:42 -5
User: ed
Warning:
This is an error message
for the log file
---
Time: 2001-11-23 15:02:31 -5
User: ed
Warning:
A slightly different error
message.
---
Date: 2001-11-23 15:03:17 -5
User: ed
Fatal:
Unknown variable "bar"
Stack:
- file: TopClass.py
line: 23
code: |
x = MoreObject("345\n")
- file: MoreClass.py
line: 58
code: |-
foo = bar
This diff is collapsed.
This diff is collapsed.
......@@ -281,9 +281,9 @@ cdef class CParser:
cdef object _parser_error(self):
if self.parser.error == YAML_MEMORY_ERROR:
raise MemoryError
return MemoryError
elif self.parser.error == YAML_READER_ERROR:
raise ReaderError(self.stream_name, self.parser.problem_offset,
return ReaderError(self.stream_name, self.parser.problem_offset,
self.parser.problem_value, '?', self.parser.problem)
elif self.parser.error == YAML_SCANNER_ERROR \
or self.parser.error == YAML_PARSER_ERROR:
......@@ -609,9 +609,9 @@ cdef class CParser:
if event.data.mapping_start.implicit == 1:
implicit = True
flow_style = None
if event.data.mapping_start.style == YAML_FLOW_SEQUENCE_STYLE:
if event.data.mapping_start.style == YAML_FLOW_MAPPING_STYLE:
flow_style = True
elif event.data.mapping_start.style == YAML_BLOCK_SEQUENCE_STYLE:
elif event.data.mapping_start.style == YAML_BLOCK_MAPPING_STYLE:
flow_style = False
return MappingStartEvent(anchor, tag, implicit,
start_mark, end_mark, flow_style)
......@@ -663,6 +663,24 @@ cdef class CParser:
if self.parsed_event.type != YAML_STREAM_END_EVENT:
return self._compose_document()
def get_single_node(self):
self._parse_next_event()
yaml_event_delete(&self.parsed_event)
self._parse_next_event()
document = None
if self.parsed_event.type != YAML_STREAM_END_EVENT:
document = self._compose_document()
self._parse_next_event()
if self.parsed_event.type != YAML_STREAM_END_EVENT:
mark = Mark(self.stream_name,
self.parsed_event.start_mark.index,
self.parsed_event.start_mark.line,
self.parsed_event.start_mark.column,
None, None)
raise ComposerError("expected a single document in the stream",
document.start_mark, "but found another document", mark)
return document
cdef object _compose_document(self):
yaml_event_delete(&self.parsed_event)
node = self._compose_node(None, None)
......
......@@ -8,10 +8,13 @@ from nodes import *
from loader import *
from dumper import *
__version__ = '3.06'
try:
from cyaml import *
__with_libyaml__ = True
except ImportError:
pass
__with_libyaml__ = False
def scan(stream, Loader=Loader):
"""
......@@ -35,8 +38,7 @@ def compose(stream, Loader=Loader):
and produce the corresponding representation tree.
"""
loader = Loader(stream)
if loader.check_node():
return loader.get_node()
return loader.get_single_node()
def compose_all(stream, Loader=Loader):
"""
......@@ -47,6 +49,14 @@ def compose_all(stream, Loader=Loader):
while loader.check_node():
yield loader.get_node()
def load(stream, Loader=Loader):
"""
Parse the first YAML document in a stream
and produce the corresponding Python object.
"""
loader = Loader(stream)
return loader.get_single_data()
def load_all(stream, Loader=Loader):
"""
Parse all YAML documents in a stream
......@@ -56,14 +66,13 @@ def load_all(stream, Loader=Loader):
while loader.check_data():
yield loader.get_data()
def load(stream, Loader=Loader):
def safe_load(stream):
"""
Parse the first YAML document in a stream
and produce the corresponding Python object.
Resolve only basic YAML tags.
"""
loader = Loader(stream)
if loader.check_data():
return loader.get_data()
return load(stream, SafeLoader)
def safe_load_all(stream):
"""
......@@ -73,14 +82,6 @@ def safe_load_all(stream):
"""
return load_all(stream, SafeLoader)
def safe_load(stream):
"""
Parse the first YAML document in a stream
and produce the corresponding Python object.
Resolve only basic YAML tags.
"""
return load(stream, SafeLoader)
def emit(events, stream=None, Dumper=Dumper,
canonical=None, indent=None, width=None,
allow_unicode=None, line_break=None):
......
......@@ -26,6 +26,27 @@ class Composer(object):
if not self.check_event(StreamEndEvent):
return self.compose_document()
def get_single_node(self):
# Drop the STREAM-START event.
self.get_event()
# Compose a document if the stream is not empty.
document = None
if not self.check_event(StreamEndEvent):
document = self.compose_document()
# Ensure that the stream contains no more documents.
if not self.check_event(StreamEndEvent):
event = self.get_event()
raise ComposerError("expected a single document in the stream",
document.start_mark, "but found another document",
event.start_mark)
# Drop the STREAM-END event.
self.get_event()
return document
def compose_document(self):
# Drop the DOCUMENT-START event.
self.get_event()
......
......@@ -37,6 +37,13 @@ class BaseConstructor(object):
if self.check_node():
return self.construct_document(self.get_node())
def get_single_data(self):
# Ensure that the stream contains a single document and construct it.
node = self.get_single_node()
if node is not None:
return self.construct_document(node)
return None
def construct_document(self, node):
data = self.construct_object(node)
while self.state_generators:
......@@ -314,7 +321,10 @@ class SafeConstructor(BaseConstructor):
second = int(values['second'])
fraction = 0
if values['fraction']:
fraction = int(values['fraction'][:6].ljust(6, '0'))
fraction = values['fraction'][:6]
while len(fraction) < 6:
fraction += '0'
fraction = int(fraction)
delta = None
if values['tz_sign']:
tz_hour = int(values['tz_hour'])
......
......@@ -173,7 +173,8 @@ Resolver.add_implicit_resolver(
Resolver.add_implicit_resolver(
u'tag:yaml.org,2002:float',
re.compile(ur'''^(?:[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*(?:[eE][-+][0-9]+)?
re.compile(ur'''^(?:[-+]?(?:[0-9][0-9_]*)\.[0-9_]*(?:[eE][-+][0-9]+)?
|\.[0-9_]+(?:[eE][-+][0-9]+)?
|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*
|[-+]?\.(?:inf|Inf|INF)
|\.(?:nan|NaN|NAN))$''', re.X),
......
......@@ -17,12 +17,18 @@
# The following options are used to build PyYAML Windows installer
# for Python 2.3 on my PC:
#include_dirs=../../libyaml/trunk/include
#library_dirs=../../libyaml/trunk/win32/vc6/output/release/lib
#include_dirs=../../libyaml/branches/stable/include
#library_dirs=../../libyaml/branches/stable/win32/vc6/output/release/lib
#define=YAML_DECLARE_STATIC
# The following options are used to build PyYAML Windows installer
# for Python 2.4 and Python 2.5 on my PC:
#include_dirs=../../libyaml/trunk/include
#library_dirs=../../libyaml/trunk/win32/vs2003/output/release/lib
#include_dirs=../../libyaml/branches/stable/include
#library_dirs=../../libyaml/branches/stable/win32/vs2003/output/release/lib
#define=YAML_DECLARE_STATIC
# The following options are used to build PyYAML Windows installer
# for Python 2.6 on my PC:
#include_dirs=../../libyaml/branches/stable/include
#library_dirs=../../libyaml/branches/stable/win32/vs2008/output/release/lib
#define=YAML_DECLARE_STATIC
NAME = 'PyYAML'
VERSION = '3.05'
VERSION = '3.06'
DESCRIPTION = "YAML parser and emitter for Python"
LONG_DESCRIPTION = """\
YAML is a data serialization format designed for human readability and
......@@ -21,7 +21,7 @@ PLATFORMS = "Any"
URL = "http://pyyaml.org/wiki/PyYAML"
DOWNLOAD_URL = "http://pyyaml.org/download/pyyaml/%s-%s.tar.gz" % (NAME, VERSION)
CLASSIFIERS = [
"Development Status :: 4 - Beta",
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
......@@ -30,7 +30,205 @@ CLASSIFIERS = [
"Topic :: Text Processing :: Markup",
]
from distutils.core import setup
LIBYAML_CHECK = """
#include <yaml.h>
int main(void) {
yaml_parser_t parser;
yaml_emitter_t emitter;
yaml_parser_initialize(&parser);
yaml_parser_delete(&parser);
yaml_emitter_initialize(&emitter);
yaml_emitter_delete(&emitter);
return 0;
}
"""
from distutils import log
from distutils.core import setup, Command
from distutils.core import Distribution as _Distribution
from distutils.core import Extension as _Extension
from distutils.dir_util import mkpath
from distutils.command.build_ext import build_ext as _build_ext
from distutils.errors import CompileError, LinkError, DistutilsPlatformError
try:
from Pyrex.Distutils import Extension as _Extension
from Pyrex.Distutils import build_ext as _build_ext
with_pyrex = True
except ImportError:
with_pyrex = False
import sys, os.path
class Distribution(_Distribution):
def __init__(self, attrs=None):
_Distribution.__init__(self, attrs)
if not self.ext_modules:
return
for idx in range(len(self.ext_modules)-1, -1, -1):
ext = self.ext_modules[idx]
if not isinstance(ext, Extension):
continue
setattr(self, ext.attr_name, None)
self.global_options = [
(ext.option_name, None,
"include %s (default if %s is available)"
% (ext.feature_description, ext.feature_name)),
(ext.neg_option_name, None,
"exclude %s" % ext.feature_description),
] + self.global_options
self.negative_opt = self.negative_opt.copy()
self.negative_opt[ext.neg_option_name] = ext.option_name
class Extension(_Extension):
def __init__(self, name, sources, feature_name, feature_description,
feature_check, **kwds):
if not with_pyrex:
for filename in sources[:]:
base, ext = os.path.splitext(filename)
if ext == '.pyx':
sources.remove(filename)
sources.append('%s.c' % base)
_Extension.__init__(self, name, sources, **kwds)
self.feature_name = feature_name
self.feature_description = feature_description
self.feature_check = feature_check
self.attr_name = 'with_' + feature_name.replace('-', '_')
self.option_name = 'with-' + feature_name
self.neg_option_name = 'without-' + feature_name
class build_ext(_build_ext):
def run(self):
optional = True
disabled = True
for ext in self.extensions:
if isinstance(ext, Extension):
with_ext = getattr(self.distribution, ext.attr_name)
if with_ext is None:
disabled = False
elif with_ext:
optional = False
disabled = False
else:
optional = False
disabled = False
break
if disabled:
return
try:
_build_ext.run(self)
except DistutilsPlatformError, exc:
if optional:
log.warn(str(exc))
log.warn("skipping build_ext")
else:
raise
def get_source_files(self):
self.check_extensions_list(self.extensions)
filenames = []
for ext in self.extensions:
if with_pyrex:
self.pyrex_sources(ext.sources, ext)
for filename in ext.sources:
filenames.append(filename)
base = os.path.splitext(filename)[0]
for ext in ['c', 'h', 'pyx', 'pxd']:
filename = '%s.%s' % (base, ext)
if filename not in filenames and os.path.isfile(filename):
filenames.append(filename)
return filenames
def build_extensions(self):
self.check_extensions_list(self.extensions)
for ext in self.extensions:
if isinstance(ext, Extension):
with_ext = getattr(self.distribution, ext.attr_name)
if with_ext is None:
with_ext = self.check_extension_availability(ext)
if not with_ext:
continue
if with_pyrex:
ext.sources = self.pyrex_sources(ext.sources, ext)
self.build_extension(ext)
def check_extension_availability(self, ext):
cache = os.path.join(self.build_temp, 'check_%s.out' % ext.feature_name)
if not self.force and os.path.isfile(cache):
data = open(cache).read().strip()
if data == '1':
return True
elif data == '0':
return False
mkpath(self.build_temp)
src = os.path.join(self.build_temp, 'check_%s.c' % ext.feature_name)
open(src, 'w').write(ext.feature_check)
log.info("checking if %s compiles" % ext.feature_name)
try:
[obj] = self.compiler.compile([src],
macros=ext.define_macros+[(undef,) for undef in ext.undef_macros],
include_dirs=ext.include_dirs,
extra_postargs=(ext.extra_compile_args or []),
depends=ext.depends)
except CompileError:
log.warn("%s appears not to be installed" % ext.feature_name)
log.warn("(if %s is installed, you may need to specify"
% ext.feature_name)
log.warn(" the option --include-dirs or uncomment and modify")
log.warn(" the parameter include_dirs in setup.cfg)")
open(cache, 'w').write('0\n')
return False
prog = 'check_%s' % ext.feature_name
log.info("checking if %s links" % ext.feature_name)
try:
self.compiler.link_executable([obj], prog,
output_dir=self.build_temp,
libraries=ext.libraries,
library_dirs=ext.library_dirs,
runtime_library_dirs=ext.runtime_library_dirs,
extra_postargs=(ext.extra_link_args or []))
except LinkError:
log.warn("unable to link against %s" % ext.feature_name)
log.warn("(if %s is installed correctly, you may need to specify"
% ext.feature_name)
log.warn(" the option --lib