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