mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #45205 from terminalmage/py3-serializers
[PY3] Add unicode_literals to sdb and serializers
This commit is contained in:
commit
d595c7af36
19 changed files with 49 additions and 45 deletions
|
@ -46,7 +46,7 @@ it must be specified in the URI:
|
|||
'''
|
||||
|
||||
# import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import salt.cache
|
||||
|
||||
__func_alias__ = {
|
||||
|
|
|
@ -35,11 +35,11 @@ The module can be configured via sdb in the minion config:
|
|||
Module Documentation
|
||||
====================
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import logging
|
||||
import copy
|
||||
import logging
|
||||
|
||||
# Import third party libs
|
||||
try:
|
||||
|
|
|
@ -27,7 +27,7 @@ requires very little. For example:
|
|||
The ``driver`` refers to the Consul module, all other options are optional.
|
||||
For option details see: https://python-consul.readthedocs.io/en/latest/#consul
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
from salt.exceptions import CommandExecutionError
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ Additional contributions to build true map-reduce functionality into this module
|
|||
would be welcome.
|
||||
'''
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Python libraries
|
||||
import logging
|
||||
|
|
|
@ -57,10 +57,10 @@ in the environment:
|
|||
..snip
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# import python libs
|
||||
from os import environ
|
||||
# Import Python libs
|
||||
import os
|
||||
|
||||
__func_alias__ = {
|
||||
'set_': 'set'
|
||||
|
@ -79,7 +79,7 @@ def set_(key, value, profile=None):
|
|||
Set a key/value pair
|
||||
'''
|
||||
# pylint: disable=unused-argument
|
||||
return environ.setdefault(key, value)
|
||||
return os.environ.setdefault(key, value)
|
||||
|
||||
|
||||
def get(key, profile=None):
|
||||
|
@ -87,4 +87,4 @@ def get(key, profile=None):
|
|||
Get a value
|
||||
'''
|
||||
# pylint: disable=unused-argument
|
||||
return environ.get(key)
|
||||
return os.environ.get(key)
|
||||
|
|
|
@ -33,7 +33,7 @@ is hosting the etcd database and ``etcd.port`` refers to the port on that host.
|
|||
'''
|
||||
|
||||
# import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
|
||||
try:
|
||||
|
|
|
@ -44,7 +44,7 @@ https://pypi.python.org/pypi/keyring
|
|||
|
||||
.. versionadded:: 2014.1.4
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# import python libs
|
||||
import logging
|
||||
|
|
|
@ -30,7 +30,7 @@ and ``mymemcached`` refers to the name that will appear in the URI:
|
|||
password: sdb://mymemcached/mykey
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# import python libs
|
||||
import logging
|
||||
|
|
|
@ -66,7 +66,7 @@ For instance:
|
|||
'''
|
||||
|
||||
# import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
|
||||
import salt.loader
|
||||
|
|
|
@ -42,7 +42,7 @@ create the table(s) and get and set values.
|
|||
get_query: "SELECT d FROM advanced WHERE a=:key"
|
||||
set_query: "INSERT OR REPLACE INTO advanced (a, d) VALUES (:key, :value)"
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import logging
|
||||
|
|
|
@ -29,12 +29,13 @@ configuration.
|
|||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
|
||||
# Import Salt libs
|
||||
import salt.utils.json
|
||||
import salt.utils.http as http
|
||||
from salt.ext import six
|
||||
from salt.exceptions import SaltConfigurationError
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -68,7 +69,10 @@ def get(key, service=None, profile=None): # pylint: disable=W0613
|
|||
decrypted = result.get('body')
|
||||
|
||||
if not decrypted:
|
||||
log.warning('tism.get sdb decryption request failed with error {0}'.format(result.get('error', 'unknown')))
|
||||
return "ERROR"+str(result.get('status', 'unknown'))
|
||||
log.warning(
|
||||
'tism.get sdb decryption request failed with error %s',
|
||||
result.get('error', 'unknown')
|
||||
)
|
||||
return 'ERROR' + six.text_type(result.get('status', 'unknown'))
|
||||
|
||||
return decrypted
|
||||
|
|
|
@ -41,7 +41,7 @@ The above URI is analogous to running the following vault command:
|
|||
'''
|
||||
|
||||
# import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
import salt.exceptions
|
||||
|
||||
|
@ -64,16 +64,16 @@ def set_(key, value, profile=None):
|
|||
url = 'v1/{0}'.format(path)
|
||||
data = {key: value}
|
||||
response = __utils__['vault.make_request'](
|
||||
'POST',
|
||||
url,
|
||||
profile,
|
||||
json=data
|
||||
)
|
||||
'POST',
|
||||
url,
|
||||
profile,
|
||||
json=data)
|
||||
|
||||
if response.status_code != 204:
|
||||
response.raise_for_status()
|
||||
return True
|
||||
except Exception as e:
|
||||
log.error('Failed to write secret! {0}: {1}'.format(type(e).__name__, e))
|
||||
log.error('Failed to write secret! %s: %s', type(e).__name__, e)
|
||||
raise salt.exceptions.CommandExecutionError(e)
|
||||
|
||||
|
||||
|
@ -94,5 +94,5 @@ def get(key, profile=None):
|
|||
|
||||
return data[key]
|
||||
except Exception as e:
|
||||
log.error('Failed to read secret! {0}: {1}'.format(type(e).__name__, e))
|
||||
log.error('Failed to read secret! %s: %s', type(e).__name__, e)
|
||||
raise salt.exceptions.CommandExecutionError(e)
|
||||
|
|
|
@ -40,7 +40,7 @@ GPG-encrypted data using the :py:mod:`GPG renderer <salt.renderers.gpg>`.
|
|||
'''
|
||||
|
||||
# import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
|
||||
import salt.exceptions
|
||||
|
@ -96,9 +96,9 @@ def _get_values(profile=None):
|
|||
ret = salt.utils.dictupdate.merge(
|
||||
ret, contents, **profile.get('merge', {}))
|
||||
except IOError:
|
||||
log.error("File not found '{0}'".format(fname))
|
||||
except TypeError:
|
||||
log.error("Error deserializing sdb file '{0}'".format(fname))
|
||||
log.error("File '%s' not found ", fname)
|
||||
except TypeError as exc:
|
||||
log.error("Error deserializing sdb file '%s': %s", fname, exc)
|
||||
return ret
|
||||
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
'''
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
from salt.exceptions import SaltException, SaltRenderError
|
||||
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt Libs
|
||||
from salt.ext import six
|
||||
|
@ -90,10 +90,10 @@ def _read_dict(configparser, dictionary):
|
|||
Cribbed from python3's ConfigParser.read_dict function.
|
||||
'''
|
||||
for section, keys in dictionary.items():
|
||||
section = str(section)
|
||||
section = six.text_type(section)
|
||||
configparser.add_section(section)
|
||||
for key, value in keys.items():
|
||||
key = configparser.optionxform(str(key))
|
||||
key = configparser.optionxform(six.text_type(key))
|
||||
if value is not None:
|
||||
value = str(value)
|
||||
value = six.text_type(value)
|
||||
configparser.set(section, key, value)
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import copy
|
||||
import logging
|
||||
from copy import copy
|
||||
|
||||
# Import Salt Libs
|
||||
from salt.log import setup_console_logger
|
||||
|
@ -87,7 +87,7 @@ else: # msgpack.version < 0.2.0
|
|||
return dict(data)
|
||||
elif isinstance(obj, (list, tuple)):
|
||||
return [_encoder(value) for value in obj]
|
||||
return copy(obj)
|
||||
return copy.copy(obj)
|
||||
|
||||
def _decoder(obj):
|
||||
return obj
|
||||
|
|
|
@ -103,10 +103,10 @@
|
|||
# pylint: disable=too-few-public-methods,too-many-public-methods
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
import logging
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import copy
|
||||
import datetime
|
||||
from copy import copy
|
||||
import logging
|
||||
|
||||
|
||||
# Import Salt Libs
|
||||
|
@ -270,7 +270,7 @@ class Loader(BaseLoader): # pylint: disable=W0232
|
|||
except:
|
||||
raise ConstructorError('unable to build reset')
|
||||
|
||||
node = copy(node)
|
||||
node = copy.copy(node)
|
||||
node.tag = tag
|
||||
obj = self.construct_object(node, deep)
|
||||
if obj is None:
|
||||
|
@ -287,7 +287,7 @@ class Loader(BaseLoader): # pylint: disable=W0232
|
|||
except:
|
||||
raise ConstructorError('unable to build reset')
|
||||
|
||||
node = copy(node)
|
||||
node = copy.copy(node)
|
||||
node.tag = tag
|
||||
|
||||
return self.construct_object(node, deep)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
'''
|
||||
Test case for env sdb module
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import os
|
||||
import textwrap
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ Test case for the YAML SDB module
|
|||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.unit import skipIf, TestCase
|
||||
|
|
Loading…
Add table
Reference in a new issue