FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pymanager-python/src/_native/misc.cpp at main · zooba/pymanager-python · GitHub
zooba
pymanager-python
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pymanager-python
/
src
/
_native
/
misc.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
98 lines (87 loc) · 2.33 KB
Breadcrumbs
pymanager-python
/
src
/
_native
/
misc.cpp
Copy path
File metadata and controls
98 lines (87 loc) · 2.33 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#
include
<
Python.h
>
#
include
<
windows.h
>
#
include
"
helpers.h
"
extern
"
C
"
{
PyObject *
coinitialize
(PyObject *, PyObject *args, PyObject *kwargs) {
HRESULT
hr =
CoInitializeEx
(
NULL
,
COINIT_APARTMENTTHREADED
);
if
(
FAILED
(hr)) {
PyErr_SetFromWindowsErr
(hr);
return
NULL
;
}
Py_RETURN_NONE;
}
static
void
_invalid_parameter
(
const
wchar_t
* expression,
const
wchar_t
* function,
const
wchar_t
* file,
unsigned
int
line,
uintptr_t
pReserved
) { }
PyObject *
fd_supports_vt100
(PyObject *, PyObject *args, PyObject *kwargs) {
static
const
char
* keywords[] = {
"
fd
"
,
NULL
};
int
fd;
if
(!
PyArg_ParseTupleAndKeywords
(args, kwargs,
"
i:fd_supports_vt100
"
, keywords, &fd)) {
return
NULL
;
}
PyObject *r =
NULL
;
HANDLE
h;
DWORD
mode;
const
DWORD
expect_flags =
ENABLE_PROCESSED_OUTPUT
|
ENABLE_VIRTUAL_TERMINAL_PROCESSING
;
auto
handler =
_set_thread_local_invalid_parameter_handler
(_invalid_parameter);
h = (
HANDLE
)
_get_osfhandle
(fd);
_set_thread_local_invalid_parameter_handler
(handler);
if
(
GetConsoleMode
(h, &mode)) {
if
((mode & expect_flags) == expect_flags) {
r =
Py_GetConstant
(Py_CONSTANT_TRUE);
}
else
{
r =
Py_GetConstant
(Py_CONSTANT_FALSE);
}
}
else
{
PyErr_SetFromWindowsErr
(
0
);
}
return
r;
}
PyObject *
date_as_str
(PyObject *, PyObject *, PyObject *) {
wchar_t
buffer[
256
];
DWORD
cch =
GetDateFormatEx
(
LOCALE_NAME_INVARIANT
,
0
,
NULL
,
L"
yyyyMMdd
"
,
buffer,
sizeof
(buffer) /
sizeof
(buffer[
0
]),
NULL
);
if
(!cch) {
PyErr_SetFromWindowsErr
(
0
);
return
NULL
;
}
return
PyUnicode_FromWideChar
(buffer, cch -
1
);
}
PyObject *
datetime_as_str
(PyObject *, PyObject *, PyObject *) {
wchar_t
buffer[
256
];
DWORD
cch =
GetDateFormatEx
(
LOCALE_NAME_INVARIANT
,
0
,
NULL
,
L"
yyyyMMdd
"
,
buffer,
sizeof
(buffer) /
sizeof
(buffer[
0
]),
NULL
);
if
(!cch) {
PyErr_SetFromWindowsErr
(
0
);
return
NULL
;
}
cch -=
1
;
cch +=
GetTimeFormatEx
(
LOCALE_NAME_INVARIANT
,
0
,
NULL
,
L"
HHmmss
"
,
&buffer[cch],
sizeof
(buffer) /
sizeof
(buffer[
0
]) - cch
);
return
PyUnicode_FromWideChar
(buffer, cch -
1
);
}
}
Back
|
FazBrowse Home
|
New Git URL