本文整理汇总了Python中posix.fdopen方法的典型用法代码示例。如果您正苦于以下问题:Python posix.fdopen方法的具体用法?Python posix.fdopen怎么用?Python posix.fdopen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类posix
的用法示例。
在下文中一共展示了posix.fdopen方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_FILE_only_for_FILE_arg
# 需要导入模块: import posix [as 别名]
# 或者: from posix import fdopen [as 别名]
def test_FILE_only_for_FILE_arg():
if sys.platform == "win32":
py.test.skip("testing FILE not implemented")
#
B_NOT_FILE = new_struct_type("struct NOT_FILE")
B_NOT_FILEP = new_pointer_type(B_NOT_FILE)
BChar = new_primitive_type("char")
BCharP = new_pointer_type(BChar)
BInt = new_primitive_type("int")
BFunc = new_function_type((BCharP, B_NOT_FILEP), BInt, False)
ll = find_and_load_library('c')
fputs = ll.load_function(BFunc, "fputs")
#
import posix
fdr, fdw = posix.pipe()
fr1 = posix.fdopen(fdr, 'r')
fw1 = posix.fdopen(fdw, 'w')
#
e = py.test.raises(TypeError, fputs, b"hello world\n", fw1)
assert str(e.value).startswith(
"initializer for ctype 'struct NOT_FILE *' must "
"be a cdata pointer, not ")
示例2: dup
# 需要导入模块: import posix [as 别名]
# 或者: from posix import fdopen [as 别名]
def dup(self):
import posix
if not hasattr(posix, 'fdopen'):
raise AttributeError, 'dup() method unavailable'
return posix.fdopen(posix.dup(self._file_.fileno()), self._file_.mode)
示例3: dup2
# 需要导入模块: import posix [as 别名]
# 或者: from posix import fdopen [as 别名]
def dup2(self, fd):
import posix
if not hasattr(posix, 'fdopen'):
raise AttributeError, 'dup() method unavailable'
posix.dup2(self._file_.fileno(), fd)
return posix.fdopen(fd, self._file_.mode)
示例4: test_FILE
# 需要导入模块: import posix [as 别名]
# 或者: from posix import fdopen [as 别名]
def test_FILE():
if sys.platform == "win32":
py.test.skip("testing FILE not implemented")
#
BFILE = new_struct_type("struct _IO_FILE")
BFILEP = new_pointer_type(BFILE)
BChar = new_primitive_type("char")
BCharP = new_pointer_type(BChar)
BInt = new_primitive_type("int")
BFunc = new_function_type((BCharP, BFILEP), BInt, False)
BFunc2 = new_function_type((BFILEP, BCharP), BInt, True)
ll = find_and_load_library('c')
fputs = ll.load_function(BFunc, "fputs")
fscanf = ll.load_function(BFunc2, "fscanf")
#
import posix
fdr, fdw = posix.pipe()
fr1 = posix.fdopen(fdr, 'rb', 256)
fw1 = posix.fdopen(fdw, 'wb', 256)
#
fw1.write(b"X")
res = fputs(b"hello world\n", fw1)
assert res >= 0
fw1.flush() # should not be needed
#
p = newp(new_array_type(BCharP, 100), None)
res = fscanf(fr1, b"%s\n", p)
assert res == 1
assert string(p) == b"Xhello"
fr1.close()
fw1.close()
示例5: test_FILE_object
# 需要导入模块: import posix [as 别名]
# 或者: from posix import fdopen [as 别名]
def test_FILE_object():
if sys.platform == "win32":
py.test.skip("testing FILE not implemented")
#
BFILE = new_struct_type("FILE")
BFILEP = new_pointer_type(BFILE)
BChar = new_primitive_type("char")
BCharP = new_pointer_type(BChar)
BInt = new_primitive_type("int")
BFunc = new_function_type((BCharP, BFILEP), BInt, False)
BFunc2 = new_function_type((BFILEP,), BInt, False)
ll = find_and_load_library('c')
fputs = ll.load_function(BFunc, "fputs")
fileno = ll.load_function(BFunc2, "fileno")
#
import posix
fdr, fdw = posix.pipe()
fw1 = posix.fdopen(fdw, 'wb', 256)
#
fw1p = cast(BFILEP, fw1)
fw1.write(b"X")
fw1.flush()
res = fputs(b"hello\n", fw1p)
assert res >= 0
res = fileno(fw1p)
assert (res == fdw) == (sys.version_info < (3,))
fw1.close()
#
data = posix.read(fdr, 256)
assert data == b"Xhello\n"
posix.close(fdr)
示例6: fdopen_helper
# 需要导入模块: import posix [as 别名]
# 或者: from posix import fdopen [as 别名]
def fdopen_helper(self, *args):
fd = os.open(test_support.TESTFN, os.O_RDONLY)
fp2 = posix.fdopen(fd, *args)
fp2.close()
示例7: test_fdopen
# 需要导入模块: import posix [as 别名]
# 或者: from posix import fdopen [as 别名]
def test_fdopen(self):
if hasattr(posix, 'fdopen'):
self.fdopen_helper()
self.fdopen_helper('r')
self.fdopen_helper('r', 100)