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


Python sys.std方法代码示例

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


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

示例1: __call__

# 需要导入模块: import sys [as 别名]
# 或者: from sys import std [as 别名]
def __call__(self, string):
            # the special argument "-" means sys.std{in,out}
            if string == '-':
                if 'r' in self._mode:
                    return sys.stdin
                elif 'w' in self._mode:
                    return sys.stdout
                else:
                    msg = _('argument "-" with mode %r') % self._mode
                    raise ValueError(msg)

            # all other arguments are used as file names
            try:
                return open(string, self._mode, self._bufsize, self._encoding, self._errors)
            except OSError as e:
                message = _("can't open '%s': %s")
                raise ArgumentTypeError(message % (string, e)) 
开发者ID:nojanath,项目名称:SublimeKSP,代码行数:19,代码来源:ksp_compiler.py

示例2: get_stream_enc

# 需要导入模块: import sys [as 别名]
# 或者: from sys import std [as 别名]
def get_stream_enc(stream, default=None):
    """Return the given stream's encoding or a default.

    There are cases where ``sys.std*`` might not actually be a stream, so
    check for the encoding attribute prior to returning it, and return
    a default if it doesn't exist or evaluates as False. ``default``
    is None if not provided.
    """
    if not hasattr(stream, 'encoding') or not stream.encoding:
        return default
    else:
        return stream.encoding

# Less conservative replacement for sys.getdefaultencoding, that will try
# to match the environment.
# Defined here as central function, so if we find better choices, we
# won't need to make changes all over IPython. 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:19,代码来源:encoding.py

示例3: patch_sys

# 需要导入模块: import sys [as 别名]
# 或者: from sys import std [as 别名]
def patch_sys(stdin=True, stdout=True, stderr=True):
    """Patch sys.std[in,out,err] to use a cooperative IO via a threadpool.

    This is relatively dangerous and can have unintended consequences such as hanging
    the process or `misinterpreting control keys`_ when ``input`` and ``raw_input``
    are used.

    This method does nothing on Python 3. The Python 3 interpreter wants to flush
    the TextIOWrapper objects that make up stderr/stdout at shutdown time, but
    using a threadpool at that time leads to a hang.

    .. _`misinterpreting control keys`: https://github.com/gevent/gevent/issues/274
    """
    # test__issue6.py demonstrates the hang if these lines are removed;
    # strangely enough that test passes even without monkey-patching sys
    if PY3:
        return

    if stdin:
        _patch_sys_std('stdin')
    if stdout:
        _patch_sys_std('stdout')
    if stderr:
        _patch_sys_std('stderr') 
开发者ID:leancloud,项目名称:satori,代码行数:26,代码来源:monkey.py

示例4: get_dropbox_client

# 需要导入模块: import sys [as 别名]
# 或者: from sys import std [as 别名]
def get_dropbox_client(username, setup=True, stdin=None, stdout=None):
    """
	checks wether a dropbox.dropbox.Dropbox is available for username.
	If it is, it is returned.
	Otherwise, if setup is True, a command-line setup is shown.
	The setup uses stdin and stout, both defaulting to the sys.std*.
	If no client was found and setup is False, None will be returned.
	"""
    if stdout is None:
        stdout = sys.stdout
    if stdin is None:
        stdin = sys.stdin
    data = load_dropbox_data(username)
    if data is None:
        stdout.write("\n")
        if not setup:
            return None
        dropbox_setup(username, stdin, stdout)
        data = load_dropbox_data(username)
    token = data["access_token"]
    dbclient = dropbox.dropbox.Dropbox(token)
    return dbclient 
开发者ID:ywangd,项目名称:stash,代码行数:24,代码来源:dbutils.py

示例5: test_patching_std_streams

# 需要导入模块: import sys [as 别名]
# 或者: from sys import std [as 别名]
def test_patching_std_streams(self):
        """
        Test if std streams are correctly redirected to the web-console
        """
        time.sleep(1)
        self.stdin.send_keys('n')
        self.send_btn.click()
        time.sleep(1)
        self.assertIn('Enter something:', self.stdout_tag.text)
        self.stdin.send_keys('spam')
        self.send_btn.click()
        time.sleep(1)
        self.stdin.send_keys('n')
        self.send_btn.click()
        time.sleep(1)
        self.assertIn('You have entered: spam', self.stdout_tag.text) 
