當前位置: 首頁>>代碼示例>>Python>>正文


Python _pyio.open方法代碼示例

本文整理匯總了Python中_pyio.open方法的典型用法代碼示例。如果您正苦於以下問題:Python _pyio.open方法的具體用法?Python _pyio.open怎麽用?Python _pyio.open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在_pyio的用法示例。


在下文中一共展示了_pyio.open方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testSetBufferSize

# 需要導入模塊: import _pyio [as 別名]
# 或者: from _pyio import open [as 別名]
def testSetBufferSize(self):
        # make sure that explicitly setting the buffer size doesn't cause
        # misbehaviour especially with repeated close() calls
        for s in (-1, 0, 1, 512):
            try:
                f = self.open(TESTFN, 'wb', s)
                f.write(str(s).encode("ascii"))
                f.close()
                f.close()
                f = self.open(TESTFN, 'rb', s)
                d = int(f.read().decode("ascii"))
                f.close()
                f.close()
            except IOError as msg:
                self.fail('error setting buffer size %d: %s' % (s, str(msg)))
            self.assertEqual(d, s) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:18,代碼來源:test_file.py

示例2: test_main

# 需要導入模塊: import _pyio [as 別名]
# 或者: from _pyio import open [as 別名]
def test_main():
    base_tests = (TestCRNewlines,
                  TestLFNewlines,
                  TestCRLFNewlines,
                  TestMixedNewlines)
    tests = []
    # Test the C and Python implementations.
    for test in base_tests:
        class CTest(test):
            open = io.open
        CTest.__name__ = str("C" + test.__name__)
        class PyTest(test):
            open = staticmethod(pyio.open)
        PyTest.__name__ = str("Py" + test.__name__)
        tests.append(CTest)
        tests.append(PyTest)
    support.run_unittest(*tests) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,代碼來源:test_univnewlines.py

示例3: testSetBufferSize

# 需要導入模塊: import _pyio [as 別名]
# 或者: from _pyio import open [as 別名]
def testSetBufferSize(self):
        # make sure that explicitly setting the buffer size doesn't cause
        # misbehaviour especially with repeated close() calls
        for s in (-1, 0, 1, 512):
            try:
                f = self.open(TESTFN, 'wb', s)
                f.write(str(s).encode("ascii"))
                f.close()
                f.close()
                f = self.open(TESTFN, 'rb', s)
                d = int(f.read().decode("ascii"))
                f.close()
                f.close()
            except OSError as msg:
                self.fail('error setting buffer size %d: %s' % (s, str(msg)))
            self.assertEqual(d, s) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:18,代碼來源:test_file.py

示例4: setUp

# 需要導入模塊: import _pyio [as 別名]
# 或者: from _pyio import open [as 別名]
def setUp(self):
        self.f = self.open(TESTFN, 'wb') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:4,代碼來源:test_file.py

示例5: testReadinto

# 需要導入模塊: import _pyio [as 別名]
# 或者: from _pyio import open [as 別名]
def testReadinto(self):
        # verify readinto
        self.f.write(b'12')
        self.f.close()
        a = array('b', b'x'*10)
        self.f = self.open(TESTFN, 'rb')
        n = self.f.readinto(a)
        self.assertEqual(b'12', a.tostring()[:n]) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:10,代碼來源:test_file.py

示例6: testReadinto_text

# 需要導入模塊: import _pyio [as 別名]
# 或者: from _pyio import open [as 別名]
def testReadinto_text(self):
        # verify readinto refuses text files
        a = array('b', b'x'*10)
        self.f.close()
        self.f = self.open(TESTFN, 'r')
        if hasattr(self.f, "readinto"):
            self.assertRaises(TypeError, self.f.readinto, a) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:9,代碼來源:test_file.py

示例7: testWritelinesUserList

# 需要導入模塊: import _pyio [as 別名]
# 或者: from _pyio import open [as 別名]
def testWritelinesUserList(self):
        # verify writelines with instance sequence
        l = UserList([b'1', b'2'])
        self.f.writelines(l)
        self.f.close()
        self.f = self.open(TESTFN, 'rb')
        buf = self.f.read()
        self.assertEqual(buf, b'12') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:10,代碼來源:test_file.py

