Commit 718e2ec2 authored by SVN-Git Migration's avatar SVN-Git Migration

Imported Upstream version 3.05

parent dd09282a
Metadata-Version: 1.0
Name: PyYAML
Version: 3.04
Version: 3.05
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.04.tar.gz
Download-URL: http://pyyaml.org/download/pyyaml/PyYAML-3.05.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 3000 - The next generation YAML parser and emitter for Python.
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 them with the calls:
Then you may use the LibYAML based parser this way:
>>> yaml.load(stream, Loader=yaml.CLoader)
>>> yaml.dump(data, Dumper=yaml.CDumper)
......@@ -20,5 +20,5 @@ Post your questions and opinions to the YAML-Core mailing list:
Submit bug reports and feature requests to the PyYAML bug tracker:
'http://pyyaml.org/newticket?component=pyyaml'.
PyYAML 3000 is written by Kirill Simonov <xi@resolvent.net>. It is released
PyYAML is written by Kirill Simonov <xi@resolvent.net>. It is released
under the MIT license. See the file LICENSE for more details.
This diff is collapsed.
......@@ -651,6 +651,9 @@ cdef class CParser:
def check_node(self):
self._parse_next_event()
if self.parsed_event.type == YAML_STREAM_START_EVENT:
yaml_event_delete(&self.parsed_event)
self._parse_next_event()
if self.parsed_event.type != YAML_STREAM_END_EVENT:
return True
return False
......@@ -661,9 +664,6 @@ cdef class CParser:
return self._compose_document()
cdef object _compose_document(self):
if self.parsed_event.type == YAML_STREAM_START_EVENT:
yaml_event_delete(&self.parsed_event)
self._parse_next_event()
yaml_event_delete(&self.parsed_event)
node = self._compose_node(None, None)
self._parse_next_event()
......
......@@ -265,6 +265,7 @@ class YAMLObject(object):
"""
__metaclass__ = YAMLObjectMetaclass
__slots__ = () # no direct instantiation, so allow immutable subclasses
yaml_loader = Loader
yaml_dumper = Dumper
......
......@@ -14,6 +14,10 @@ class Composer(object):
self.anchors = {}
def check_node(self):
# Drop the STREAM-START event.
if self.check_event(StreamStartEvent):
self.get_event()
# If there are more documents available?
return not self.check_event(StreamEndEvent)
......@@ -23,11 +27,6 @@ class Composer(object):
return self.compose_document()
def compose_document(self):
# Drop the STREAM-START event.
if self.check_event(StreamStartEvent):
self.get_event()
# Drop the DOCUMENT-START event.
self.get_event()
......
......@@ -12,7 +12,7 @@ try:
except NameError:
from sets import Set as set
import binascii, re, sys
import binascii, re, sys, types
class ConstructorError(MarkedYAMLError):
pass
......@@ -37,10 +37,6 @@ class BaseConstructor(object):
if self.check_node():
return self.construct_document(self.get_node())
def g(): yield None
generator_type = type(g())
del g
def construct_document(self, node):
data = self.construct_object(node)
while self.state_generators:
......@@ -91,7 +87,7 @@ class BaseConstructor(object):
data = constructor(self, node)
else:
data = constructor(self, tag_suffix, node)
if isinstance(data, self.generator_type):
if isinstance(data, types.GeneratorType):
generator = data
data = generator.next()
if self.deep_construct:
......@@ -300,7 +296,7 @@ class SafeConstructor(BaseConstructor):
(?P<hour>[0-9][0-9]?)
:(?P<minute>[0-9][0-9])
:(?P<second>[0-9][0-9])
(?:(?P<fraction>\.[0-9]*))?
(?:\.(?P<fraction>[0-9]*))?
(?:[ \t]*(?P<tz>Z|(?P<tz_sign>[-+])(?P<tz_hour>[0-9][0-9]?)
(?::(?P<tz_minute>[0-9][0-9]))?))?)?$''', re.X)
......@@ -318,7 +314,7 @@ class SafeConstructor(BaseConstructor):
second = int(values['second'])
fraction = 0
if values['fraction']:
fraction = int(float(values['fraction'])*1000000)
fraction = int(values['fraction'][:6].ljust(6, '0'))
delta = None
if values['tz_sign']:
tz_hour = int(values['tz_hour'])
......@@ -383,7 +379,7 @@ class SafeConstructor(BaseConstructor):
def construct_yaml_str(self, node):
value = self.construct_scalar(node)
try:
return str(value)
return value.encode('ascii')
except UnicodeEncodeError:
return value
......
......@@ -155,6 +155,10 @@ class Parser(object):
def parse_document_start(self):
# Parse any extra document end indicators.
while self.check_token(DocumentEndToken):
self.get_token()
# Parse an explicit document.
if not self.check_token(StreamEndToken):
token = self.peek_token()
......@@ -186,7 +190,7 @@ class Parser(object):
token = self.peek_token()
start_mark = end_mark = token.start_mark
explicit = False
while self.check_token(DocumentEndToken):
if self.check_token(DocumentEndToken):
token = self.get_token()
end_mark = token.end_mark
explicit = True
......@@ -291,7 +295,7 @@ class Parser(object):
token = self.get_token()
end_mark = token.end_mark
anchor = token.value
if tag is not None and tag != u'!':
if tag is not None:
handle, suffix = tag
if handle is not None:
if handle not in self.tag_handles:
......
......@@ -12,7 +12,7 @@ try:
except NameError:
from sets import Set as set
import sys, copy_reg
import sys, copy_reg, types
class RepresenterError(YAMLError):
pass
......@@ -36,18 +36,6 @@ class BaseRepresenter(object):
self.object_keeper = []
self.alias_key = None
class C: pass
c = C()
def f(): pass
def g(): yield None
classobj_type = type(C)
instance_type = type(c)
function_type = type(f)
generator_type = type(g())
builtin_function_type = type(abs)
module_type = type(sys)
del C, c, f, g
def get_classobj_bases(self, cls):
bases = [cls]
for base in cls.__bases__:
......@@ -68,7 +56,7 @@ class BaseRepresenter(object):
#self.represented_objects[alias_key] = None
self.object_keeper.append(data)
data_types = type(data).__mro__
if type(data) is self.instance_type:
if type(data) is types.InstanceType:
data_types = self.get_classobj_bases(data.__class__)+list(data_types)
if data_types[0] in self.yaml_representers:
node = self.yaml_representers[data_types[0]](self, data)
......@@ -209,7 +197,16 @@ class SafeRepresenter(BaseRepresenter):
elif data == -self.inf_value:
value = u'-.inf'
else:
value = unicode(repr(data))
value = unicode(repr(data)).lower()
# Note that in some cases `repr(data)` represents a float number
# without the decimal parts. For instance:
# >>> repr(1e17)
# '1e17'
# Unfortunately, this is not a valid float representation according
# to the definition of the `!!float` tag. We fix this by adding
# '.0' before the 'e' symbol.
if u'.' not in value and u'e' in value:
value = value.replace(u'e', u'.0e', 1)
return self.represent_scalar(u'tag:yaml.org,2002:float', value)
def represent_list(self, data):
......@@ -471,19 +468,19 @@ Representer.add_representer(tuple,
Representer.add_representer(type,
Representer.represent_name)
Representer.add_representer(Representer.classobj_type,
Representer.add_representer(types.ClassType,
Representer.represent_name)
Representer.add_representer(Representer.function_type,
Representer.add_representer(types.FunctionType,
Representer.represent_name)
Representer.add_representer(Representer.builtin_function_type,
Representer.add_representer(types.BuiltinFunctionType,
Representer.represent_name)
Representer.add_representer(Representer.module_type,
Representer.add_representer(types.ModuleType,
Representer.represent_module)
Representer.add_multi_representer(Representer.instance_type,
Representer.add_multi_representer(types.InstanceType,
Representer.represent_instance)
Representer.add_multi_representer(object,
......
......@@ -32,6 +32,18 @@ class BaseResolver(object):
add_implicit_resolver = classmethod(add_implicit_resolver)
def add_path_resolver(cls, tag, path, kind=None):
# Note: `add_path_resolver` is experimental. The API could be changed.
# `new_path` is a pattern that is matched against the path from the
# root to the node that is being considered. `node_path` elements are
# tuples `(node_check, index_check)`. `node_check` is a node class:
# `ScalarNode`, `SequenceNode`, `MappingNode` or `None`. `None`
# matches any kind of a node. `index_check` could be `None`, a boolean
# value, a string value, or a number. `None` and `False` match against
# any _value_ of sequence and mapping nodes. `True` matches against
# any _key_ of a mapping node. A string `index_check` matches against
# a mapping value that corresponds to a scalar key which content is
# equal to the `index_check` value. An integer `index_check` matches
# against a sequence value with the index equal to `index_check`.
if not 'yaml_path_resolvers' in cls.__dict__:
cls.yaml_path_resolvers = cls.yaml_path_resolvers.copy()
new_path = []
......@@ -113,13 +125,14 @@ class BaseResolver(object):
return
if index_check is True and current_index is not None:
return
if index_check in [False, None] and current_index is None:
if (index_check is False or index_check is None) \
and current_index is None:
return
if isinstance(index_check, basestring):
if not (isinstance(current_index, ScalarNode)
and index_check == current_index.value):
return
elif isinstance(index_check, int):
elif isinstance(index_check, int) and not isinstance(index_check, bool):
if index_check != current_index:
return
return True
......
......@@ -9,9 +9,20 @@
# List of directories to search for 'libyaml.a' (separated by ':').
#library_dirs=/usr/local/lib:../../lib
# An alternative compiler to build the extention.
#compiler=mingw32
# Additional preprocessor definitions might be required.
#define=YAML_DECLARE_STATIC
# 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
#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
#define=YAML_DECLARE_STATIC
NAME = 'PyYAML'
VERSION = '3.04'
VERSION = '3.05'
DESCRIPTION = "YAML parser and emitter for Python"
LONG_DESCRIPTION = """\
YAML is a data serialization format designed for human readability and
......
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