Merged in scorphus/pyyaml (pull request #9)

scanner: use infinitive verb after auxiliary word could
diff --git a/ext/_yaml.pxd b/ext/_yaml.pxd
index f47f459..7937c9d 100644
--- a/ext/_yaml.pxd
+++ b/ext/_yaml.pxd
@@ -86,15 +86,15 @@
         YAML_MAPPING_END_EVENT
 
     ctypedef int yaml_read_handler_t(void *data, char *buffer,
-            int size, int *size_read) except 0
+            size_t size, size_t *size_read) except 0
 
     ctypedef int yaml_write_handler_t(void *data, char *buffer,
-            int size) except 0
+            size_t size) except 0
 
     ctypedef struct yaml_mark_t:
-        int index
-        int line
-        int column
+        size_t index
+        size_t line
+        size_t column
     ctypedef struct yaml_version_directive_t:
         int major
         int minor
@@ -113,7 +113,7 @@
         char *suffix
     ctypedef struct _yaml_token_scalar_data_t:
         char *value
-        int length
+        size_t length
         yaml_scalar_style_t style
     ctypedef struct _yaml_token_version_directive_data_t:
         int major
@@ -152,7 +152,7 @@
         char *anchor
         char *tag
         char *value
-        int length
+        size_t length
         int plain_implicit
         int quoted_implicit
         yaml_scalar_style_t style
@@ -183,7 +183,7 @@
     ctypedef struct yaml_parser_t:
         yaml_error_type_t error
         char *problem
-        int problem_offset
+        size_t problem_offset
         int problem_value
         yaml_mark_t problem_mark
         char *context
