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


Python StringIO.StringIO方法代码示例

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


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

示例1: testRunnerRegistersResult

# 需要导入模块: from cStringIO import StringIO [as 别名]
# 或者: from cStringIO.StringIO import StringIO [as 别名]
def testRunnerRegistersResult(self):
        class Test(unittest2.TestCase):
            def testFoo(self):
                pass
        originalRegisterResult = unittest2.runner.registerResult
        def cleanup():
            unittest2.runner.registerResult = originalRegisterResult
        self.addCleanup(cleanup)
        
        result = unittest2.TestResult()
        runner = unittest2.TextTestRunner(stream=StringIO())
        # Use our result object
        runner._makeResult = lambda: result
        
        self.wasRegistered = 0
        def fakeRegisterResult(thisResult):
            self.wasRegistered += 1
            self.assertEqual(thisResult, result)
        unittest2.runner.registerResult = fakeRegisterResult
        
        runner.run(unittest2.TestSuite())
        self.assertEqual(self.wasRegistered, 1) 
开发者ID:Lithium876,项目名称:ConTroll_Remote_Access_Trojan,代码行数:24,代码来源:test_runner.py

示例2: test_startTestRun_stopTestRun_called

# 需要导入模块: from cStringIO import StringIO [as 别名]
# 或者: from cStringIO.StringIO import StringIO [as 别名]
def test_startTestRun_stopTestRun_called(self):
        class LoggingTextResult(LoggingResult):
            separator2 = ''
            def printErrors(self):
                pass

        class LoggingRunner(unittest2.TextTestRunner):
            def __init__(self, events):
                super(LoggingRunner, self).__init__(StringIO())
                self._events = events

            def _makeResult(self):
                return LoggingTextResult(self._events)

        events = []
        runner = LoggingRunner(events)
        runner.run(unittest2.TestSuite())
        expected = ['startTestRun', 'stopTestRun']
        self.assertEqual(events, expected) 
开发者ID:Lithium876,项目名称:ConTroll_Remote_Access_Trojan,代码行数:21,代码来源:test_runner.py

示例3: loadUiType

# 需要导入模块: from cStringIO import StringIO [as 别名]
# 或者: from cStringIO.StringIO import StringIO [as 别名]
def loadUiType(uiFile):
    '''
    Pyside lacks the "loadUiType" command, so we have to convert the ui file to py code in-memory first
    and then execute it in a special frame to retrieve the form_class.
    '''
    parsed = xml.parse(uiFile)
    widget_class = parsed.find('widget').get('class')
    form_class = parsed.find('class').text

    with open(uiFile, 'r') as f:
        o = StringIO()
        frame = {}
        
        pysideuic.compileUi(f, o, indent=0)
        pyc = compile(o.getvalue(), '<string>', 'exec')
        exec pyc in frame
        
        #Fetch the base_class and form class based on their type in the xml from designer
        form_class = frame['Ui_%s' % form_class]
        base_class = eval('QtGui.%s' % widget_class)
    return form_class, base_class 
开发者ID:patcorwin,项目名称:fossil,代码行数:23,代码来源:ui.py

示例4: __iter__

# 需要导入模块: from cStringIO import StringIO [as 别名]
# 或者: from cStringIO.StringIO import StringIO [as 别名]
def __iter__(self):
        environ = self.environ

        self.path = environ.get('PATH_INFO', '')
        self.client_address = environ.get('REMOTE_ADDR','-'), \
                              environ.get('REMOTE_PORT','-')
        self.command = environ.get('REQUEST_METHOD', '-')

        from cStringIO import StringIO
        self.wfile = StringIO() # for capturing error

        try:
            path = self.translate_path(self.path)
            etag = '"%s"' % os.path.getmtime(path)
            client_etag = environ.get('HTTP_IF_NONE_MATCH')
            self.send_header('ETag', etag)
            if etag == client_etag:
                self.send_response(304, "Not Modified")
                self.start_response(self.status, self.headers)
                raise StopIteration
        except OSError:
            pass # Probably a 404

        f = self.send_head()
        self.start_response(self.status, self.headers)

        if f:
            block_size = 16 * 1024
            while True:
                buf = f.read(block_size)
                if not buf:
                    break
                yield buf
            f.close()
        else:
            value = self.wfile.getvalue()
            yield value 
开发者ID:joxeankoret,项目名称:nightmare,代码行数:39,代码来源:httpserver.py

示例5: __init__

# 需要导入模块: from cStringIO import StringIO [as 别名]
# 或者: from cStringIO.StringIO import StringIO [as 别名]
def __init__(self, app):
        self.app = app
        self.format = '%s - - [%s] "%s %s %s" - %s'
    
        from BaseHTTPServer import BaseHTTPRequestHandler
        import StringIO
        f = StringIO.StringIO()
        
        class FakeSocket:
            def makefile(self, *a):
                return f
        
        # take log_date_time_string method from BaseHTTPRequestHandler
        self.log_date_time_string = BaseHTTPRequestHandler(FakeSocket(), None, None).log_date_time_string 
