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


Python StringIO.StringIO方法代码示例

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


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

示例1: test_str

# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import StringIO [as 别名]
def test_str(self):
        """
        Test __str__ method, for full coverage and check that all modules have required attributes.
        """

        for mod in self.allmods:
            with RedirectStreams(stdout=self.dev_null):
                obj = mod()
            original_stdout = sys.stdout
            # sys.stdout = StringIO.StringIO()
            sys.stdout = StringIO()
            # call __str__ method
            result = obj.__str__()
            # examine what was printed
            contents = sys.stdout.getvalue()
            self.assertEqual(type(contents), type(''))
            sys.stdout.close()
            # it also returns a string, which is not necessary
            self.assertEqual(type(result), type(''))
            # put stdout back
            sys.stdout = original_stdout 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:23,代码来源:test_BackgroundSources.py

示例2: _render

# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import StringIO [as 别名]
def _render(self, mode='human', close=False):
    if close:
      return

    outfile = StringIO.StringIO() if mode == 'ansi' else sys.stdout

    row, col = self.s // self.ncol, self.s % self.ncol
    desc = self.desc.tolist()
    desc[row][col] = utils.colorize(desc[row][col], "red", highlight=True)

    outfile.write("\n".join("".join(row) for row in desc)+"\n")
    if self.lastaction is not None:
      outfile.write("  ({})\n".format(self.get_action_meanings()[self.lastaction]))
    else:
      outfile.write("\n")

    return outfile 
开发者ID:carpedm20,项目名称:deep-rl-tensorflow,代码行数:19,代码来源:corridor.py

示例3: execute_code

# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import StringIO [as 别名]
def execute_code(cls, code):
        """ Executes supplied code as pure python and returns a list of stdout, stderr

        Args:
            code (string): Python code to execute

        Results:
            (list): stdout, stderr of executed python code

        Raises:
            ExecutionError when supplied python is incorrect

        Examples:
            >>> execute_code('print "foobar"')
            'foobar'
        """

        output = StringIO.StringIO()
        err = StringIO.StringIO()

        sys.stdout = output
        sys.stderr = err

        try:
            # pylint: disable=exec-used
            exec(code)
        # If the code is invalid, just skip the block - any actual code errors
        # will be raised properly
        except TypeError:
            pass
        sys.stdout = sys.__stdout__
        sys.stderr = sys.__stderr__

        results = list()
        results.append(output.getvalue())
        results.append(err.getvalue())
        results = ''.join(results)

        return results 
开发者ID:jpsenior,项目名称:sphinx-execute-code,代码行数:41,代码来源:__init__.py

示例4: __init__

# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import StringIO [as 别名]
def __init__(self):
        self.boundary = None
        self.current_chunk = StringIO.StringIO()

    # Return: mjpeg chunk if found
    #         None: in the middle of the chunk 
开发者ID:kennethjiang,项目名称:OctoPrint-Anywhere,代码行数:8,代码来源:mjpeg_stream.py

示例5: test_stdout_encoding_None

# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import StringIO [as 别名]
def test_stdout_encoding_None():
    instance = PdbTest()
    instance.stdout = BytesIO()
    instance.stdout.encoding = None

    instance.ensure_file_can_write_unicode(instance.stdout)

    try:
        import cStringIO
    except ImportError:
        pass
    else:
        instance.stdout = cStringIO.StringIO()
        instance.ensure_file_can_write_unicode(instance.stdout) 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:16,代码来源:test_pdb.py

示例6: test_py2_ensure_file_can_write_unicode

# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import StringIO [as 别名]
def test_py2_ensure_file_can_write_unicode():
    import StringIO

    stdout = StringIO.StringIO()
    stdout.encoding = 'ascii'

    p = Pdb(Config=DefaultConfig, stdout=stdout)

    assert p.stdout.stream is stdout

    p.stdout.write(u"test äöüß")
    stdout.seek(0)
    assert stdout.read().decode('utf-8') == u"test äöüß" 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:15,代码来源:test_pdb.py

示例7: __init__

# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import StringIO [as 别名]
def __init__(self, code, msg, headers, data, url=None):
        StringIO.StringIO.__init__(self, data)
        self.code, self.msg, self.headers, self.url = code, msg, headers, url 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_urllib2.py

示例8: http_open

# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import StringIO [as 别名]
def http_open(self, req):
        import mimetools, copy
        from StringIO import StringIO
        self.requests.append(copy.deepcopy(req))
        if self._count == 0:
            self._count = self._count + 1
            name = httplib.responses[self.code]
            msg = mimetools.Message(StringIO(self.headers))
            return self.parent.error(
                "http", req, MockFile(), self.code, name, msg)
        else:
            self.req = req
            msg = mimetools.Message(StringIO("\r\n\r\n"))
            return MockResponse(200, "OK", msg, "", req.get_full_url()) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:16,代码来源:test_urllib2.py

