• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python six.text_type函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中salt.ext.six.text_type函数的典型用法代码示例。如果您正苦于以下问题:Python text_type函数的具体用法?Python text_type怎么用?Python text_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了text_type函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:HowardMei,项目名称:saltstack,代码行数:8,代码来源:boto3.py


示例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
开发者ID:mitodl,项目名称:salt-extensions,代码行数:8,代码来源:boto_rds.py


示例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
开发者ID:DavideyLee,项目名称:salt,代码行数:32,代码来源:grains.py


示例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
开发者ID:bryson,项目名称:salt,代码行数:34,代码来源:__init__.py


示例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
开发者ID:bryson,项目名称:salt,代码行数:28,代码来源:__init__.py


示例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)
开发者ID:bryson,项目名称:salt,代码行数:30,代码来源:__init__.py


示例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
开发者ID:DavideyLee,项目名称:salt,代码行数:16,代码来源:atomicfile.py


示例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
开发者ID:bryson,项目名称:salt,代码行数:28,代码来源:__init__.py


示例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)
开发者ID:DaveQB,项目名称:salt,代码行数:27,代码来源:postgres_local_cache.py


示例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
开发者ID:napalm-automation,项目名称:napalm-salt,代码行数:17,代码来源:args.py


示例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)
开发者ID:rallytime,项目名称:salt-jenkins,代码行数:9,代码来源:localemod.py


示例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
开发者ID:wcannon,项目名称:salt-check,代码行数:10,代码来源:saltcheck.py


示例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
开发者ID:wcannon,项目名称:salt-check,代码行数:10,代码来源:saltcheck.py


示例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
开发者ID:wcannon,项目名称:salt-check,代码行数:10,代码来源:saltcheck.py


示例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
开发者ID:wcannon,项目名称:salt-check,代码行数:10,代码来源:saltcheck.py


示例16: _mbcs_to_unicode

def _mbcs_to_unicode(instr):
    '''
    Converts from current users character encoding to unicode.
    When instr has a value of None, the return value of the function
    will also be None.
    '''
    if instr is None or isinstance(instr, six.text_type):
        return instr
    else:
        return six.text_type(instr, 'mbcs')
开发者ID:bryson,项目名称:salt,代码行数:10,代码来源:reg.py


示例17: yaml_dquote

def yaml_dquote(text):
    '''
    Make text into a double-quoted YAML string with correct escaping
    for special characters.  Includes the opening and closing double
    quote characters.
    '''
    with io.StringIO() as ostream:
        yemitter = yaml.emitter.Emitter(ostream)
        yemitter.write_double_quoted(six.text_type(text))
        return ostream.getvalue()
开发者ID:qzchenwl,项目名称:saltstack-verify,代码行数:10,代码来源:yamlencoding.py


示例18: clear_lock

def clear_lock(remote=None):
    '''
    Clear update.lk

    ``remote`` can either be a dictionary containing repo configuration
    information, or a pattern. If the latter, then remotes for which the URL
    matches the pattern will be locked.
    '''
    def _do_clear_lock(repo):
        def _add_error(errlist, repo, exc):
            msg = ('Unable to remove update lock for {0} ({1}): {2} '
                   .format(repo['url'], repo['lockfile'], exc))
            log.debug(msg)
            errlist.append(msg)
        success = []
        failed = []
        if os.path.exists(repo['lockfile']):
            try:
                os.remove(repo['lockfile'])
            except OSError as exc:
                if exc.errno == errno.EISDIR:
                    # Somehow this path is a directory. Should never happen
                    # unless some wiseguy manually creates a directory at this
                    # path, but just in case, handle it.
                    try:
                        shutil.rmtree(repo['lockfile'])
                    except OSError as exc:
                        _add_error(failed, repo, exc)
                else:
                    _add_error(failed, repo, exc)
            else:
                msg = 'Removed lock for {0}'.format(repo['url'])
                log.debug(msg)
                success.append(msg)
        return success, failed

    if isinstance(remote, dict):
        return _do_clear_lock(remote)

    cleared = []
    errors = []
    for repo in init():
        if remote:
            try:
                if remote not in repo['url']:
                    continue
            except TypeError:
                # remote was non-string, try again
                if six.text_type(remote) not in repo['url']:
                    continue
        success, failed = _do_clear_lock(repo)
        cleared.extend(success)
        errors.extend(failed)
    return cleared, errors
开发者ID:bryson,项目名称:salt,代码行数:54,代码来源:svnfs.py


示例19: split_input

def split_input(val, mapper=None):
    '''
    Take an input value and split it into a list, returning the resulting list
    '''
    if mapper is None:
        mapper = lambda x: x
    if isinstance(val, list):
        return list(map(mapper, val))
    try:
        return list(map(mapper, [x.strip() for x in val.split(',')]))
    except AttributeError:
        return list(map(mapper, [x.strip() for x in six.text_type(val).split(',')]))
开发者ID:napalm-automation,项目名称:napalm-salt,代码行数:12,代码来源:args.py


示例20: __assert_not_equal

 def __assert_not_equal(expected, returned, assert_print_result=True):
     '''
     Test if two objects are not equal
     '''
     result = "Pass"
     try:
         if assert_print_result:
             assert (expected != returned), "{0} is equal to {1}".format(expected, returned)
         else:
             assert (expected != returned), "Result is equal"
     except AssertionError as err:
         result = "Fail: " + six.text_type(err)
     return result
开发者ID:wcannon,项目名称:salt-check,代码行数:13,代码来源:saltcheck.py



注:本文中的salt.ext.six.text_type函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python moves.map函数代码示例发布时间:2022-05-27
下一篇:
Python six.itervalues函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap