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