@@ -210,7 +210,7 @@
             int implicit)
     int yaml_alias_event_initialize(yaml_event_t *event, char *anchor)
     int yaml_scalar_event_initialize(yaml_event_t *event,
-            char *anchor, char *tag, char *value, int length,
+            char *anchor, char *tag, char *value, size_t length,
             int plain_implicit, int quoted_implicit,
             yaml_scalar_style_t style)
     int yaml_sequence_start_event_initialize(yaml_event_t *event,
@@ -224,7 +224,7 @@
     int yaml_parser_initialize(yaml_parser_t *parser)
     void yaml_parser_delete(yaml_parser_t *parser)
     void yaml_parser_set_input_string(yaml_parser_t *parser,
-            char *input, int size)
+            char *input, size_t size)
     void yaml_parser_set_input(yaml_parser_t *parser,
             yaml_read_handler_t *handler, void *data)
     void yaml_parser_set_encoding(yaml_parser_t *parser,
@@ -235,7 +235,7 @@
     int yaml_emitter_initialize(yaml_emitter_t *emitter)
     void yaml_emitter_delete(yaml_emitter_t *emitter)
     void yaml_emitter_set_output_string(yaml_emitter_t *emitter,
-            char *output, int size, int *size_written)
+            char *output, size_t size, size_t *size_written)
     void yaml_emitter_set_output(yaml_emitter_t *emitter,
             yaml_write_handler_t *handler, void *data)
     void yaml_emitter_set_encoding(yaml_emitter_t *emitter,
diff --git a/ext/_yaml.pyx b/ext/_yaml.pyx
index 5158fb4..83eca65 100644
--- a/ext/_yaml.pyx
+++ b/ext/_yaml.pyx
@@ -905,7 +905,7 @@
                 raise error
         return 1
 
-cdef int input_handler(void *data, char *buffer, int size, int *read) except 0:
+cdef int input_handler(void *data, char *buffer, size_t size, size_t *read) except 0:
     cdef CParser parser
     parser = <CParser>data
     if parser.stream_cache is None:
@@ -1515,7 +1515,7 @@
             self.ascend_resolver()
         return 1
 
-cdef int output_handler(void *data, char *buffer, int size) except 0:
+cdef int output_handler(void *data, char *buffer, size_t size) except 0:
     cdef CEmitter emitter
     emitter = <CEmitter>data
     if emitter.dump_unicode == 0:
diff --git a/lib/yaml/__init__.py b/lib/yaml/__init__.py
index 76e19e1..87c15d3 100644
--- a/lib/yaml/__init__.py
+++ b/lib/yaml/__init__.py
@@ -8,7 +8,7 @@
 from loader import *
 from dumper import *
 
-__version__ = '3.11'
+__version__ = '3.12'
 
 try:
     from cyaml import *
diff --git a/lib/yaml/representer.py b/lib/yaml/representer.py
index 5f4fc70..4ea8cb1 100644
--- a/lib/yaml/representer.py
+++ b/lib/yaml/representer.py
@@ -139,7 +139,9 @@
 class SafeRepresenter(BaseRepresenter):
 
     def ignore_aliases(self, data):
-        if data in [None, ()]:
+        if data is None:
+            return True
+        if isinstance(data, tuple) and data == ():
             return True
         if isinstance(data, (str, unicode, bool, int, float)):
             return True
diff --git a/lib/yaml/resolver.py b/lib/yaml/resolver.py
index 6b5ab87..528fbc0 100644
--- a/lib/yaml/resolver.py
+++ b/lib/yaml/resolver.py
@@ -24,7 +24,10 @@
 
     def add_implicit_resolver(cls, tag, regexp, first):
         if not 'yaml_implicit_resolvers' in cls.__dict__:
-            cls.yaml_implicit_resolvers = cls.yaml_implicit_resolvers.copy()
+            implicit_resolvers = {}
+            for key in cls.yaml_implicit_resolvers:
+                implicit_resolvers[key] = cls.yaml_implicit_resolvers[key][:]
+            cls.yaml_implicit_resolvers = implicit_resolvers
         if first is None:
             first = [None]
         for ch in first:
diff --git a/lib3/yaml/__init__.py b/lib3/yaml/__init__.py
index a5e20f9..d7d27fe 100644
--- a/lib3/yaml/__init__.py
+++ b/lib3/yaml/__init__.py
@@ -8,7 +8,7 @@
 from .loader import *
 from .dumper import *
 
-__version__ = '3.11'
+__version__ = '3.12'
 try:
     from .cyaml import *
     __with_libyaml__ = True
diff --git a/lib3/yaml/representer.py b/lib3/yaml/representer.py
index 67cd6fd..b9e65c5 100644
--- a/lib3/yaml/representer.py
+++ b/lib3/yaml/representer.py
@@ -5,7 +5,7 @@
 from .error import *
 from .nodes import *
 
-import datetime, sys, copyreg, types, base64
+import datetime, sys, copyreg, types, base64, collections
 
 class RepresenterError(YAMLError):
     pass
@@ -132,7 +132,9 @@
 class SafeRepresenter(BaseRepresenter):
 
     def ignore_aliases(self, data):
-        if data in [None, ()]:
+        if data is None:
+            return True
+        if isinstance(data, tuple) and data == ():
             return True
         if isinstance(data, (str, bytes, bool, int, float)):
             return True
@@ -351,6 +353,14 @@
             value['dictitems'] = dictitems
         return self.represent_mapping(tag+function_name, value)
 
+    def represent_ordered_dict(self, data):
+        # Provide uniform representation across different Python versions.
+        data_type = type(data)
+        tag = 'tag:yaml.org,2002:python/object/apply:%s.%s' \
+                % (data_type.__module__, data_type.__name__)
+        items = [[key, value] for key, value in data.items()]
+        return self.represent_sequence(tag, [items])
+
 Representer.add_representer(complex,
         Representer.represent_complex)
 
@@ -360,6 +370,9 @@
 Representer.add_representer(type,
         Representer.represent_name)
 
+Representer.add_representer(collections.OrderedDict,
+        Representer.represent_ordered_dict)
+
 Representer.add_representer(types.FunctionType,
         Representer.represent_name)
 
diff --git a/lib3/yaml/resolver.py b/lib3/yaml/resolver.py
index 0eece25..02b82e7 100644
--- a/lib3/yaml/resolver.py
+++ b/lib3/yaml/resolver.py
@@ -25,7 +25,10 @@
     @classmethod
     def add_implicit_resolver(cls, tag, regexp, first):
         if not 'yaml_implicit_resolvers' in cls.__dict__:
-            cls.yaml_implicit_resolvers = cls.yaml_implicit_resolvers.copy()
+            implicit_resolvers = {}
+            for key in cls.yaml_implicit_resolvers:
+                implicit_resolvers[key] = cls.yaml_implicit_resolvers[key][:]
+            cls.yaml_implicit_resolvers = implicit_resolvers
         if first is None:
             first = [None]
         for ch in first:
diff --git a/setup.py b/setup.py
index 727c3e0..9dc5e8d 100644
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,6 @@
 
 NAME = 'PyYAML'
-VERSION = '3.11'
+VERSION = '3.12'
 DESCRIPTION = "YAML parser and emitter for Python"
 LONG_DESCRIPTION = """\
 YAML is a data serialization format designed for human readability
@@ -27,13 +27,10 @@
     "Operating System :: OS Independent",
     "Programming Language :: Python",
     "Programming Language :: Python :: 2",
-    "Programming Language :: Python :: 2.5",
-    "Programming Language :: Python :: 2.6",
     "Programming Language :: Python :: 2.7",
     "Programming Language :: Python :: 3",
-    "Programming Language :: Python :: 3.0",
-    "Programming Language :: Python :: 3.1",
-    "Programming Language :: Python :: 3.2",
+    "Programming Language :: Python :: 3.4",
+    "Programming Language :: Python :: 3.5",
     "Topic :: Software Development :: Libraries :: Python Modules",
     "Topic :: Text Processing :: Markup",
 ]
@@ -57,7 +54,7 @@
 """
 
 
-import sys, os.path
+import sys, os.path, platform
 
 from distutils import log
 from distutils.core import setup, Command
@@ -66,7 +63,7 @@
 from distutils.dir_util import mkpath
 from distutils.command.build_ext import build_ext as _build_ext
 from distutils.command.bdist_rpm import bdist_rpm as _bdist_rpm
-from distutils.errors import CompileError, LinkError, DistutilsPlatformError
+from distutils.errors import DistutilsError, CompileError, LinkError, DistutilsPlatformError
 
 if 'setuptools.extension' in sys.modules:
     _Extension = sys.modules['setuptools.extension']._Extension
@@ -74,21 +71,18 @@
     sys.modules['distutils.extension'].Extension = _Extension
     sys.modules['distutils.command.build_ext'].Extension = _Extension
 
-with_pyrex = None
-if sys.version_info[0] < 3:
-    try:
-        from Cython.Distutils.extension import Extension as _Extension
-        from Cython.Distutils import build_ext as _build_ext
-        with_pyrex = 'cython'
-    except ImportError:
-        try:
-            # Pyrex cannot build _yaml.c at the moment,
-            # but it may get fixed eventually.
-            from Pyrex.Distutils import Extension as _Extension
-            from Pyrex.Distutils import build_ext as _build_ext
-            with_pyrex = 'pyrex'
-        except ImportError:
-            pass
+with_cython = False
+try:
+    from Cython.Distutils.extension import Extension as _Extension
+    from Cython.Distutils import build_ext as _build_ext
+    with_cython = True
+except ImportError:
+    pass
+
+try:
+    from wheel.bdist_wheel import bdist_wheel
+except ImportError:
+    bdist_wheel = None
 
 
 class Distribution(_Distribution):
@@ -122,7 +116,8 @@
         return False
 
     def ext_status(self, ext):
-        if 'Java' in sys.version or 'IronPython' in sys.version or 'PyPy' in sys.version:
+        implementation = platform.python_implementation()
+        if implementation != 'CPython':
             return False
         if isinstance(ext, Extension):
             with_ext = getattr(self, ext.attr_name)
@@ -135,7 +130,7 @@
 
     def __init__(self, name, sources, feature_name, feature_description,
             feature_check, **kwds):
-        if not with_pyrex:
+        if not with_cython:
             for filename in sources[:]:
                 base, ext = os.path.splitext(filename)
                 if ext == '.pyx':
@@ -179,9 +174,7 @@
         self.check_extensions_list(self.extensions)
         filenames = []
         for ext in self.extensions:
-            if with_pyrex == 'pyrex':
-                self.pyrex_sources(ext.sources, ext)
-            elif with_pyrex == 'cython':
+            if with_cython:
                 self.cython_sources(ext.sources, ext)
             for filename in ext.sources:
                 filenames.append(filename)
@@ -211,9 +204,7 @@
                 with_ext = self.check_extension_availability(ext)
             if not with_ext:
                 continue
-            if with_pyrex == 'pyrex':
-                ext.sources = self.pyrex_sources(ext.sources, ext)
-            elif with_pyrex == 'cython':
+            if with_cython:
                 ext.sources = self.cython_sources(ext.sources, ext)
             self.build_extension(ext)
 
@@ -308,7 +299,17 @@
         else:
             sys.path.insert(0, 'tests/lib3')
         import test_all
-        test_all.main([])
+        if not test_all.main([]):
+            raise DistutilsError("Tests failed")
+
+
+cmdclass = {
+    'build_ext': build_ext,
+    'bdist_rpm': bdist_rpm,
+    'test': test,
+}
+if bdist_wheel:
+    cmdclass['bdist_wheel'] = bdist_wheel
 
 
 if __name__ == '__main__':
@@ -335,11 +336,6 @@
         ],
 
         distclass=Distribution,
