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


Python _io.FileIO方法代码示例

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


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

示例1: testAbles

# 需要导入模块: import _io [as 别名]
# 或者: from _io import FileIO [as 别名]
def testAbles(self):
        try:
            f = _FileIO(TESTFN, "w")
            self.assertEqual(f.readable(), False)
            self.assertEqual(f.writable(), True)
            self.assertEqual(f.seekable(), True)
            f.close()

            f = _FileIO(TESTFN, "r")
            self.assertEqual(f.readable(), True)
            self.assertEqual(f.writable(), False)
            self.assertEqual(f.seekable(), True)
            f.close()

            f = _FileIO(TESTFN, "a+")
            self.assertEqual(f.readable(), True)
            self.assertEqual(f.writable(), True)
            self.assertEqual(f.seekable(), True)
            self.assertEqual(f.isatty(), False)
            f.close()
        finally:
            os.unlink(TESTFN) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_fileio.py

示例2: testAblesOnTTY

# 需要导入模块: import _io [as 别名]
# 或者: from _io import FileIO [as 别名]
def testAblesOnTTY(self):
        try:
            f = _FileIO("/dev/tty", "a")
        except EnvironmentError:
            # When run in a cron job there just aren't any
            # ttys, so skip the test.  This also handles other
            # OS'es that don't support /dev/tty.
            self.skipTest('need /dev/tty')
        else:
            self.assertEqual(f.readable(), False)
            self.assertEqual(f.writable(), True)
            if sys.platform != "darwin" and \
               'bsd' not in sys.platform and \
               not sys.platform.startswith(('sunos', 'aix')):
                # Somehow /dev/tty appears seekable on some BSDs
                self.assertEqual(f.seekable(), False)
            self.assertEqual(f.isatty(), True)
            f.close() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_fileio.py

示例3: test_surrogates

# 需要导入模块: import _io [as 别名]
# 或者: from _io import FileIO [as 别名]
def test_surrogates(self):
        # Issue #8438: try to open a filename containing surrogates.
        # It should either fail because the file doesn't exist or the filename
        # can't be represented using the filesystem encoding, but not because
        # of a LookupError for the error handler "surrogateescape".
        filename = u'\udc80.txt'
        try:
            with _FileIO(filename):
                pass
        except (UnicodeEncodeError, IOError):
            pass
        # Spawn a separate Python process with a different "file system
        # default encoding", to exercise this further.
        env = dict(os.environ)
        env[b'LC_CTYPE'] = b'C'
        _, out = run_python('-c', 'import _io; _io.FileIO(%r)' % filename, env=env)
        if ('UnicodeEncodeError' not in out and not
                ( ('IOError: [Errno 2] No such file or directory' in out) or
                  ('IOError: [Errno 22] Invalid argument' in out) ) ):
            self.fail('Bad output: %r' % out) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:22,代码来源:test_fileio.py

示例4: testAblesOnTTY

# 需要导入模块: import _io [as 别名]
# 或者: from _io import FileIO [as 别名]
def testAblesOnTTY(self):
        try:
            f = _FileIO("/dev/tty", "a")
        except EnvironmentError:
            # When run in a cron job there just aren't any
            # ttys, so skip the test.  This also handles other
            # OS'es that don't support /dev/tty.
            self.skipTest('need /dev/tty')
        else:
            self.assertEqual(f.readable(), False)
            self.assertEqual(f.writable(), True)
            if sys.platform != "darwin" and \
               'bsd' not in sys.platform and \
               not sys.platform.startswith('sunos'):
                # Somehow /dev/tty appears seekable on some BSDs
                self.assertEqual(f.seekable(), False)
            self.assertEqual(f.isatty(), True)
            f.close() 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:20,代码来源:test_fileio.py

示例5: setUp

# 需要导入模块: import _io [as 别名]
# 或者: from _io import FileIO [as 别名]
def setUp(self):
        self.f = _FileIO(TESTFN, 'w') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_fileio.py

示例6: testReadinto

