From 608c18040e98e522c528a7e35a8a8bf0c70f768b Mon Sep 17 00:00:00 2001 From: "Domme, Sergej" Date: Thu, 10 Sep 2015 14:04:07 +0200 Subject: [PATCH] Additional use six library and import some future stuff --- build.py | 1 + setup.cfg | 2 +- src/main/python/yamlreader/__init__.py | 3 ++- src/main/python/yamlreader/yamlreader.py | 9 ++++++--- src/unittest/python/yamlreader_tests.py | 2 ++ 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/build.py b/build.py index 5223a40..df29ca5 100644 --- a/build.py +++ b/build.py @@ -22,6 +22,7 @@ @init def set_properties(project): project.depends_on("PyYAML") + project.depends_on("six") project.set_property('distutils_console_scripts', ['yamlreader=yamlreader:__main']) diff --git a/setup.cfg b/setup.cfg index fefc07f..c2b88f3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,4 +1,4 @@ [bdist_rpm] -requires = python >= 2.6 PyYAML python-setuptools +requires = python >= 2.6 PyYAML python-setuptools python-six release = ${rpm_release} diff --git a/src/main/python/yamlreader/__init__.py b/src/main/python/yamlreader/__init__.py index 9ff494c..cb5def8 100644 --- a/src/main/python/yamlreader/__init__.py +++ b/src/main/python/yamlreader/__init__.py @@ -1,6 +1,7 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- +from __future__ import print_function, absolute_import, unicode_literals, division + from .yamlreader import data_merge, yaml_load, YamlReaderError __all__ = ['data_merge', 'yaml_load', 'YamlReaderError'] diff --git a/src/main/python/yamlreader/yamlreader.py b/src/main/python/yamlreader/yamlreader.py index 02a9d7f..be5b326 100644 --- a/src/main/python/yamlreader/yamlreader.py +++ b/src/main/python/yamlreader/yamlreader.py @@ -1,3 +1,5 @@ +from __future__ import print_function, absolute_import, unicode_literals, division + __all__ = ["YamlReaderError", "yaml_load"] __version__ = "3.0.1" @@ -5,6 +7,7 @@ import glob import os import logging +import six class NoDefault(object): @@ -29,7 +32,7 @@ def data_merge(a, b): # ## debug output # sys.stderr.write("DEBUG: %s to %s\n" %(b,a)) try: - if a is None or isinstance(a, (str, unicode, int, long, float)): + if a is None or isinstance(a, (six.string_types, float, six.integer_types)): # border case for first run or if a is a primitive a = b elif isinstance(a, list): @@ -137,8 +140,8 @@ def __main(): if not args: parser.error("Need at least one argument") try: - print safe_dump(yaml_load(args, defaultdata={}), - indent=4, default_flow_style=False, canonical=False) + print(safe_dump(yaml_load(args, defaultdata={}), + indent=4, default_flow_style=False, canonical=False)) except Exception as e: parser.error(e) diff --git a/src/unittest/python/yamlreader_tests.py b/src/unittest/python/yamlreader_tests.py index 618751d..12182e2 100644 --- a/src/unittest/python/yamlreader_tests.py +++ b/src/unittest/python/yamlreader_tests.py @@ -1,3 +1,5 @@ +from __future__ import print_function, absolute_import, unicode_literals, division + import unittest import logging from yamlreader import data_merge, yaml_load, YamlReaderError