-
-        cmdclass={
-            'build_ext': build_ext,
-            'bdist_rpm': bdist_rpm,
-            'test': test,
-        },
+        cmdclass=cmdclass,
     )
 
diff --git a/tests/data/invalid-python-name-module-2.loader-error b/tests/data/invalid-python-name-module-2.loader-error
deleted file mode 100644
index debc313..0000000
--- a/tests/data/invalid-python-name-module-2.loader-error
+++ /dev/null
@@ -1 +0,0 @@
---- !!python/name:xml.parsers
diff --git a/tests/lib/test_all.py b/tests/lib/test_all.py
index fec4ae4..72a5067 100644
--- a/tests/lib/test_all.py
+++ b/tests/lib/test_all.py
@@ -8,7 +8,7 @@
     if yaml.__with_libyaml__:
         import test_yaml_ext
         collections.append(test_yaml_ext)
-    test_appliance.run(collections, args)
+    return test_appliance.run(collections, args)
 
 if __name__ == '__main__':
     main()
diff --git a/tests/lib/test_appliance.py b/tests/lib/test_appliance.py
index d50d5a2..e27d25b 100644
--- a/tests/lib/test_appliance.py
+++ b/tests/lib/test_appliance.py
@@ -118,6 +118,7 @@
         sys.stdout.write('FAILURES: %s\n' % failures)
     if errors:
         sys.stdout.write('ERRORS: %s\n' % errors)
