Commit 3e293a44 authored by SVN-Git Migration's avatar SVN-Git Migration

Imported Upstream version 3.09

parent 2bdb6d06
......@@ -2,6 +2,22 @@
For a complete Subversion changelog, see 'http://pyyaml.org/log/pyyaml'.
3.09 (2009-08-31)
-----------------
* Fixed an obscure scanner error not reported when there is
no line break at the end of the stream (Thank to Ingy).
* Fixed use of uninitialized memory when emitting anchors with
LibYAML bindings (Thank to cegner(at)yahoo-inc(dot)com).
* Fixed emitting incorrect BOM characters for UTF-16 (Thank to
Valentin Nechayev)
* Fixed the emitter for folded scalars not respecting the preferred
line width (Thank to Ingy).
* Fixed a subtle ordering issue with emitting '%TAG' directives
(Thank to Andrey Somov).
* Fixed performance regression with LibYAML bindings.
3.08 (2008-12-31)
-----------------
......
Metadata-Version: 1.0
Name: PyYAML
Version: 3.08
Version: 3.09
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.08.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.
Download-URL: http://pyyaml.org/download/pyyaml/PyYAML-3.09.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.
PyYAML features a complete YAML 1.1 parser, Unicode support, pickle
support, capable extension API, and sensible error messages. PyYAML
supports standard YAML tags and provides Python-specific tags that allow
to represent an arbitrary Python object.
supports standard YAML tags and provides Python-specific tags that
allow to represent an arbitrary Python object.
PyYAML is applicable for a broad range of tasks from complex
configuration files to object serialization and persistance.
......@@ -31,5 +31,6 @@ Classifier: Programming Language :: Python :: 2.5
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.0
Classifier: Programming Language :: Python :: 3.1
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Text Processing :: Markup
This diff is collapsed.
......@@ -14,7 +14,7 @@ def get_version():
yaml_get_version(&major, &minor, &patch)
return (major, minor, patch)
Mark = yaml.error.Mark
#Mark = yaml.error.Mark
YAMLError = yaml.error.YAMLError
ReaderError = yaml.reader.ReaderError
ScannerError = yaml.scanner.ScannerError
......@@ -61,31 +61,31 @@ ScalarNode = yaml.nodes.ScalarNode
SequenceNode = yaml.nodes.SequenceNode
MappingNode = yaml.nodes.MappingNode
#cdef class Mark:
# cdef readonly object name
# cdef readonly int index
# cdef readonly int line
# cdef readonly int column
# cdef readonly buffer
# cdef readonly pointer
#
# def __init__(self, object name, int index, int line, int column,
# object buffer, object pointer):
# self.name = name
# self.index = index
# self.line = line
# self.column = column
# self.buffer = buffer
# self.pointer = pointer
#
# def get_snippet(self):
# return None
#
# def __str__(self):
# where = " in \"%s\", line %d, column %d" \
# % (self.name, self.line+1, self.column+1)
# return where
#
cdef class Mark:
cdef readonly object name
cdef readonly int index
cdef readonly int line
cdef readonly int column
cdef readonly buffer
cdef readonly pointer
def __init__(self, object name, int index, int line, int column,
object buffer, object pointer):
self.name = name
self.index = index
self.line = line
self.column = column
self.buffer = buffer
self.pointer = pointer
def get_snippet(self):
return None
def __str__(self):
where = " in \"%s\", line %d, column %d" \
% (self.name, self.line+1, self.column+1)
return where
#class YAMLError(Exception):
# pass
#
......@@ -954,11 +954,12 @@ cdef class CEmitter:
raise MemoryError
self.stream = stream
self.dump_unicode = 0
try:
if stream.encoding:
if PY_MAJOR_VERSION < 3:
if getattr3(stream, 'encoding', None):
self.dump_unicode = 1
else:
if hasattr(stream, u'encoding'):
self.dump_unicode = 1
except AttributeError:
pass
self.use_encoding = encoding
yaml_emitter_set_output(&self.emitter, output_handler, <void *>self)
if canonical:
......@@ -1380,7 +1381,14 @@ cdef class CEmitter:
anchor_object = self.anchors[node]
anchor = NULL
if anchor_object is not None:
anchor = PyString_AS_STRING(PyUnicode_AsUTF8String(anchor_object))
if PyUnicode_CheckExact(anchor_object):
anchor_object = PyUnicode_AsUTF8String(anchor_object)
if not PyString_CheckExact(anchor_object):
if PY_MAJOR_VERSION < 3:
raise TypeError("anchor must be a string")
else:
raise TypeError(u"anchor must be a string")
anchor = PyString_AS_STRING(anchor_object)
if node in self.serialized_nodes:
if yaml_alias_event_initialize(&event, anchor) == 0:
raise MemoryError
......
......@@ -8,7 +8,7 @@ from nodes import *
from loader import *
from dumper import *
__version__ = '3.08'
__version__ = '3.09'
try:
from cyaml import *
......@@ -43,7 +43,7 @@ def compose(stream, Loader=Loader):
def compose_all(stream, Loader=Loader):
"""
Parse all YAML documents in a stream
and produce corresponsing representation trees.
and produce corresponding representation trees.
"""
loader = Loader(stream)
while loader.check_node():
......
......@@ -581,7 +581,9 @@ class Emitter(object):
return tag
handle = None
suffix = tag
for prefix in self.tag_prefixes:
prefixes = self.tag_prefixes.keys()
prefixes.sort()
for prefix in prefixes:
if tag.startswith(prefix) \
and (prefix == u'!' or len(prefix) < len(tag)):
handle = self.tag_prefixes[prefix]
......@@ -787,7 +789,7 @@ class Emitter(object):
def write_stream_start(self):
# Write BOM if needed.
if self.encoding and self.encoding.startswith('utf-16'):
self.stream.write(u'\xFF\xFE'.encode(self.encoding))
self.stream.write(u'\uFEFF'.encode(self.encoding))
def write_stream_end(self):
self.flush_stream()
......@@ -1025,6 +1027,7 @@ class Emitter(object):
else:
if ch is None or ch in u' \n\x85\u2028\u2029':
data = text[start:end]
self.column += len(data)
if self.encoding:
data = data.encode(self.encoding)
self.stream.write(data)
......
......@@ -374,7 +374,8 @@ class Scanner(object):
# Set the current intendation to -1.
self.unwind_indent(-1)
# Reset everything (not really needed).
# Reset simple keys.
self.remove_possible_simple_key()
self.allow_simple_key = False
self.possible_simple_keys = {}
......
......@@ -8,7 +8,7 @@ from .nodes import *
from .loader import *
from .dumper import *
__version__ = '3.08'
__version__ = '3.09'
try:
from .cyaml import *
__with_libyaml__ = True
......@@ -44,7 +44,7 @@ def compose(stream, Loader=Loader):
def compose_all(stream, Loader=Loader):
"""
Parse all YAML documents in a stream
and produce corresponsing representation trees.
and produce corresponding representation trees.
"""
loader = Loader(stream)
while loader.check_node():
......
......@@ -285,7 +285,10 @@ class SafeConstructor(BaseConstructor):
"failed to convert base64 data into ascii: %s" % exc,
node.start_mark)
try:
return base64.decodestring(value)
if hasattr(base64, 'decodebytes'):
return base64.decodebytes(value)
else:
return base64.decodestring(value)
except binascii.Error as exc:
raise ConstructorError(None, None,
"failed to decode base64 data: %s" % exc, node.start_mark)
......@@ -477,7 +480,10 @@ class Constructor(SafeConstructor):
"failed to convert base64 data into ascii: %s" % exc,
node.start_mark)
try:
return base64.decodestring(value)
if hasattr(base64, 'decodebytes'):
return base64.decodebytes(value)
else:
return base64.decodestring(value)
except binascii.Error as exc:
raise ConstructorError(None, None,
"failed to decode base64 data: %s" % exc, node.start_mark)
......
......@@ -579,7 +579,8 @@ class Emitter:
return tag
handle = None
suffix = tag
for prefix in self.tag_prefixes:
prefixes = sorted(self.tag_prefixes.keys())
for prefix in prefixes:
if tag.startswith(prefix) \
and (prefix == '!' or len(prefix) < len(tag)):
handle = self.tag_prefixes[prefix]
......@@ -785,7 +786,7 @@ class Emitter:
def write_stream_start(self):
# Write BOM if needed.
if self.encoding and self.encoding.startswith('utf-16'):
self.stream.write('\xFF\xFE'.encode(self.encoding))
self.stream.write('\uFEFF'.encode(self.encoding))
def write_stream_end(self):
self.flush_stream()
......@@ -1023,6 +1024,7 @@ class Emitter:
else:
if ch is None or ch in ' \n\x85\u2028\u2029':
data = text[start:end]
self.column += len(data)
if self.encoding:
data = data.encode(self.encoding)
self.stream.write(data)
......
......@@ -156,7 +156,7 @@ class Reader(object):
data, converted = self.raw_decode(self.raw_buffer,
'strict', self.eof)
except UnicodeDecodeError as exc:
character = exc.object[exc.start]
character = self.raw_buffer[exc.start]
if self.stream is not None:
position = self.stream_pointer-len(self.raw_buffer)+exc.start
else:
......
......@@ -144,7 +144,10 @@ class SafeRepresenter(BaseRepresenter):
return self.represent_scalar('tag:yaml.org,2002:str', data)
def represent_binary(self, data):
data = base64.encodestring(data).decode('ascii')
if hasattr(base64, 'encodebytes'):
data = base64.encodebytes(data).decode('ascii')
else:
data = base64.encodestring(data).decode('ascii')
return self.represent_scalar('tag:yaml.org,2002:binary', data, style='|')
def represent_bool(self, data):
......
......@@ -374,7 +374,8 @@ class Scanner:
# Set the current intendation to -1.
self.unwind_indent(-1)
# Reset everything (not really needed).
# Reset simple keys.
self.remove_possible_simple_key()
self.allow_simple_key = False
self.possible_simple_keys = {}
......
......@@ -17,18 +17,19 @@
# The following options are used to build PyYAML Windows installer
# for Python 2.3 on my PC:
#include_dirs=../../../libyaml/tags/0.1.2/include
#library_dirs=../../../libyaml/tags/0.1.2/win32/vc6/output/release/lib
#include_dirs=../../../libyaml/tags/0.1.3/include
#library_dirs=../../../libyaml/tags/0.1.3/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/tags/0.1.2/include
#library_dirs=../../../libyaml/tags/0.1.2/win32/vs2003/output/release/lib
#include_dirs=../../../libyaml/tags/0.1.3/include
#library_dirs=../../../libyaml/tags/0.1.3/win32/vs2003/output/release/lib
#define=YAML_DECLARE_STATIC
# The following options are used to build PyYAML Windows installer
# for Python 2.6 and Python 3.0 on my PC:
#include_dirs=../../../libyaml/tags/0.1.2/include
#library_dirs=../../../libyaml/tags/0.1.2/win32/vs2008/output/release/lib
# for Python 2.6, Python 3.0 and Python 3.1 on my PC:
#include_dirs=../../../libyaml/tags/0.1.3/include
#library_dirs=../../../libyaml/tags/0.1.3/win32/vs2008/output/release/lib
#define=YAML_DECLARE_STATIC
NAME = 'PyYAML'
VERSION = '3.08'
VERSION = '3.09'
DESCRIPTION = "YAML parser and emitter for Python"
LONG_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.
YAML is a data serialization format designed for human readability
and interaction with scripting languages. PyYAML is a YAML parser
and emitter for Python.
PyYAML features a complete YAML 1.1 parser, Unicode support, pickle
support, capable extension API, and sensible error messages. PyYAML
supports standard YAML tags and provides Python-specific tags that allow
to represent an arbitrary Python object.
supports standard YAML tags and provides Python-specific tags that
allow to represent an arbitrary Python object.
PyYAML is applicable for a broad range of tasks from complex
configuration files to object serialization and persistance."""
......@@ -33,6 +33,7 @@ CLASSIFIERS = [
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.0",
"Programming Language :: Python :: 3.1",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Text Processing :: Markup",
]
......@@ -310,10 +311,6 @@ class test(Command):
if __name__ == '__main__':
package_dir = {
'2': 'lib',
}
setup(
name=NAME,
version=VERSION,
......
B--- UTF-16-BE
B--- UTF-16-LE
......@@ -17,7 +17,7 @@ def _make_objects():
global MyLoader, MyDumper, MyTestClass1, MyTestClass2, MyTestClass3, YAMLObject1, YAMLObject2, \
AnObject, AnInstance, AState, ACustomState, InitArgs, InitArgsWithState, \
NewArgs, NewArgsWithState, Reduce, ReduceWithState, MyInt, MyList, MyDict, \
FixedOffset, execute
FixedOffset, today, execute
class MyLoader(yaml.Loader):
pass
......@@ -213,6 +213,8 @@ def _make_objects():
def dst(self, dt):
return datetime.timedelta(0)
today = datetime.date.today()
def _load_code(expression):
return eval(expression)
......
import yaml
import codecs, StringIO
import codecs, StringIO, tempfile, os, os.path
def _unicode_open(file, encoding, errors='strict'):
info = codecs.lookup(encoding)
......@@ -95,6 +95,35 @@ def test_unicode_output(unicode_filename, verbose=False):
test_unicode_output.unittest = ['.unicode']
def test_file_output(unicode_filename, verbose=False):
data = open(unicode_filename, 'rb').read().decode('utf-8')
handle, filename = tempfile.mkstemp()
os.close(handle)
try:
stream = StringIO.StringIO()
yaml.dump(data, stream, allow_unicode=True)
data1 = stream.getvalue()
stream = open(filename, 'wb')
yaml.dump(data, stream, allow_unicode=True)
stream.close()
data2 = open(filename, 'rb').read()
stream = open(filename, 'wb')
yaml.dump(data, stream, encoding='utf-16-le', allow_unicode=True)
stream.close()
data3 = open(filename, 'rb').read().decode('utf-16-le')[1:].encode('utf-8')
stream = _unicode_open(open(filename, 'wb'), 'utf-8')
yaml.dump(data, stream, allow_unicode=True)
stream.close()
data4 = open(filename, 'rb').read()
assert data1 == data2, (data1, data2)
assert data1 == data3, (data1, data3)
assert data1 == data4, (data1, data4)
finally:
if os.path.exists(filename):
os.unlink(filename)
test_file_output.unittest = ['.unicode']
def test_unicode_transfer(unicode_filename, verbose=False):
data = open(unicode_filename, 'rb').read().decode('utf-8')
for encoding in [None, 'utf-8', 'utf-16-be', 'utf-16-le']:
......
......@@ -6,33 +6,34 @@ import pprint
def test_representer_types(code_filename, verbose=False):
test_constructor._make_objects()
for allow_unicode in [False, True]:
native1 = test_constructor._load_code(open(code_filename, 'rb').read())
native2 = None
try:
output = yaml.dump(native1, Dumper=test_constructor.MyDumper,
allow_unicode=allow_unicode)
native2 = yaml.load(output, Loader=test_constructor.MyLoader)
for encoding in ['utf-8', 'utf-16-be', 'utf-16-le']:
native1 = test_constructor._load_code(open(code_filename, 'rb').read())
native2 = None
try:
if native1 == native2:
continue
except TypeError:
pass
value1 = test_constructor._serialize_value(native1)
value2 = test_constructor._serialize_value(native2)
if verbose:
print "SERIALIZED NATIVE1:"
print value1
print "SERIALIZED NATIVE2:"
print value2
assert value1 == value2, (native1, native2)
finally:
if verbose:
print "NATIVE1:"
pprint.pprint(native1)
print "NATIVE2:"
pprint.pprint(native2)
print "OUTPUT:"
print output
output = yaml.dump(native1, Dumper=test_constructor.MyDumper,
allow_unicode=allow_unicode, encoding=encoding)
native2 = yaml.load(output, Loader=test_constructor.MyLoader)
try:
if native1 == native2:
continue
except TypeError:
pass
value1 = test_constructor._serialize_value(native1)
value2 = test_constructor._serialize_value(native2)
if verbose:
print "SERIALIZED NATIVE1:"
print value1
print "SERIALIZED NATIVE2:"
print value2
assert value1 == value2, (native1, native2)
finally:
if verbose:
print "NATIVE1:"
pprint.pprint(native1)
print "NATIVE2:"
pprint.pprint(native2)
print "OUTPUT:"
print output
test_representer_types.unittest = ['.code']
......
......@@ -14,7 +14,7 @@ def _make_objects():
global MyLoader, MyDumper, MyTestClass1, MyTestClass2, MyTestClass3, YAMLObject1, YAMLObject2, \
AnObject, AnInstance, AState, ACustomState, InitArgs, InitArgsWithState, \
NewArgs, NewArgsWithState, Reduce, ReduceWithState, MyInt, MyList, MyDict, \
FixedOffset, execute
FixedOffset, today, execute
class MyLoader(yaml.Loader):
pass
......@@ -200,6 +200,8 @@ def _make_objects():
def dst(self, dt):
return datetime.timedelta(0)
today = datetime.date.today()
def _load_code(expression):
return eval(expression)
......
import yaml
import codecs, io
import codecs, io, tempfile, os, os.path
def test_unicode_input(unicode_filename, verbose=False):
data = open(unicode_filename, 'rb').read().decode('utf-8')
......@@ -94,6 +94,34 @@ def test_unicode_output(unicode_filename, verbose=False):
test_unicode_output.unittest = ['.unicode']
def test_file_output(unicode_filename, verbose=False):
data = open(unicode_filename, 'rb').read().decode('utf-8')
handle, filename = tempfile.mkstemp()
os.close(handle)
try:
stream = io.StringIO()
yaml.dump(data, stream, allow_unicode=True)
data1 = stream.getvalue()
stream = io.BytesIO()
yaml.dump(data, stream, encoding='utf-16-le', allow_unicode=True)
data2 = stream.getvalue().decode('utf-16-le')[1:]
stream = open(filename, 'w', encoding='utf-16-le')
yaml.dump(data, stream, allow_unicode=True)
stream.close()
data3 = open(filename, 'r', encoding='utf-16-le').read()
stream = open(filename, 'wb')
yaml.dump(data, stream, encoding='utf-8', allow_unicode=True)
stream.close()
data4 = open(filename, 'r', encoding='utf-8').read()
assert data1 == data2, (data1, data2)
assert data1 == data3, (data1, data3)
assert data1 == data4, (data1, data4)
finally:
if os.path.exists(filename):
os.unlink(filename)
test_file_output.unittest = ['.unicode']
def test_unicode_transfer(unicode_filename, verbose=False):
data = open(unicode_filename, 'rb').read().decode('utf-8')
for encoding in [None, 'utf-8', 'utf-16-be', 'utf-16-le']:
......
......@@ -6,33 +6,34 @@ import pprint
def test_representer_types(code_filename, verbose=False):
test_constructor._make_objects()
for allow_unicode in [False, True]:
native1 = test_constructor._load_code(open(code_filename, 'rb').read())
native2 = None
try:
output = yaml.dump(native1, Dumper=test_constructor.MyDumper,
allow_unicode=allow_unicode)
native2 = yaml.load(output, Loader=test_constructor.MyLoader)
for encoding in ['utf-8', 'utf-16-be', 'utf-16-le']:
native1 = test_constructor._load_code(open(code_filename, 'rb').read())
native2 = None
try:
if native1 == native2:
continue
except TypeError:
pass
value1 = test_constructor._serialize_value(native1)
value2 = test_constructor._serialize_value(native2)
if verbose:
print("SERIALIZED NATIVE1:")
print(value1)
print("SERIALIZED NATIVE2:")
print(value2)
assert value1 == value2, (native1, native2)
finally:
if verbose:
print("NATIVE1:")
pprint.pprint(native1)
print("NATIVE2:")
pprint.pprint(native2)
print("OUTPUT:")
print(output)
output = yaml.dump(native1, Dumper=test_constructor.MyDumper,
allow_unicode=allow_unicode, encoding=encoding)
native2 = yaml.load(output, Loader=test_constructor.MyLoader)
try:
if native1 == native2:
continue
except TypeError:
pass
value1 = test_constructor._serialize_value(native1)
value2 = test_constructor._serialize_value(native2)
if verbose:
print("SERIALIZED NATIVE1:")
print(value1)
print("SERIALIZED NATIVE2:")
print(value2)
assert value1 == value2, (native1, native2)
finally:
if verbose:
print("NATIVE1:")
pprint.pprint(native1)
print("NATIVE2:")
pprint.pprint(native2)
print("OUTPUT:")
print(output)
test_representer_types.unittest = ['.code']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment