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


Python six.StringIO方法代码示例

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


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

示例1: quiet

# 需要导入模块: from setuptools.extern import six [as 别名]
# 或者: from setuptools.extern.six import StringIO [as 别名]
def quiet():
    """
    Redirect stdout/stderr to StringIO objects to prevent console output from
    distutils commands.
    """

    old_stdout = sys.stdout
    old_stderr = sys.stderr
    new_stdout = sys.stdout = six.StringIO()
    new_stderr = sys.stderr = six.StringIO()
    try:
        yield new_stdout, new_stderr
    finally:
        new_stdout.seek(0)
        new_stderr.seek(0)
        sys.stdout = old_stdout
        sys.stderr = old_stderr 
开发者ID:pypa,项目名称:setuptools,代码行数:19,代码来源:contexts.py

示例2: local_open

# 需要导入模块: from setuptools.extern import six [as 别名]
# 或者: from setuptools.extern.six import StringIO [as 别名]
def local_open(url):
    """Read a local path, with special support for directories"""
    scheme, server, path, param, query, frag = urllib.parse.urlparse(url)
    filename = urllib.request.url2pathname(path)
    if os.path.isfile(filename):
        return urllib.request.urlopen(url)
    elif path.endswith('/') and os.path.isdir(filename):
        files = []
        for f in os.listdir(filename):
            filepath = os.path.join(filename, f)
            if f == 'index.html':
                with open(filepath, 'r') as fp:
                    body = fp.read()
                break
            elif os.path.isdir(filepath):
                f += '/'
            files.append('<a href="{name}">{name}</a>'.format(name=f))
        else:
            tmpl = ("<html><head><title>{url}</title>"
                "</head><body>{files}</body></html>")
            body = tmpl.format(url=url, files='\n'.join(files))
        status, message = 200, "OK"
    else:
        status, message, body = 404, "Path not found", "Not found"

    headers = {'content-type': 'text/html'}
    body_stream = six.StringIO(body)
    return urllib.error.HTTPError(url, status, message, headers, body_stream) 
开发者ID:jpush,项目名称:jbox,代码行数:30,代码来源:package_index.py

示例3: extract_wininst_cfg

# 需要导入模块: from setuptools.extern import six [as 别名]
# 或者: from setuptools.extern.six import StringIO [as 别名]
def extract_wininst_cfg(dist_filename):
    """Extract configuration data from a bdist_wininst .exe

    Returns a configparser.RawConfigParser, or None
    """
    f = open(dist_filename, 'rb')
    try:
        endrec = zipfile._EndRecData(f)
        if endrec is None:
            return None

        prepended = (endrec[9] - endrec[5]) - endrec[6]
        if prepended < 12:  # no wininst data here
            return None
        f.seek(prepended - 12)

        tag, cfglen, bmlen = struct.unpack("<iii", f.read(12))
        if tag not in (0x1234567A, 0x1234567B):
            return None  # not a valid tag

        f.seek(prepended - (12 + cfglen))
        cfg = configparser.RawConfigParser(
            {'version': '', 'target_version': ''})
        try:
            part = f.read(cfglen)
            # Read up to the first null byte.
            config = part.split(b'\0', 1)[0]
            # Now the config is in bytes, but for RawConfigParser, it should
            #  be text, so decode it.
            config = config.decode(sys.getfilesystemencoding())
            cfg.readfp(six.StringIO(config))
        except configparser.Error:
            return None
        if not cfg.has_section('metadata') or not cfg.has_section('Setup'):
            return None
        return cfg

    finally:
        f.close() 
开发者ID:jpush,项目名称:jbox,代码行数:41,代码来源:easy_install.py

示例4: write_requirements

# 需要导入模块: from setuptools.extern import six [as 别名]
# 或者: from setuptools.extern.six import StringIO [as 别名]
def write_requirements(cmd, basename, filename):
    dist = cmd.distribution
    data = six.StringIO()
    _write_requirements(data, dist.install_requires)
    extras_require = dist.extras_require or {}
    for extra in sorted(extras_require):
        data.write('\n[{extra}]\n'.format(**vars()))
        _write_requirements(data, extras_require[extra])
    cmd.write_or_delete_file("requirements", filename, data.getvalue()) 