示例8: testModeStrings

# 需要導入模塊: import _pyio [as 別名]
# 或者: from _pyio import open [as 別名]
def testModeStrings(self):
        # check invalid mode strings
        self.open(TESTFN, 'wb').close()
        for mode in ("", "aU", "wU+"):
            try:
                f = self.open(TESTFN, mode)
            except ValueError:
                pass
            else:
                f.close()
                self.fail('%r is an invalid file mode' % mode) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:test_file.py

示例9: testTruncateOnWindows

# 需要導入模塊: import _pyio [as 別名]
# 或者: from _pyio import open [as 別名]
def testTruncateOnWindows(self):
        # SF bug <http://www.python.org/sf/801631>
        # "file.truncate fault on windows"

        f = self.open(TESTFN, 'wb')

        try:
            f.write(b'12345678901')   # 11 bytes
            f.close()

            f = self.open(TESTFN,'rb+')
            data = f.read(5)
            if data != b'12345':
                self.fail("Read on file opened for update failed %r" % data)
            if f.tell() != 5:
                self.fail("File pos after read wrong %d" % f.tell())

            f.truncate()
            if f.tell() != 5:
                self.fail("File pos after ftruncate wrong %d" % f.tell())

            f.close()
            size = os.path.getsize(TESTFN)
            if size != 5:
                self.fail("File size after ftruncate wrong %d" % size)
        finally:
            f.close() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:29,代碼來源:test_file.py

示例10: setUp

# 需要導入模塊: import _pyio [as 別名]
# 或者: from _pyio import open [as 別名]
def setUp(self):
        data = self.DATA
        if "b" in self.WRITEMODE:
            data = data.encode("ascii")
        with self.open(support.TESTFN, self.WRITEMODE) as fp:
            fp.write(data) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:8,代碼來源:test_univnewlines.py

示例11: test_read

# 需要導入模塊: import _pyio [as 別名]
# 或者: from _pyio import open [as 別名]
def test_read(self):
        with self.open(support.TESTFN, self.READMODE) as fp:
            data = fp.read()
        self.assertEqual(data, DATA_LF)
        self.assertEqual(set(fp.newlines), set(self.NEWLINE)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:test_univnewlines.py

示例12: test_readlines

# 需要導入模塊: import _pyio [as 別名]
# 或者: from _pyio import open [as 別名]
def test_readlines(self):
        with self.open(support.TESTFN, self.READMODE) as fp:
            data = fp.readlines()
        self.assertEqual(data, DATA_SPLIT)
        self.assertEqual(set(fp.newlines), set(self.NEWLINE)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:test_univnewlines.py

示例13: test_seek

# 需要導入模塊: import _pyio [as 別名]
# 或者: from _pyio import open [as 別名]
def test_seek(self):
        with self.open(support.TESTFN, self.READMODE) as fp:
            fp.readline()
            pos = fp.tell()
            data = fp.readlines()
            self.assertEqual(data, DATA_SPLIT[1:])
            fp.seek(pos)
            data = fp.readlines()
        self.assertEqual(data, DATA_SPLIT[1:]) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:test_univnewlines.py

示例14: test_tell

# 需要導入模塊: import _pyio [as 別名]
# 或者: from _pyio import open [as 別名]
def test_tell(self):
        with self.open(support.TESTFN, self.READMODE) as fp:
            self.assertEqual(repr(fp.newlines), repr(None))
            data = fp.readline()
            pos = fp.tell()
        self.assertEqual(repr(fp.newlines), repr(self.NEWLINE)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:8,代碼來源:test_univnewlines.py

示例15: testModeStrings

# 需要導入模塊: import _pyio [as 別名]
# 或者: from _pyio import open [as 別名]
def testModeStrings(self):
        # check invalid mode strings
        for mode in ("", "aU", "wU+"):
            try:
                f = self.open(TESTFN, mode)
            except ValueError:
                pass
            else:
                f.close()
                self.fail('%r is an invalid file mode' % mode) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:12,代碼來源:test_file.py


注:本文中的_pyio.open方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。