diff options
author | nkozlovskiy <nmk@ydb.tech> | 2023-10-02 18:57:38 +0300 |
---|---|---|
committer | nkozlovskiy <nmk@ydb.tech> | 2023-10-02 19:39:06 +0300 |
commit | 6295ef4d23465c11296e898b9dc4524ad9592b5d (patch) | |
tree | fc0c852877b2c52f365a1f6ed0710955844338c2 /contrib/deprecated/python/win-unicode-console/win_unicode_console/file_object.py | |
parent | de63c80b75948ecc13894854514d147840ff8430 (diff) | |
download | ydb-6295ef4d23465c11296e898b9dc4524ad9592b5d.tar.gz |
oss ydb: fix dstool building and test run
Diffstat (limited to 'contrib/deprecated/python/win-unicode-console/win_unicode_console/file_object.py')
-rw-r--r-- | contrib/deprecated/python/win-unicode-console/win_unicode_console/file_object.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/contrib/deprecated/python/win-unicode-console/win_unicode_console/file_object.py b/contrib/deprecated/python/win-unicode-console/win_unicode_console/file_object.py new file mode 100644 index 0000000000..3c9b56ccb4 --- /dev/null +++ b/contrib/deprecated/python/win-unicode-console/win_unicode_console/file_object.py @@ -0,0 +1,55 @@ + +from .info import check_PY2 +check_PY2() + +import ctypes +from ctypes import (byref, pythonapi, + c_int, c_char_p, c_void_p, py_object, c_ssize_t) + + +class FileObject(ctypes.Structure): + _fields_ = [ + #("_ob_next", c_void_p), + #("_ob_prev", c_void_p), + ("ob_refcnt", c_ssize_t), + ("ob_type", c_void_p), + + ("fp", c_void_p), + ("name", py_object), + ("mode", py_object), + ("close", c_void_p), + ("softspace", c_int), + ("binary", c_int), + ("buf", c_char_p), + ("bufend", c_char_p), + ("bufptr", c_char_p), + ("setbuf", c_char_p), + ("univ_newline", c_int), + ("newlinetypes", c_int), + ("skipnextlf", c_int), + ("encoding", py_object), + ("errors", py_object), + ("weakreflist", py_object), + ("unlocked_count", c_int), + ("readable", c_int), + ("writable", c_int), + ] + + @classmethod + def from_file(cls, f): + if not isinstance(f, file): + raise TypeError("f has to be a file") + + return cls.from_address(id(f)) + + def set_encoding(self, encoding): + if not isinstance(encoding, str): + raise TypeError("encoding has to be a str") + + pythonapi.PyFile_SetEncoding(byref(self), encoding) + + def copy_file_pointer(self, f): + if not isinstance(f, file): + raise TypeError("f has to be a file") + + self.fp = pythonapi.PyFile_AsFile(py_object(f)) |