开发者ID:jpush,项目名称:jbox,代码行数:11,代码来源:egg_info.py

示例5: write_setup_requirements

# 需要导入模块: from setuptools.extern import six [as 别名]
# 或者: from setuptools.extern.six import StringIO [as 别名]
def write_setup_requirements(cmd, basename, filename):
    data = StringIO()
    _write_requirements(data, cmd.distribution.setup_requires)
    cmd.write_or_delete_file("setup-requirements", filename, data.getvalue()) 
开发者ID:jpush,项目名称:jbox,代码行数:6,代码来源:egg_info.py

示例6: extract_wininst_cfg

# 需要导入模块: from setuptools.extern import six [as 别名]
# 或者: from setuptools.extern.six import StringIO [as 别名]
def extract_wininst_cfg(dist_filename):
    """Extract configuration data from a bdist_wininst .exe

    Returns a configparser.RawConfigParser, or None
    """
    f = open(dist_filename, 'rb')
    try:
        endrec = zipfile._EndRecData(f)
        if endrec is None:
            return None

        prepended = (endrec[9] - endrec[5]) - endrec[6]
        if prepended < 12:  # no wininst data here
            return None
        f.seek(prepended - 12)

        tag, cfglen, bmlen = struct.unpack("<iii", f.read(12))
        if tag not in (0x1234567A, 0x1234567B):
            return None  # not a valid tag

        f.seek(prepended - (12 + cfglen))
        init = {'version': '', 'target_version': ''}
        cfg = configparser.RawConfigParser(init)
        try:
            part = f.read(cfglen)
            # Read up to the first null byte.
            config = part.split(b'\0', 1)[0]
            # Now the config is in bytes, but for RawConfigParser, it should
            #  be text, so decode it.
            config = config.decode(sys.getfilesystemencoding())
            cfg.readfp(six.StringIO(config))
        except configparser.Error:
            return None
        if not cfg.has_section('metadata') or not cfg.has_section('Setup'):
            return None
        return cfg

    finally:
        f.close() 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:41,代码来源:easy_install.py

示例7: local_open

# 需要导入模块: from setuptools.extern import six [as 别名]
# 或者: from setuptools.extern.six import StringIO [as 别名]
def local_open(url):
    """Read a local path, with special support for directories"""
    scheme, server, path, param, query, frag = urllib.parse.urlparse(url)
    filename = urllib.request.url2pathname(path)
    if os.path.isfile(filename):
        return urllib.request.urlopen(url)
    elif path.endswith('/') and os.path.isdir(filename):
        files = []
        for f in os.listdir(filename):
            filepath = os.path.join(filename, f)
            if f == 'index.html':
                with open(filepath, 'r') as fp:
                    body = fp.read()
                break
            elif os.path.isdir(filepath):
                f += '/'
            files.append('<a href="{name}">{name}</a>'.format(name=f))
        else:
            tmpl = (
                "<html><head><title>{url}</title>"
                "</head><body>{files}</body></html>")
            body = tmpl.format(url=url, files='\n'.join(files))
        status, message = 200, "OK"
    else:
        status, message, body = 404, "Path not found", "Not found"

    headers = {'content-type': 'text/html'}
    body_stream = six.StringIO(body)
    return urllib.error.HTTPError(url, status, message, headers, body_stream) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:31,代码来源:package_index.py

示例8: write_setup_requirements

# 需要导入模块: from setuptools.extern import six [as 别名]
# 或者: from setuptools.extern.six import StringIO [as 别名]
def write_setup_requirements(cmd, basename, filename):
    data = io.StringIO()
    _write_requirements(data, cmd.distribution.setup_requires)
    cmd.write_or_delete_file("setup-requirements", filename, data.getvalue()) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:6,代码来源:egg_info.py


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