当前位置: 首页>>代码示例>>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;未经允许,请勿转载。