# 需要导入模块: import _io [as 别名]
# 或者: from _io import FileIO [as 别名]
def testReadinto(self):
        # verify readinto
        self.f.write(b"\x01\x02")
        self.f.close()
        a = array(b'b', b'x'*10)
        self.f = _FileIO(TESTFN, 'r')
        n = self.f.readinto(a)
        self.assertEqual(array(b'b', [1, 2]), a[:n]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_fileio.py

示例7: testWritelinesList

# 需要导入模块: import _io [as 别名]
# 或者: from _io import FileIO [as 别名]
def testWritelinesList(self):
        l = [b'123', b'456']
        self.f.writelines(l)
        self.f.close()
        self.f = _FileIO(TESTFN, 'rb')
        buf = self.f.read()
        self.assertEqual(buf, b'123456') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_fileio.py

示例8: testWritelinesUserList

# 需要导入模块: import _io [as 别名]
# 或者: from _io import FileIO [as 别名]
def testWritelinesUserList(self):
        l = UserList([b'123', b'456'])
        self.f.writelines(l)
        self.f.close()
        self.f = _FileIO(TESTFN, 'rb')
        buf = self.f.read()
        self.assertEqual(buf, b'123456') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_fileio.py

示例9: test_none_args

# 需要导入模块: import _io [as 别名]
# 或者: from _io import FileIO [as 别名]
def test_none_args(self):
        self.f.write(b"hi\nbye\nabc")
        self.f.close()
        self.f = _FileIO(TESTFN, 'r')
        self.assertEqual(self.f.read(None), b"hi\nbye\nabc")
        self.f.seek(0)
        self.assertEqual(self.f.readline(None), b"hi\n")
        self.assertEqual(self.f.readlines(None), [b"bye\n", b"abc"]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_fileio.py

示例10: testOpendir

# 需要导入模块: import _io [as 别名]
# 或者: from _io import FileIO [as 别名]
def testOpendir(self):
        # Issue 3703: opening a directory should fill the errno
        # Windows always returns "[Errno 13]: Permission denied
        # Unix calls dircheck() and returns "[Errno 21]: Is a directory"
        try:
            _FileIO('.', 'r')
        except IOError as e:
            self.assertNotEqual(e.errno, 0)
            self.assertEqual(e.filename, ".")
        else:
            self.fail("Should have raised IOError") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_fileio.py

示例11: testOpenDirFD

# 需要导入模块: import _io [as 别名]
# 或者: from _io import FileIO [as 别名]
def testOpenDirFD(self):
        fd = os.open('.', os.O_RDONLY)
        with self.assertRaises(IOError) as cm:
            _FileIO(fd, 'r')
        os.close(fd)
        self.assertEqual(cm.exception.errno, errno.EISDIR)

    #A set of functions testing that we get expected behaviour if someone has
    #manually closed the internal file descriptor.  First, a decorator: 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_fileio.py

示例12: ReopenForRead

# 需要导入模块: import _io [as 别名]
# 或者: from _io import FileIO [as 别名]
def ReopenForRead(self):
        try:
            self.f.close()
        except IOError:
            pass
        self.f = _FileIO(TESTFN, 'r')
        os.close(self.f.fileno())
        return self.f 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_fileio.py

示例13: testModeStrings

# 需要导入模块: import _io [as 别名]
# 或者: from _io import FileIO [as 别名]
def testModeStrings(self):
        # test that the mode attribute is correct for various mode strings
        # given as init args
        try:
            for modes in [('w', 'wb'), ('wb', 'wb'), ('wb+', 'rb+'),
                          ('w+b', 'rb+'), ('a', 'ab'), ('ab', 'ab'),
                          ('ab+', 'ab+'), ('a+b', 'ab+'), ('r', 'rb'),
                          ('rb', 'rb'), ('rb+', 'rb+'), ('r+b', 'rb+')]:
                # read modes are last so that TESTFN will exist first
                with _FileIO(TESTFN, modes[0]) as f:
                    self.assertEqual(f.mode, modes[1])
        finally:
            if os.path.exists(TESTFN):
                os.unlink(TESTFN) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:16,代码来源:test_fileio.py

示例14: testUnicodeOpen

# 需要导入模块: import _io [as 别名]
# 或者: from _io import FileIO [as 别名]
def testUnicodeOpen(self):
        # verify repr works for unicode too
        f = _FileIO(str(TESTFN), "w")
        f.close()
        os.unlink(TESTFN) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_fileio.py

示例15: testBytesOpen

# 需要导入模块: import _io [as 别名]
# 或者: from _io import FileIO [as 别名]
def testBytesOpen(self):
        # Opening a bytes filename
        try:
            fn = TESTFN.encode("ascii")
        except UnicodeEncodeError:
            self.skipTest('could not encode %r to ascii' % TESTFN)
        f = _FileIO(fn, "w")
        try:
            f.write(b"abc")
            f.close()
            with open(TESTFN, "rb") as f:
                self.assertEqual(f.read(), b"abc")
        finally:
            os.unlink(TESTFN) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:16,代码来源:test_fileio.py


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