當前位置: 首頁>>代碼示例>>Python>>正文


Python posix.fdopen方法代碼示例

本文整理匯總了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 ") 
開發者ID:johncsnyder,項目名稱:SwiftKitten,代碼行數:24,代碼來源:test_c.py

示例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) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:9,代碼來源:posixfile.py

示例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) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:10,代碼來源:posixfile.py

示例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() 
開發者ID:johncsnyder,項目名稱:SwiftKitten,代碼行數:33,代碼來源:test_c.py

示例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) 
開發者ID:johncsnyder,項目名稱:SwiftKitten,代碼行數:33,代碼來源:test_c.py

示例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() 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:6,代碼來源:test_posix.py

示例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) 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:7,代碼來源:test_posix.py


注:本文中的posix.fdopen方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。