开发者ID:romanvm,项目名称:python-web-pdb,代码行数:18,代码来源:tests.py

示例6: __call__

# 需要导入模块: import sys [as 别名]
# 或者: from sys import std [as 别名]
def __call__(self, string):
        # the special argument "-" means sys.std{in,out}
        if string == '-':
            if 'r' in self._mode:
                return sys.stdin
            elif 'w' in self._mode:
                return sys.stdout
            else:
                msg = 'argument "-" with mode %r' % self._mode
                raise ValueError(msg)

        # all other arguments are used as file names
        try:
            return open(string,
                        self._mode,
                        self._bufsize,
                        self._encoding,
                        self._errors,
                        newline=self._newline)
        except OSError as e:
            message = "can't open '%s': %s"
            raise argparse.ArgumentTypeError(message % (string, e)) 
开发者ID:madhat2r,项目名称:plaid2text,代码行数:24,代码来源:plaid2text.py

示例7: setUp

# 需要导入模块: import sys [as 别名]
# 或者: from sys import std [as 别名]
def setUp(self):
        super().setUp()
        self.patcher = MonkeyPatcher()
        self.addCleanup(self.patcher.restore)
        # Patch sys.std* and self.std*. Use TextIOWrapper to provide an
        # identical API to the "real" stdin, stdout, and stderr objects.
        self._addStream("stdin", self._wrapStream(self._buf_in))
        self._addStream("stdout", self._wrapStream(self._buf_out))
        self._addStream("stderr", self._wrapStream(self._buf_err))
        self.patcher.patch() 
开发者ID:maas,项目名称:maas,代码行数:12,代码来源:fixtures.py

示例8: __call__

# 需要导入模块: import sys [as 别名]
# 或者: from sys import std [as 别名]
def __call__(self, string):
        from argparse import ArgumentTypeError
        # the special argument "-" means sys.std{in,out}
        if string == '-':
            if 'r' in self._mode:
                cfp = ConfFileProxy("<stdin>", "r", stream=sys.stdin, is_file=False)
                if self._action == "load":
                    try:
                        d = cfp.data
                        del d
                    except ConfParserException as e:
                        raise ArgumentTypeError("failed to parse <stdin>: {}".format(e))
                return cfp
            elif 'w' in self._mode:
                return ConfFileProxy("<stdout>", "w", stream=sys.stdout, is_file=False)
            else:
                raise ValueError('argument "-" with mode {}'.format(self._mode))
        if self._accept_dir and os.path.isdir(string):
            return ConfDirProxy(string, self._mode, parse_profile=self._parse_profile)
        if self._action == "none":
            return ConfFileProxy(string, self._mode, parse_profile=self._parse_profile)
        else:
            try:
                # Another possible option is using:  seekable()  but that only works ONCE the stream is open
                if os.path.isfile(string):
                    encoding = detect_by_bom(string)
                    stream = open(string, self._mode, encoding=encoding)
                    cfp = ConfFileProxy(string, self._mode, stream=stream,
                                        parse_profile=self._parse_profile, is_file=True)
                else:
                    # Could be an explicit link to /dev/stdin; or /dev/fd/63; a bash <(cmd) input
                    # Assume UTF-8 here because that's the default encoding expected by Splunk
                    stream = open(string, self._mode, encoding="utf-8")
                    cfp = ConfFileProxy(string, self._mode, stream=stream,
                                        parse_profile=self._parse_profile, is_file=False)
                if self._action == "load":
                    # Force file to be parsed by accessing the 'data' property
                    d = cfp.data
                    del d
                return cfp
            except IOError as e:
                message = "can't open '%s': %s"
                debug_traceback()
                raise ArgumentTypeError(message % (string, e))
            except ConfParserException as e:
                debug_traceback()
                raise ArgumentTypeError("failed to parse '%s': %s" % (string, e))
            except TypeError as e:
                debug_traceback()
                raise ArgumentTypeError("Parser config error '%s': %s" % (string, e)) 
开发者ID:Kintyre,项目名称:ksconf,代码行数:52,代码来源:__init__.py


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