开发者ID:joxeankoret,项目名称:nightmare,代码行数:16,代码来源:httpserver.py

示例6: getFileType

# 需要导入模块: from cStringIO import StringIO [as 别名]
# 或者: from cStringIO.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

示例7: load

# 需要导入模块: from cStringIO import StringIO [as 别名]
# 或者: from cStringIO.StringIO import StringIO [as 别名]
def load(self, key, silent=False):
    """Load from location ``key``

    :param key: location
    :type key: str
    :param silent: whether load fails silently
    :type silent: bool
    :return: loaded object
    :rtype: object
    """
    # Load an object from s3 bucket
    try:
      #buffer = sio.StringIO()
      buffer = sio()
      load_key = key
      if self.aws_prefix:
        load_key = '/'.join([self.aws_prefix, key])
      # Define a Callback function and print out based on verbose level?
      # This can hang if load_key is not found?
      #self.bucket.download_fileobj(load_key, buffer)
      # Other solution with TransferConfig
      #self.bucket.download_fileobj(load_key, buffer, Config=self.transferConfig)
      resp = self.s3.Object(bucket_name=self.bucket_name, key=load_key)
      # Try to access 'content_length' to generate an 404 error if not found
      if resp.content_length == 0:
        return None
      resp.download_fileobj(buffer)
      # buffer has been filled, offset is at the end, seek to beginning for unpickling
      buffer.seek(0)
      if self.pickling:
        obj = pickle.load(buffer)
      else:
        obj = buffer
      if self.verbose > 3:
        print("[{}: log] Loaded file: {}".format(self.pp, load_key))
      return obj
    except Exception as e:
      if self.verbose > 1 and not silent:
        err_msg = "[{}: error ({}: {})] Could not load object with key: {}"
        print(err_msg.format(self.pp, type(e), e, load_key)) 
开发者ID:ColumbiaDVMM,项目名称:ColumbiaImageSearch,代码行数:42,代码来源:s3.py

示例8: testBufferAndFailfast

# 需要导入模块: from cStringIO import StringIO [as 别名]
# 或者: from cStringIO.StringIO import StringIO [as 别名]
def testBufferAndFailfast(self):
        class Test(unittest2.TestCase):
            def testFoo(self):
                pass
        result = unittest2.TestResult()
        runner = unittest2.TextTestRunner(stream=StringIO(), failfast=True,
                                           buffer=True)
        # Use our result object
        runner._makeResult = lambda: result
        runner.run(Test('testFoo'))
        
        self.assertTrue(result.failfast)
        self.assertTrue(result.buffer) 
开发者ID:Lithium876,项目名称:ConTroll_Remote_Access_Trojan,代码行数:15,代码来源:test_runner.py

示例9: test_works_with_result_without_startTestRun_stopTestRun

# 需要导入模块: from cStringIO import StringIO [as 别名]
# 或者: from cStringIO.StringIO import StringIO [as 别名]
def test_works_with_result_without_startTestRun_stopTestRun(self):
        class OldTextResult(OldTestResult):
            def __init__(self, *_):
                super(OldTextResult, self).__init__()
            separator2 = ''
            def printErrors(self):
                pass

        runner = unittest2.TextTestRunner(stream=StringIO(), 
                                          resultclass=OldTextResult)
        runner.run(unittest2.TestSuite()) 
开发者ID:Lithium876,项目名称:ConTroll_Remote_Access_Trojan,代码行数:13,代码来源:test_runner.py

示例10: test_pickle_unpickle

# 需要导入模块: from cStringIO import StringIO [as 别名]
# 或者: from cStringIO.StringIO import StringIO [as 别名]
def test_pickle_unpickle(self):
        # Issue #7197: a TextTestRunner should be (un)pickleable. This is
        # required by test_multiprocessing under Windows (in verbose mode).
        import StringIO
        # cStringIO objects are not pickleable, but StringIO objects are.
        stream = StringIO.StringIO("foo")
        runner = unittest2.TextTestRunner(stream)
        for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
            s = pickle.dumps(runner, protocol=protocol)
            obj = pickle.loads(s)
            # StringIO objects never compare equal, a cheap test instead.
            self.assertEqual(obj.stream.getvalue(), stream.getvalue()) 
开发者ID:Lithium876,项目名称:ConTroll_Remote_Access_Trojan,代码行数:14,代码来源:test_runner.py

示例11: __enter__

# 需要导入模块: from cStringIO import StringIO [as 别名]
# 或者: from cStringIO.StringIO import StringIO [as 别名]
def __enter__(self):
        self.tempOutput = StringIO.StringIO()
        self.origOutput = sys.stdout
        self.origErr = sys.stderr
        
        sys.stdout = self.tempOutput
        sys.stderr = self.tempOutput
        
        return self.tempOutput 
开发者ID:patcorwin,项目名称:fossil,代码行数:11,代码来源:ui.py


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