2006-03-04 22:43:48 +00:00
|
|
|
|
2006-04-23 18:07:52 +00:00
|
|
|
NAME = 'PyYAML'
|
Deprecate/warn usage of yaml.load(input)
The `load` and `load_all` methods will issue a warning when they are
called without the 'Loader=' parameter. The warning will point to a URL
that is always up to date with the latest information on the usage of
`load`.
There are several ways to stop the warning:
* Use `full_load(input)` - sugar for `yaml.load(input, FullLoader)`
* FullLoader is the new safe but complete loader class
* Use `safe_load(input)` - sugar for `yaml.load(input, SafeLoader)`
* Make sure your input YAML consists of the 'safe' subset
* Use `unsafe_load(input)` - sugar for `yaml.load(input, UnsafeLoader)`
* Make sure your input YAML consists of the 'safe' subset
* Use `yaml.load(input, Loader=yaml.<loader>)`
* Or shorter `yaml.load(input, yaml.<loader>)`
* Where '<loader>' can be:
* FullLoader - safe, complete Python YAML loading
* SafeLoader - safe, partial Python YAML loading
* UnsafeLoader - more explicit name for the old, unsafe 'Loader' class
* yaml.warnings({'YAMLLoadWarning': False})
* Use this when you use third party modules that use `yaml.load(input)`
* Only do this if input is trusted
The above `load()` expressions all have `load_all()` counterparts.
You can get the original unsafe behavior with:
* `yaml.unsafe_load(input)`
* `yaml.load(input, Loader=yaml.UnsafeLoader)`
In a future release, `yaml.load(input)` will raise an exception.
The new loader called FullLoader is almost entirely complete as
Loader/UnsafeLoader but it does it avoids all known code execution
paths. It is the preferred YAML loader, and the current default for
`yaml.load(input)` when you get the warning.
Here are some of the exploits that can be triggered with UnsafeLoader
but not with FullLoader:
```
python -c 'import os, yaml; yaml.full_load("!!python/object/new:os.system [echo EXPLOIT!]")'`
python -c 'import yaml; print yaml.full_load("!!python/object/new:abs [-5]")'
python -c 'import yaml; yaml.full_load("!!python/object/new:eval [exit(5)]")' ; echo $?
python -c 'import yaml; yaml.full_load("!!python/object/new:exit [5]")' ; echo $?
2019-02-18 03:22:58 +00:00
|
|
|
VERSION = '3.13'
|
2006-04-23 18:07:52 +00:00
|
|
|
DESCRIPTION = "YAML parser and emitter for Python"
|
|
|
|
LONG_DESCRIPTION = """\
|
2009-08-30 20:06:16 +00:00
|
|
|
YAML is a data serialization format designed for human readability
|
|
|
|
and interaction with scripting languages. PyYAML is a YAML parser
|
|
|
|
and emitter for Python.
|
2006-04-23 18:07:52 +00:00
|
|
|
|
2006-05-07 14:36:42 +00:00
|
|
|
PyYAML features a complete YAML 1.1 parser, Unicode support, pickle
|
|
|
|
support, capable extension API, and sensible error messages. PyYAML
|
2009-08-30 20:06:16 +00:00
|
|
|
supports standard YAML tags and provides Python-specific tags that
|
|
|
|
allow to represent an arbitrary Python object.
|
2006-04-23 18:07:52 +00:00
|
|
|
|
2006-05-07 14:36:42 +00:00
|
|
|
PyYAML is applicable for a broad range of tasks from complex
|
2017-01-22 11:42:27 +00:00
|
|
|
configuration files to object serialization and persistence."""
|
2006-03-04 22:43:48 +00:00
|
|
|
AUTHOR = "Kirill Simonov"
|
|
|
|
AUTHOR_EMAIL = 'xi@resolvent.net'
|
|
|
|
LICENSE = "MIT"
|
2006-04-23 18:07:52 +00:00
|
|
|
PLATFORMS = "Any"
|
2018-06-24 23:08:57 +00:00
|
|
|
URL = "https://github.com/yaml/pyyaml"
|
|
|
|
DOWNLOAD_URL = "https://pypi.org/project/PyYAML/"
|
2006-04-23 18:07:52 +00:00
|
|
|
CLASSIFIERS = [
|
2008-09-30 11:45:18 +00:00
|
|
|
"Development Status :: 5 - Production/Stable",
|
2006-04-23 18:07:52 +00:00
|
|
|
"Intended Audience :: Developers",
|
|
|
|
"License :: OSI Approved :: MIT License",
|
|
|
|
"Operating System :: OS Independent",
|
|
|
|
"Programming Language :: Python",
|
2008-12-05 19:37:52 +00:00
|
|
|
"Programming Language :: Python :: 2",
|
2011-05-30 03:28:15 +00:00
|
|
|
"Programming Language :: Python :: 2.7",
|
2008-12-29 17:24:05 +00:00
|
|
|
"Programming Language :: Python :: 3",
|
2016-08-25 22:52:48 +00:00
|
|
|
"Programming Language :: Python :: 3.4",
|
|
|
|
"Programming Language :: Python :: 3.5",
|
2017-04-16 22:02:35 +00:00
|
|
|
"Programming Language :: Python :: 3.6",
|
2018-01-31 08:29:58 +00:00
|
|
|
"Programming Language :: Python :: 3.7",
|
2017-04-16 22:02:35 +00:00
|
|
|
"Programming Language :: Python :: Implementation :: CPython",
|
|
|
|
"Programming Language :: Python :: Implementation :: PyPy",
|
2006-04-23 18:07:52 +00:00
|
|
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
|
|
"Topic :: Text Processing :: Markup",
|
|
|
|
]
|
|
|
|
|
2008-09-30 13:29:34 +00:00
|
|
|
|
2008-10-02 00:24:42 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2016-08-25 22:52:48 +00:00
|
|
|
import sys, os.path, platform
|
2008-10-09 15:56:20 +00:00
|
|
|
|
2008-10-02 00:24:42 +00:00
|
|
|
from distutils import log
|
2008-10-01 23:16:09 +00:00
|
|
|
from distutils.core import setup, Command
|
|
|
|
from distutils.core import Distribution as _Distribution
|
|
|
|
from distutils.core import Extension as _Extension
|
2008-10-02 00:24:42 +00:00
|
|
|
from distutils.dir_util import mkpath
|
2008-10-01 23:16:09 +00:00
|
|
|
from distutils.command.build_ext import build_ext as _build_ext
|
2008-11-30 14:06:13 +00:00
|
|
|
from distutils.command.bdist_rpm import bdist_rpm as _bdist_rpm
|
2016-06-16 01:28:10 +00:00
|
|
|
from distutils.errors import DistutilsError, CompileError, LinkError, DistutilsPlatformError
|
2008-10-01 23:16:09 +00:00
|
|
|
|
2008-10-09 15:56:20 +00:00
|
|
|
if 'setuptools.extension' in sys.modules:
|
|
|
|
_Extension = sys.modules['setuptools.extension']._Extension
|
|
|
|
sys.modules['distutils.core'].Extension = _Extension
|
|
|
|
sys.modules['distutils.extension'].Extension = _Extension
|
|
|
|
sys.modules['distutils.command.build_ext'].Extension = _Extension
|
|
|
|
|
2016-06-16 00:28:34 +00:00
|
|
|
with_cython = False
|
2018-06-28 19:23:52 +00:00
|
|
|
if 'sdist' in sys.argv:
|
|
|
|
# we need cython here
|
|
|
|
with_cython = True
|
2016-06-16 00:28:34 +00:00
|
|
|
try:
|
|
|
|
from Cython.Distutils.extension import Extension as _Extension
|
|
|
|
from Cython.Distutils import build_ext as _build_ext
|
|
|
|
with_cython = True
|
|
|
|
except ImportError:
|
2018-06-28 19:23:52 +00:00
|
|
|
if with_cython:
|
|
|
|
raise
|
2008-10-01 23:16:09 +00:00
|
|
|
|
2016-06-17 03:32:32 +00:00
|
|
|
try:
|
|
|
|
from wheel.bdist_wheel import bdist_wheel
|
|
|
|
except ImportError:
|
|
|
|
bdist_wheel = None
|
|
|
|
|
2008-10-01 23:16:09 +00:00
|
|
|
|
|
|
|
class Distribution(_Distribution):
|
|
|
|
|
|
|
|
def __init__(self, attrs=None):
|
|
|
|
_Distribution.__init__(self, attrs)
|
|
|
|
if not self.ext_modules:
|
|
|
|
return
|
2008-10-02 02:40:48 +00:00
|
|
|
for idx in range(len(self.ext_modules)-1, -1, -1):
|
|
|
|
ext = self.ext_modules[idx]
|
2008-10-01 23:16:09 +00:00
|
|
|
if not isinstance(ext, Extension):
|
|
|
|
continue
|
|
|
|
setattr(self, ext.attr_name, None)
|
|
|
|
self.global_options = [
|
|
|
|
(ext.option_name, None,
|
2008-10-02 00:24:42 +00:00
|
|
|
"include %s (default if %s is available)"
|
|
|
|
% (ext.feature_description, ext.feature_name)),
|
2008-10-01 23:16:09 +00:00
|
|
|
(ext.neg_option_name, None,
|
2008-10-02 00:24:42 +00:00
|
|
|
"exclude %s" % ext.feature_description),
|
2008-10-01 23:16:09 +00:00
|
|
|
] + self.global_options
|
|
|
|
self.negative_opt = self.negative_opt.copy()
|
|
|
|
self.negative_opt[ext.neg_option_name] = ext.option_name
|
|
|
|
|
2008-11-30 14:06:13 +00:00
|
|
|
def has_ext_modules(self):
|
|
|
|
if not self.ext_modules:
|
|
|
|
return False
|
|
|
|
for ext in self.ext_modules:
|
|
|
|
with_ext = self.ext_status(ext)
|
|
|
|
if with_ext is None or with_ext:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def ext_status(self, ext):
|
2016-08-25 22:52:48 +00:00
|
|
|
implementation = platform.python_implementation()
|
|
|
|
if implementation != 'CPython':
|
2011-05-29 16:13:17 +00:00
|
|
|
return False
|
2008-11-30 14:06:13 +00:00
|
|
|
if isinstance(ext, Extension):
|
|
|
|
with_ext = getattr(self, ext.attr_name)
|
|
|
|
return with_ext
|
|
|
|
else:
|
|
|
|
return True
|
|
|
|
|
2008-10-01 23:16:09 +00:00
|
|
|
|
|
|
|
class Extension(_Extension):
|
|
|
|
|
2008-10-02 00:24:42 +00:00
|
|
|
def __init__(self, name, sources, feature_name, feature_description,
|
|
|
|
feature_check, **kwds):
|
2016-06-16 00:28:34 +00:00
|
|
|
if not with_cython:
|
2008-10-01 23:16:09 +00:00
|
|
|
for filename in sources[:]:
|
|
|
|
base, ext = os.path.splitext(filename)
|
2008-10-02 02:40:48 +00:00
|
|
|
if ext == '.pyx':
|
|
|
|
sources.remove(filename)
|
|
|
|
sources.append('%s.c' % base)
|
2008-10-01 23:16:09 +00:00
|
|
|
_Extension.__init__(self, name, sources, **kwds)
|
|
|
|
self.feature_name = feature_name
|
|
|
|
self.feature_description = feature_description
|
2008-10-02 00:24:42 +00:00
|
|
|
self.feature_check = feature_check
|
2008-10-01 23:16:09 +00:00
|
|
|
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):
|
|
|
|
|
2008-10-02 02:40:48 +00:00
|
|
|
def run(self):
|
|
|
|
optional = True
|
|
|
|
disabled = True
|
|
|
|
for ext in self.extensions:
|
2008-11-30 14:06:13 +00:00
|
|
|
with_ext = self.distribution.ext_status(ext)
|
|
|
|
if with_ext is None:
|
|
|
|
disabled = False
|
|
|
|
elif with_ext:
|
2008-10-02 02:40:48 +00:00
|
|
|
optional = False
|
|
|
|
disabled = False
|
|
|
|
break
|
|
|
|
if disabled:
|
|
|
|
return
|
|
|
|
try:
|
|
|
|
_build_ext.run(self)
|
2008-12-29 17:24:05 +00:00
|
|
|
except DistutilsPlatformError:
|
|
|
|
exc = sys.exc_info()[1]
|
2008-10-02 02:40:48 +00:00
|
|
|
if optional:
|
|
|
|
log.warn(str(exc))
|
|
|
|
log.warn("skipping build_ext")
|
|
|
|
else:
|
|
|
|
raise
|
|
|
|
|
2008-10-01 23:16:09 +00:00
|
|
|
def get_source_files(self):
|
|
|
|
self.check_extensions_list(self.extensions)
|
|
|
|
filenames = []
|
|
|
|
for ext in self.extensions:
|
2016-06-16 00:28:34 +00:00
|
|
|
if with_cython:
|
2008-12-29 23:21:43 +00:00
|
|
|
self.cython_sources(ext.sources, ext)
|
2008-10-01 23:16:09 +00:00
|
|
|
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
|
|
|
|
|
2008-11-30 14:06:13 +00:00
|
|
|
def get_outputs(self):
|
|
|
|
self.check_extensions_list(self.extensions)
|
|
|
|
outputs = []
|
|
|
|
for ext in self.extensions:
|
|
|
|
fullname = self.get_ext_fullname(ext.name)
|
|
|
|
filename = os.path.join(self.build_lib,
|
|
|
|
self.get_ext_filename(fullname))
|
|
|
|
if os.path.isfile(filename):
|
|
|
|
outputs.append(filename)
|
|
|
|
return outputs
|
|
|
|
|
2008-10-01 23:16:09 +00:00
|
|
|
def build_extensions(self):
|
|
|
|
self.check_extensions_list(self.extensions)
|
|
|
|
for ext in self.extensions:
|
2008-11-30 14:06:13 +00:00
|
|
|
with_ext = self.distribution.ext_status(ext)
|
2017-09-08 15:05:24 +00:00
|
|
|
if with_ext is not None and not with_ext:
|
2008-11-30 14:06:13 +00:00
|
|
|
continue
|
2016-06-16 00:28:34 +00:00
|
|
|
if with_cython:
|
2008-12-29 23:21:43 +00:00
|
|
|
ext.sources = self.cython_sources(ext.sources, ext)
|
2017-09-08 15:05:24 +00:00
|
|
|
try:
|
|
|
|
self.build_extension(ext)
|
|
|
|
except (CompileError, LinkError):
|
|
|
|
if with_ext is not None:
|
|
|
|
raise
|
|
|
|
log.warn("Error compiling module, falling back to pure Python")
|
2008-10-02 00:24:42 +00:00
|
|
|
|
2008-10-01 23:16:09 +00:00
|
|
|
|
2008-11-30 14:06:13 +00:00
|
|
|
class bdist_rpm(_bdist_rpm):
|
2008-10-01 23:16:09 +00:00
|
|
|
|
2008-11-30 14:06:13 +00:00
|
|
|
def _make_spec_file(self):
|
|
|
|
argv0 = sys.argv[0]
|
|
|
|
features = []
|
|
|
|
for ext in self.distribution.ext_modules:
|
|
|
|
if not isinstance(ext, Extension):
|
|
|
|
continue
|
|
|
|
with_ext = getattr(self.distribution, ext.attr_name)
|
|
|
|
if with_ext is None:
|
|
|
|
continue
|
|
|
|
if with_ext:
|
|
|
|
features.append('--'+ext.option_name)
|
|
|
|
else:
|
|
|
|
features.append('--'+ext.neg_option_name)
|
|
|
|
sys.argv[0] = ' '.join([argv0]+features)
|
|
|
|
spec_file = _bdist_rpm._make_spec_file(self)
|
|
|
|
sys.argv[0] = argv0
|
|
|
|
return spec_file
|
2008-10-01 23:16:09 +00:00
|
|
|
|
2006-03-04 22:43:48 +00:00
|
|
|
|
2008-12-28 20:16:50 +00:00
|
|
|
class test(Command):
|
|
|
|
|
|
|
|
user_options = []
|
|
|
|
|
|
|
|
def initialize_options(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def finalize_options(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
build_cmd = self.get_finalized_command('build')
|
|
|
|
build_cmd.run()
|
|
|
|
sys.path.insert(0, build_cmd.build_lib)
|
2008-12-29 17:24:05 +00:00
|
|
|
if sys.version_info[0] < 3:
|
2008-12-29 19:05:11 +00:00
|
|
|
sys.path.insert(0, 'tests/lib')
|
2008-12-29 17:24:05 +00:00
|
|
|
else:
|
2008-12-29 19:05:11 +00:00
|
|
|
sys.path.insert(0, 'tests/lib3')
|
2008-12-28 20:16:50 +00:00
|
|
|
import test_all
|
2016-06-16 01:28:10 +00:00
|
|
|
if not test_all.main([]):
|
|
|
|
raise DistutilsError("Tests failed")
|
2008-12-28 20:16:50 +00:00
|
|
|
|
|
|
|
|
2016-06-17 03:32:32 +00:00
|
|
|
cmdclass = {
|
|
|
|
'build_ext': build_ext,
|
|
|
|
'bdist_rpm': bdist_rpm,
|
|
|
|
'test': test,
|
|
|
|
}
|
|
|
|
if bdist_wheel:
|
|
|
|
cmdclass['bdist_wheel'] = bdist_wheel
|
|
|
|
|
|
|
|
|
2006-08-19 19:37:57 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
|
2008-12-29 23:21:43 +00:00
|
|
|
setup(
|
|
|
|
name=NAME,
|
|
|
|
version=VERSION,
|
|
|
|
description=DESCRIPTION,
|
|
|
|
long_description=LONG_DESCRIPTION,
|
|
|
|
author=AUTHOR,
|
|
|
|
author_email=AUTHOR_EMAIL,
|
|
|
|
license=LICENSE,
|
|
|
|
platforms=PLATFORMS,
|
|
|
|
url=URL,
|
|
|
|
download_url=DOWNLOAD_URL,
|
|
|
|
classifiers=CLASSIFIERS,
|
|
|
|
|
|
|
|
package_dir={'': {2: 'lib', 3: 'lib3'}[sys.version_info[0]]},
|
|
|
|
packages=['yaml'],
|
|
|
|
ext_modules=[
|
|
|
|
Extension('_yaml', ['ext/_yaml.pyx'],
|
|
|
|
'libyaml', "LibYAML bindings", LIBYAML_CHECK,
|
|
|
|
libraries=['yaml']),
|
|
|
|
],
|
|
|
|
|
|
|
|
distclass=Distribution,
|
2016-06-17 03:32:32 +00:00
|
|
|
cmdclass=cmdclass,
|
2019-02-24 06:43:32 +00:00
|
|
|
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
|
2008-12-29 23:21:43 +00:00
|
|
|
)
|