本文整理匯總了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)