本文整理汇总了Python中asyncore.file_wrapper方法的典型用法代码示例。如果您正苦于以下问题:Python asyncore.file_wrapper方法的具体用法?Python asyncore.file_wrapper怎么用?Python asyncore.file_wrapper使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类asyncore
的用法示例。
在下文中一共展示了asyncore.file_wrapper方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_recv
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import file_wrapper [as 别名]
def test_recv(self):
fd = os.open(TESTFN, os.O_RDONLY)
w = asyncore.file_wrapper(fd)
os.close(fd)
self.assertNotEqual(w.fd, fd)
self.assertNotEqual(w.fileno(), fd)
self.assertEqual(w.recv(13), "It's not dead")
self.assertEqual(w.read(6), ", it's")
w.close()
self.assertRaises(OSError, w.read, 1)
示例2: test_send
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import file_wrapper [as 别名]
def test_send(self):
d1 = "Come again?"
d2 = "I want to buy some cheese."
fd = os.open(TESTFN, os.O_WRONLY | os.O_APPEND)
w = asyncore.file_wrapper(fd)
os.close(fd)
w.write(d1)
w.send(d2)
w.close()
self.assertEqual(file(TESTFN).read(), self.d + d1 + d2)
示例3: test_close_twice
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import file_wrapper [as 别名]
def test_close_twice(self):
fd = os.open(TESTFN, os.O_RDONLY)
f = asyncore.file_wrapper(fd)
os.close(fd)
os.close(f.fd) # file_wrapper dupped fd
with self.assertRaises(OSError):
f.close()
self.assertEqual(f.fd, -1)
# calling close twice should not fail
f.close()
示例4: test_recv
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import file_wrapper [as 别名]
def test_recv(self):
fd = os.open(support.TESTFN, os.O_RDONLY)
w = asyncore.file_wrapper(fd)
os.close(fd)
self.assertNotEqual(w.fd, fd)
self.assertNotEqual(w.fileno(), fd)
self.assertEqual(w.recv(13), b"It's not dead")
self.assertEqual(w.read(6), b", it's")
w.close()
self.assertRaises(OSError, w.read, 1)
示例5: test_send
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import file_wrapper [as 别名]
def test_send(self):
d1 = b"Come again?"
d2 = b"I want to buy some cheese."
fd = os.open(support.TESTFN, os.O_WRONLY | os.O_APPEND)
w = asyncore.file_wrapper(fd)
os.close(fd)
w.write(d1)
w.send(d2)
w.close()
with open(support.TESTFN, 'rb') as file:
self.assertEqual(file.read(), self.d + d1 + d2)
示例6: test_resource_warning
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import file_wrapper [as 别名]
def test_resource_warning(self):
# Issue #11453
fd = os.open(support.TESTFN, os.O_RDONLY)
f = asyncore.file_wrapper(fd)
os.close(fd)
with support.check_warnings(('', ResourceWarning)):
f = None
support.gc_collect()
示例7: test_close_twice
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import file_wrapper [as 别名]
def test_close_twice(self):
fd = os.open(support.TESTFN, os.O_RDONLY)
f = asyncore.file_wrapper(fd)
os.close(fd)
f.close()
self.assertEqual(f.fd, -1)
# calling close twice should not fail
f.close()