本文整理汇总了Python中salt.ext.six.text_type函数的典型用法代码示例。如果您正苦于以下问题:Python text_type函数的具体用法?Python text_type怎么用?Python text_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了text_type函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _ordered
def _ordered(obj):
if isinstance(obj, (list, tuple)):
return sorted(_ordered(x) for x in obj)
elif isinstance(obj, dict):
return dict((six.text_type(k) if isinstance(k, six.string_types) else k, _ordered(v)) for k, v in obj.items())
elif isinstance(obj, six.string_types):
return six.text_type(obj)
return obj
示例2: _tag_doc
def _tag_doc(tags):
taglist = []
if tags is not None:
for k, v in six.iteritems(tags):
if six.text_type(k).startswith('__'):
continue
taglist.append({'Key': six.text_type(k), 'Value': six.text_type(v)})
return taglist
示例3: output
def output(grains):
'''
Output the grains in a clean way
'''
colors = salt.utils.get_colors(__opts__.get('color'))
encoding = grains['locale_info']['defaultencoding']
if encoding == 'unknown':
encoding = 'utf-8' # let's hope for the best
ret = u''
for id_, minion in grains.items():
ret += u'{0}{1}{2}:\n'.format(colors['GREEN'], id_.decode(encoding), colors['ENDC'])
for key in sorted(minion):
ret += u' {0}{1}{2}:'.format(colors['CYAN'], key.decode(encoding), colors['ENDC'])
if key == 'cpu_flags':
ret += colors['LIGHT_GREEN']
for val in minion[key]:
ret += u' {0}'.format(val.decode(encoding))
ret += '{0}\n'.format(colors['ENDC'])
elif key == 'pythonversion':
ret += ' {0}'.format(colors['LIGHT_GREEN'])
for val in minion[key]:
ret += u'{0}.'.format(six.text_type(val))
ret = ret[:-1]
ret += '{0}\n'.format(colors['ENDC'])
elif isinstance(minion[key], list):
for val in minion[key]:
ret += u'\n {0}{1}{2}'.format(colors['LIGHT_GREEN'], val.decode(encoding), colors['ENDC'])
ret += '\n'
else:
ret += u' {0}{1}{2}\n'.format(colors['LIGHT_GREEN'], minion[key].decode(encoding), colors['ENDC'])
return ret
示例4: symlink_list
def symlink_list(self, load):
'''
Return a list of symlinked files and dirs
'''
if 'env' in load:
salt.utils.warn_until(
'Oxygen',
'Parameter \'env\' has been detected in the argument list. This '
'parameter is no longer used and has been replaced by \'saltenv\' '
'as of Salt 2016.11.0. This warning will be removed in Salt Oxygen.'
)
load.pop('env')
ret = {}
if 'saltenv' not in load:
return {}
if not isinstance(load['saltenv'], six.string_types):
load['saltenv'] = six.text_type(load['saltenv'])
for fsb in self._gen_back(load.pop('fsbackend', None)):
symlstr = '{0}.symlink_list'.format(fsb)
if symlstr in self.servers:
ret = self.servers[symlstr](load)
# upgrade all set elements to a common encoding
ret = dict([
(salt.utils.locales.sdecode(x), salt.utils.locales.sdecode(y)) for x, y in ret.items()
])
# some *fs do not handle prefix. Ensure it is filtered
prefix = load.get('prefix', '').strip('/')
if prefix != '':
ret = dict([
(x, y) for x, y in six.iteritems(ret) if x.startswith(prefix)
])
return ret
示例5: __file_hash_and_stat
def __file_hash_and_stat(self, load):
'''
Common code for hashing and stating files
'''
if 'env' in load:
salt.utils.warn_until(
'Oxygen',
'Parameter \'env\' has been detected in the argument list. '
'This parameter is no longer used and has been replaced by '
'\'saltenv\' as of Salt 2016.11.0. This warning will be removed '
'in Salt Oxygen.'
)
load.pop('env')
if 'path' not in load or 'saltenv' not in load:
return '', None
if not isinstance(load['saltenv'], six.string_types):
load['saltenv'] = six.text_type(load['saltenv'])
fnd = self.find_file(salt.utils.locales.sdecode(load['path']),
load['saltenv'])
if not fnd.get('back'):
return '', None
stat_result = fnd.get('stat', None)
fstr = '{0}.file_hash'.format(fnd['back'])
if fstr in self.servers:
return self.servers[fstr](load, fnd), stat_result
return '', None
示例6: dir_list
def dir_list(self, load):
'''
List all directories in the given environment
'''
if 'env' in load:
salt.utils.warn_until(
'Oxygen',
'Parameter \'env\' has been detected in the argument list. This '
'parameter is no longer used and has been replaced by \'saltenv\' '
'as of Salt 2016.11.0. This warning will be removed in Salt Oxygen.'
)
load.pop('env')
ret = set()
if 'saltenv' not in load:
return []
if not isinstance(load['saltenv'], six.string_types):
load['saltenv'] = six.text_type(load['saltenv'])
for fsb in self._gen_back(load.pop('fsbackend', None)):
fstr = '{0}.dir_list'.format(fsb)
if fstr in self.servers:
ret.update(self.servers[fstr](load))
# upgrade all set elements to a common encoding
ret = [salt.utils.locales.sdecode(f) for f in ret]
# some *fs do not handle prefix. Ensure it is filtered
prefix = load.get('prefix', '').strip('/')
if prefix != '':
ret = [f for f in ret if f.startswith(prefix)]
return sorted(ret)
示例7: _rename
def _rename(src, dst): # pylint: disable=E0102
if not isinstance(src, six.text_type):
src = six.text_type(src, sys.getfilesystemencoding())
if not isinstance(dst, six.text_type):
dst = six.text_type(dst, sys.getfilesystemencoding())
if _rename_atomic(src, dst):
return True
retry = 0
rval = False
while not rval and retry < 100:
rval = _MoveFileEx(src, dst, _MOVEFILE_REPLACE_EXISTING |
_MOVEFILE_WRITE_THROUGH)
if not rval:
time.sleep(0.001)
retry += 1
return rval
示例8: serve_file
def serve_file(self, load):
'''
Serve up a chunk of a file
'''
ret = {'data': '',
'dest': ''}
if 'env' in load:
salt.utils.warn_until(
'Oxygen',
'Parameter \'env\' has been detected in the argument list. This '
'parameter is no longer used and has been replaced by \'saltenv\' '
'as of Salt 2016.11.0. This warning will be removed in Salt Oxygen.'
)
load.pop('env')
if 'path' not in load or 'loc' not in load or 'saltenv' not in load:
return ret
if not isinstance(load['saltenv'], six.string_types):
load['saltenv'] = six.text_type(load['saltenv'])
fnd = self.find_file(load['path'], load['saltenv'])
if not fnd.get('back'):
return ret
fstr = '{0}.serve_file'.format(fnd['back'])
if fstr in self.servers:
return self.servers[fstr](load, fnd)
return ret
示例9: returner
def returner(load):
'''
Return data to a postgres server
'''
# salt guarantees that there will be 'fun', 'jid', 'return' and 'id' but not
# 'success'
success = 'Unknown'
if 'success' in load:
success = load['success']
conn = _get_conn()
if conn is None:
return None
cur = conn.cursor()
sql = '''INSERT INTO salt_returns
(fun, jid, return, id, success)
VALUES (%s, %s, %s, %s, %s)'''
cur.execute(
sql, (
load['fun'],
load['jid'],
json.dumps(six.text_type(str(load['return']), 'utf-8', 'replace')),
load['id'],
success
)
)
_close_conn(conn)
示例10: condition_input
def condition_input(args, kwargs):
'''
Return a single arg structure for the publisher to safely use
'''
ret = []
for arg in args:
if (six.PY3 and isinstance(arg, six.integer_types) and salt.utils.jid.is_jid(six.text_type(arg))) or \
(six.PY2 and isinstance(arg, long)): # pylint: disable=incompatible-py3-code
ret.append(six.text_type(arg))
else:
ret.append(arg)
if isinstance(kwargs, dict) and kwargs:
kw_ = {'__kwarg__': True}
for key, val in six.iteritems(kwargs):
kw_[key] = val
return ret + [kw_]
return ret
示例11: _localectl_set
def _localectl_set(locale=''):
'''
Use systemd's localectl command to set the LANG locale parameter, making
sure not to trample on other params that have been set.
'''
locale_params = _parse_dbus_locale() if dbus is not None else _localectl_status().get('system_locale', {})
locale_params['LANG'] = six.text_type(locale)
args = ' '.join(['{0}="{1}"'.format(k, v) for k, v in six.iteritems(locale_params) if v is not None])
return not __salt__['cmd.retcode']('localectl set-locale {0}'.format(args), python_shell=False)
示例12: __assert_not_empty
def __assert_not_empty(returned):
'''
Test if a returned value is not empty
'''
result = "Pass"
try:
assert (returned), "value is empty"
except AssertionError as err:
result = "Fail: " + six.text_type(err)
return result
示例13: __assert_less_equal
def __assert_less_equal(expected, returned):
'''
Test if a value is less than or equal to the returned value
'''
result = "Pass"
try:
assert (expected <= returned), "{0} not False".format(returned)
except AssertionError as err:
result = "Fail: " + six.text_type(err)
return result
示例14: __assert_greater
def __assert_greater(expected, returned):
'''
Test if a value is greater than the returned value
'''
result = "Pass"
try:
assert (expected > returned), "{0} not False".format(returned)
except AssertionError as err:
result = "Fail: " + six.text_type(err)
return result
示例15: __assert_true
def __assert_true(returned):
'''
Test if an boolean is True
'''
result = "Pass"
try:
assert (returned is True), "{0} not True".format(returned)
except AssertionError as err:
result = "Fail: " + six.text_type(err)
return result