當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。