+    return not (failures or errors)
 
 def run(collections, args=None):
     test_functions = find_test_functions(collections)
@@ -147,5 +148,5 @@
         else:
             result = execute(function, [], verbose)
             results.append(result)
-    display(results, verbose=verbose)
+    return display(results, verbose=verbose)
 
diff --git a/tests/lib3/test_all.py b/tests/lib3/test_all.py
index fec4ae4..72a5067 100644
--- a/tests/lib3/test_all.py
+++ b/tests/lib3/test_all.py
@@ -8,7 +8,7 @@
     if yaml.__with_libyaml__:
         import test_yaml_ext
         collections.append(test_yaml_ext)
-    test_appliance.run(collections, args)
+    return test_appliance.run(collections, args)
 
 if __name__ == '__main__':
     main()
diff --git a/tests/lib3/test_appliance.py b/tests/lib3/test_appliance.py
index 81ff00b..77e0052 100644
--- a/tests/lib3/test_appliance.py
+++ b/tests/lib3/test_appliance.py
@@ -112,6 +112,7 @@
         sys.stdout.write('FAILURES: %s\n' % failures)
     if errors:
         sys.stdout.write('ERRORS: %s\n' % errors)
+    return not (failures or errors)
 
 def run(collections, args=None):
     test_functions = find_test_functions(collections)
@@ -141,5 +142,5 @@
         else:
             result = execute(function, [], verbose)
             results.append(result)
-    display(results, verbose=verbose)
+    return display(results, verbose=verbose)