当前位置: 首页>>代码示例>>Python>>正文


Python six.text_type方法代码示例

本文整理汇总了Python中pip._vendor.six.text_type方法的典型用法代码示例。如果您正苦于以下问题:Python six.text_type方法的具体用法?Python six.text_type怎么用?Python six.text_type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pip._vendor.six的用法示例。


在下文中一共展示了six.text_type方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: HTMLInputStream

# 需要导入模块: from pip._vendor import six [as 别名]
# 或者: from pip._vendor.six import text_type [as 别名]
def HTMLInputStream(source, **kwargs):
    # Work around Python bug #20007: read(0) closes the connection.
    # http://bugs.python.org/issue20007
    if (isinstance(source, http_client.HTTPResponse) or
        # Also check for addinfourl wrapping HTTPResponse
        (isinstance(source, urllib.response.addbase) and
         isinstance(source.fp, http_client.HTTPResponse))):
        isUnicode = False
    elif hasattr(source, "read"):
        isUnicode = isinstance(source.read(0), text_type)
    else:
        isUnicode = isinstance(source, text_type)

    if isUnicode:
        encodings = [x for x in kwargs if x.endswith("_encoding")]
        if encodings:
            raise TypeError("Cannot set an encoding with a unicode input, set %r" % encodings)

        return HTMLUnicodeInputStream(source, **kwargs)
    else:
        return HTMLBinaryInputStream(source, **kwargs) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:23,代码来源:_inputstream.py

示例2: elementInScope

# 需要导入模块: from pip._vendor import six [as 别名]
# 或者: from pip._vendor.six import text_type [as 别名]
def elementInScope(self, target, variant=None):

        # If we pass a node in we match that. if we pass a string
        # match any node with that name
        exactNode = hasattr(target, "nameTuple")
        if not exactNode:
            if isinstance(target, text_type):
                target = (namespaces["html"], target)
            assert isinstance(target, tuple)

        listElements, invert = listElementsMap[variant]

        for node in reversed(self.openElements):
            if exactNode and node == target:
                return True
            elif not exactNode and node.nameTuple == target:
                return True
            elif (invert ^ (node.nameTuple in listElements)):
                return False

        assert False  # We should never reach this point 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:23,代码来源:base.py

示例3: _select_progress_class

# 需要导入模块: from pip._vendor import six [as 别名]
# 或者: from pip._vendor.six import text_type [as 别名]
def _select_progress_class(preferred, fallback):
    encoding = getattr(preferred.file, "encoding", None)

    # If we don't know what encoding this file is in, then we'll just assume
    # that it doesn't support unicode and use the ASCII bar.
    if not encoding:
        return fallback

    # Collect all of the possible characters we want to use with the preferred
    # bar.
    characters = [
        getattr(preferred, "empty_fill", six.text_type()),
        getattr(preferred, "fill", six.text_type()),
    ]
    characters += list(getattr(preferred, "phases", []))

    # Try to decode the characters we're using for the bar using the encoding
    # of the given file, if this works then we'll assume that we can use the
    # fancier bar and if not we'll fall back to the plaintext bar.
    try:
        six.text_type().join(characters).encode(encoding)
    except UnicodeEncodeError:
        return fallback
    else:
        return preferred 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:27,代码来源:ui.py

示例4: setup_py

# 需要导入模块: from pip._vendor import six [as 别名]
# 或者: from pip._vendor.six import text_type [as 别名]
def setup_py(self):
        assert self.source_dir, "No source dir for %s" % self
        try:
            import setuptools  # noqa
        except ImportError:
            if get_installed_version('setuptools') is None:
                add_msg = "Please install setuptools."
            else:
                add_msg = traceback.format_exc()
            # Setuptools is not available
            raise InstallationError(
                "Could not import setuptools which is required to "
                "install from a source distribution.\n%s" % add_msg
            )

        setup_py = os.path.join(self.setup_py_dir, 'setup.py')

        # Python2 __file__ should not be unicode
        if six.PY2 and isinstance(setup_py, six.text_type):
            setup_py = setup_py.encode(sys.getfilesystemencoding())

        return setup_py 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:req_install.py

示例5: HTMLInputStream

# 需要导入模块: from pip._vendor import six [as 别名]
# 或者: from pip._vendor.six import text_type [as 别名]
def HTMLInputStream(source, encoding=None, parseMeta=True, chardet=True):
    if isinstance(source, http_client.HTTPResponse):
        # Work around Python bug #20007: read(0) closes the connection.
        # http://bugs.python.org/issue20007
        isUnicode = False
    elif hasattr(source, "read"):
        isUnicode = isinstance(source.read(0), text_type)
    else:
        isUnicode = isinstance(source, text_type)

    if isUnicode:
        if encoding is not None:
            raise TypeError("Cannot explicitly set an encoding with a unicode string")

        return HTMLUnicodeInputStream(source)
    else:
        return HTMLBinaryInputStream(source, encoding, parseMeta, chardet) 
开发者ID:jpush,项目名称:jbox,代码行数:19,代码来源:inputstream.py

示例6: format_for_json

# 需要导入模块: from pip._vendor import six [as 别名]
# 或者: from pip._vendor.six import text_type [as 别名]
def format_for_json(packages, options):
    data = []
    for dist in packages:
        info = {
            'name': dist.project_name,
            'version': six.text_type(dist.version),
        }
        if options.outdated:
            info['latest_version'] = six.text_type(dist.latest_version)
            info['latest_filetype'] = dist.latest_filetype
        data.append(info)
    return json.dumps(data) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:14,代码来源:list.py

示例7: native_str

# 需要导入模块: from pip._vendor import six [as 别名]
# 或者: from pip._vendor.six import text_type [as 别名]
def native_str(s, replace=False):
        # Replace is ignored -- unicode to UTF-8 can't fail
        if isinstance(s, text_type):
            return s.encode('utf-8')
        return s 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:__init__.py

示例8: ensure_str

# 需要导入模块: from pip._vendor import six [as 别名]
# 或者: from pip._vendor.six import text_type [as 别名]
def ensure_str(s):
    if s is None:
        return None
    elif isinstance(s, text_type):
        return s
    else:
        return s.decode("ascii", "strict") 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:etree_lxml.py

示例9: encode

# 需要导入模块: from pip._vendor import six [as 别名]
# 或者: from pip._vendor.six import text_type [as 别名]
def encode(self, string):
        assert(isinstance(string, text_type))
        if self.encoding:
            return string.encode(self.encoding, "htmlentityreplace")
        else:
            return string 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:serializer.py

示例10: encodeStrict

# 需要导入模块: from pip._vendor import six [as 别名]
# 或者: from pip._vendor.six import text_type [as 别名]
def encodeStrict(self, string):
        assert(isinstance(string, text_type))
        if self.encoding:
            return string.encode(self.encoding, "strict")
        else:
            return string 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:serializer.py

示例11: __init__

# 需要导入模块: from pip._vendor import six [as 别名]
# 或者: from pip._vendor.six import text_type [as 别名]
def __init__(self, data):
        if not all(isinstance(x, text_type) for x in data.keys()):
            raise TypeError("All keys must be strings")

        self._data = data
        self._keys = sorted(data.keys())
        self._cachestr = ""
        self._cachepoints = (0, len(data)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:py.py


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