示例9: read_ascii_string

# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import StringIO [as 别名]
def read_ascii_string(data):
    """Read geometry from a :py:class:`str` containing data in the STL *ASCII* format.

    This is just a wrapper around :py:func:`read_ascii_file` that first wraps
    the provided string in a :py:class:`StringIO.StringIO` object.
    """
    from StringIO import StringIO
    return read_ascii_file(StringIO(data)) 
开发者ID:ladybug-tools,项目名称:butterfly,代码行数:10,代码来源:__init__.py

示例10: read_binary_string

# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import StringIO [as 别名]
def read_binary_string(data):
    """Read geometry from a :py:class:`str` containing data in the STL *binary* format.

    This is just a wrapper around :py:func:`read_binary_file` that first wraps
    the provided string in a :py:class:`StringIO.StringIO` object.
    """
    from StringIO import StringIO
    return read_binary_file(StringIO(data)) 
开发者ID:ladybug-tools,项目名称:butterfly,代码行数:10,代码来源:__init__.py

示例11: http_open

# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import StringIO [as 别名]
def http_open(self, req):
        import mimetools, httplib, copy
        from StringIO import StringIO
        self.requests.append(copy.deepcopy(req))
        if self._count == 0:
            self._count = self._count + 1
            name = httplib.responses[self.code]
            msg = mimetools.Message(StringIO(self.headers))
            return self.parent.error(
                "http", req, MockFile(), self.code, name, msg)
        else:
            self.req = req
            msg = mimetools.Message(StringIO("\r\n\r\n"))
            return MockResponse(200, "OK", msg, "", req.get_full_url()) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:16,代码来源:test_urllib2.py

示例12: run_request

# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import StringIO [as 别名]
def run_request(request):
    pid = subprocess.Popen(run_command, shell=True, stdin=subprocess.PIPE,
                           stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    results = pid.communicate(input=request.encode())
    tmp_file = StringIO(results[0].decode())
    results = read_rpc_messages(tmp_file)
    parsed_results = []
    for result in results:
        if "method" in result:
            continue
        parsed_results.append(result['result'])
    errcode = pid.poll()
    return errcode, parsed_results 
开发者ID:hansec,项目名称:fortran-language-server,代码行数:15,代码来源:test_server.py

示例13: getFileType

# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import StringIO [as 别名]
def getFileType(self):
        try:
            from StringIO import StringIO
        except ImportError:
            raise SkipTest("StringIO.StringIO is not available.")
        else:
            return StringIO 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:test_wsgi.py

示例14: png_client

# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import StringIO [as 别名]
def png_client(images,info={},port=10000,host='localhost',compress_level=0,resize=(1.0,1.0)):
    if len(images.shape) == 2:
        images = [images]
    # Create a TCP/IP socket
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    # Connect the socket to the port where the server is listening
    server_address = (host, port)
    sock.connect(server_address)
    try:
        for A in images:
            im = Image.fromarray(256.0*A).convert('RGB')
            if resize != (1.0,1.0) and resize is not None:
                if not type(resize) == tuple:
                    resize = (resize,resize)
                im = im.resize((int(resize[0]*im.size[0]), int(resize[1]*im.size[1])), PIL.Image.ANTIALIAS)
            output = StringIO.StringIO()
            meta = PngImagePlugin.PngInfo()
            reserved = ('interlace', 'gamma', 'dpi', 'transparency', 'aspect')
            for k,v in _iteritems(info):
                if k in reserved:
                    continue
                meta.add_text(str(k), str(v), 0)
            im.save(output, format="PNG", pnginfo=meta, compress_level=compress_level)
            message = output.getvalue()
            output.close()
            sock.sendall(message)
    finally:
        sock.close() 
开发者ID:jahuth,项目名称:convis,代码行数:31,代码来源:png.py

示例15: __init__

# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import StringIO [as 别名]
def __init__(self, port = 10000, size=(0,0)):
        from PIL import Image, ImageTk
        self.port = port
        self.size = size
        self.buffer = StringIO()
        self.image = Image.fromarray(np.zeros((200,200))).convert('RGB')
        self.closed = False
        self.dirty = False
        self.refresh_rate = 10
        self.last_buffer = []
        self.debug = False
        thread.start_new_thread(self.wait_for_connection,tuple()) 
开发者ID:jahuth,项目名称:convis,代码行数:14,代码来源:png.py


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