lyrpy 2024.0.4__py3-none-any.whl → 2025.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of lyrpy might be problematic. Click here for more details.
- SRC/LIB/__init__.py +21 -0
- SRC/LIB/lyrpy/LUConst.py +358 -0
- {lyrpy → SRC/LIB/lyrpy}/LUDateTime.py +2 -4
- {lyrpy → SRC/LIB/lyrpy}/LUDecotators.py +2 -3
- {lyrpy → SRC/LIB/lyrpy}/LUDict.py +0 -1
- {lyrpy → SRC/LIB/lyrpy}/LUDoc.py +4 -3
- {lyrpy → SRC/LIB/lyrpy}/LUErrors.py +0 -1
- {lyrpy → SRC/LIB/lyrpy}/LUFile.py +115 -61
- {lyrpy → SRC/LIB/lyrpy}/LUFileUtils.py +60 -45
- {lyrpy → SRC/LIB/lyrpy}/LULog.py +267 -191
- {lyrpy → SRC/LIB/lyrpy}/LUObjects.py +4 -4
- {lyrpy → SRC/LIB/lyrpy}/LUObjectsYT.py +39 -22
- {lyrpy → SRC/LIB/lyrpy}/LUParserARG.py +2 -3
- {lyrpy → SRC/LIB/lyrpy}/LUParserINI.py +8 -3
- {lyrpy → SRC/LIB/lyrpy}/LUParserREG.py +5 -1
- {lyrpy → SRC/LIB/lyrpy}/LUQThread.py +6 -4
- {lyrpy → SRC/LIB/lyrpy}/LUQTimer.py +5 -5
- {lyrpy → SRC/LIB/lyrpy}/LUSheduler.py +24 -23
- SRC/LIB/lyrpy/LUTelegram.py +428 -0
- {lyrpy → SRC/LIB/lyrpy}/LUThread.py +7 -6
- {lyrpy → SRC/LIB/lyrpy}/LUTimer.py +5 -3
- {lyrpy → SRC/LIB/lyrpy}/LUVersion.py +4 -1
- {lyrpy → SRC/LIB/lyrpy}/LUYouTube.py +6 -7
- {lyrpy → SRC/LIB/lyrpy}/LUos.py +13 -3
- SRC/LIB/lyrpy/__init__.py +21 -0
- {lyrpy → SRC/LIB/lyrpy}/__main__.py +20 -19
- SRC/__init__.py +0 -0
- SRC/lyrpy/LUConsole.py +402 -0
- SRC/lyrpy/LUConst.py +358 -0
- SRC/lyrpy/LUDateTime.py +205 -0
- SRC/lyrpy/LUDecotators.py +417 -0
- SRC/lyrpy/LUDict.py +116 -0
- SRC/lyrpy/LUDoc.py +62 -0
- SRC/lyrpy/LUErrors.py +79 -0
- SRC/lyrpy/LUFile.py +1228 -0
- SRC/lyrpy/LUFileUtils.py +501 -0
- SRC/lyrpy/LULog.py +2324 -0
- SRC/lyrpy/LUNetwork.py +277 -0
- SRC/lyrpy/LUNumUtils.py +305 -0
- SRC/lyrpy/LUObjects.py +208 -0
- SRC/lyrpy/LUObjectsYT.py +846 -0
- SRC/lyrpy/LUParserARG.py +364 -0
- SRC/lyrpy/LUParserINI.py +376 -0
- SRC/lyrpy/LUParserREG.py +514 -0
- SRC/lyrpy/LUProc.py +110 -0
- SRC/lyrpy/LUQThread.py +141 -0
- SRC/lyrpy/LUQTimer.py +197 -0
- SRC/lyrpy/LUSheduler.py +941 -0
- SRC/lyrpy/LUStrDecode.py +223 -0
- SRC/lyrpy/LUStrUtils.py +633 -0
- SRC/lyrpy/LUSupport.py +124 -0
- SRC/lyrpy/LUTelegram.py +428 -0
- SRC/lyrpy/LUThread.py +177 -0
- SRC/lyrpy/LUTimer.py +141 -0
- SRC/lyrpy/LUVersion.py +383 -0
- SRC/lyrpy/LUYouTube.py +203 -0
- SRC/lyrpy/LUos.py +807 -0
- lyrpy/LUConst.py → SRC/lyrpy/LUsys.py +12 -10
- SRC/lyrpy/__init__.py +21 -0
- lyrpy/__init__.py → SRC/lyrpy/__main__.py +2 -3
- TESTS/__init__.py +0 -0
- TESTS/test_lyrpy.py +4 -0
- TESTS/test_main.py +10 -0
- __SRC/LIB/__init__.py +0 -0
- __SRC/LIB/lyrpy/LUConsole.py +402 -0
- __SRC/LIB/lyrpy/LUConst.py +358 -0
- __SRC/LIB/lyrpy/LUDateTime.py +205 -0
- __SRC/LIB/lyrpy/LUDecotators.py +417 -0
- __SRC/LIB/lyrpy/LUDict.py +116 -0
- __SRC/LIB/lyrpy/LUDoc.py +62 -0
- __SRC/LIB/lyrpy/LUErrors.py +79 -0
- __SRC/LIB/lyrpy/LUFile.py +1228 -0
- __SRC/LIB/lyrpy/LUFileUtils.py +501 -0
- __SRC/LIB/lyrpy/LULog.py +2324 -0
- __SRC/LIB/lyrpy/LUNetwork.py +277 -0
- __SRC/LIB/lyrpy/LUNumUtils.py +305 -0
- __SRC/LIB/lyrpy/LUObjects.py +208 -0
- __SRC/LIB/lyrpy/LUObjectsYT.py +846 -0
- __SRC/LIB/lyrpy/LUParserARG.py +364 -0
- __SRC/LIB/lyrpy/LUParserINI.py +376 -0
- __SRC/LIB/lyrpy/LUParserREG.py +514 -0
- __SRC/LIB/lyrpy/LUProc.py +110 -0
- __SRC/LIB/lyrpy/LUQThread.py +141 -0
- __SRC/LIB/lyrpy/LUQTimer.py +197 -0
- __SRC/LIB/lyrpy/LUSheduler.py +941 -0
- __SRC/LIB/lyrpy/LUStrDecode.py +223 -0
- __SRC/LIB/lyrpy/LUStrUtils.py +633 -0
- __SRC/LIB/lyrpy/LUSupport.py +124 -0
- __SRC/LIB/lyrpy/LUTelegram.py +428 -0
- __SRC/LIB/lyrpy/LUThread.py +177 -0
- __SRC/LIB/lyrpy/LUTimer.py +141 -0
- __SRC/LIB/lyrpy/LUVersion.py +383 -0
- __SRC/LIB/lyrpy/LUYouTube.py +203 -0
- __SRC/LIB/lyrpy/LUos.py +807 -0
- __SRC/LIB/lyrpy/LUsys.py +47 -0
- __SRC/LIB/lyrpy/__init__.py +21 -0
- __SRC/LIB/lyrpy/__main__.py +20 -0
- __SRC/__init__.py +0 -0
- ____src/__init__.py +0 -0
- ____src/lyrpy/LUConsole.py +402 -0
- ____src/lyrpy/LUConst.py +358 -0
- ____src/lyrpy/LUDateTime.py +205 -0
- ____src/lyrpy/LUDecotators.py +417 -0
- ____src/lyrpy/LUDict.py +116 -0
- ____src/lyrpy/LUDoc.py +62 -0
- ____src/lyrpy/LUErrors.py +79 -0
- ____src/lyrpy/LUFile.py +1228 -0
- ____src/lyrpy/LUFileUtils.py +501 -0
- ____src/lyrpy/LULog.py +2324 -0
- ____src/lyrpy/LUNetwork.py +277 -0
- ____src/lyrpy/LUNumUtils.py +305 -0
- ____src/lyrpy/LUObjects.py +208 -0
- ____src/lyrpy/LUObjectsYT.py +846 -0
- ____src/lyrpy/LUParserARG.py +364 -0
- ____src/lyrpy/LUParserINI.py +376 -0
- ____src/lyrpy/LUParserREG.py +514 -0
- ____src/lyrpy/LUProc.py +110 -0
- ____src/lyrpy/LUQThread.py +141 -0
- ____src/lyrpy/LUQTimer.py +197 -0
- ____src/lyrpy/LUSheduler.py +941 -0
- ____src/lyrpy/LUStrDecode.py +223 -0
- ____src/lyrpy/LUStrUtils.py +633 -0
- ____src/lyrpy/LUSupport.py +124 -0
- ____src/lyrpy/LUTelegram.py +428 -0
- ____src/lyrpy/LUThread.py +177 -0
- ____src/lyrpy/LUTimer.py +141 -0
- ____src/lyrpy/LUVersion.py +383 -0
- ____src/lyrpy/LUYouTube.py +203 -0
- ____src/lyrpy/LUos.py +807 -0
- ____src/lyrpy/LUsys.py +47 -0
- ____src/lyrpy/__init__.py +21 -0
- ____src/lyrpy/__main__.py +20 -0
- lyrpy-2025.0.2.dist-info/METADATA +21 -0
- lyrpy-2025.0.2.dist-info/RECORD +145 -0
- {lyrpy-2024.0.4.dist-info → lyrpy-2025.0.2.dist-info}/WHEEL +1 -1
- lyrpy-2025.0.2.dist-info/top_level.txt +2 -0
- lyrpy-2024.0.4.data/data/data/text.txt +0 -1
- lyrpy-2024.0.4.dist-info/METADATA +0 -44
- lyrpy-2024.0.4.dist-info/RECORD +0 -38
- lyrpy-2024.0.4.dist-info/top_level.txt +0 -1
- {lyrpy → SRC/LIB/lyrpy}/LUConsole.py +0 -0
- {lyrpy → SRC/LIB/lyrpy}/LUNetwork.py +0 -0
- {lyrpy → SRC/LIB/lyrpy}/LUNumUtils.py +0 -0
- {lyrpy → SRC/LIB/lyrpy}/LUProc.py +0 -0
- {lyrpy → SRC/LIB/lyrpy}/LUStrDecode.py +0 -0
- {lyrpy → SRC/LIB/lyrpy}/LUStrUtils.py +0 -0
- {lyrpy → SRC/LIB/lyrpy}/LUSupport.py +0 -0
- {lyrpy → SRC/LIB/lyrpy}/LUsys.py +0 -0
- {lyrpy-2024.0.4.dist-info → lyrpy-2025.0.2.dist-info/licenses}/LICENSE +0 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"""LUNetwork.py"""
|
|
2
|
+
# -*- coding: UTF-8 -*-
|
|
3
|
+
__annotations__ = """
|
|
4
|
+
=======================================================
|
|
5
|
+
Copyright (c) 2023-2024
|
|
6
|
+
Author:
|
|
7
|
+
Lisitsin Y.R.
|
|
8
|
+
Project:
|
|
9
|
+
LU_PY
|
|
10
|
+
Python (LU)
|
|
11
|
+
Module:
|
|
12
|
+
LUNetwork.py
|
|
13
|
+
|
|
14
|
+
=======================================================
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
#------------------------------------------
|
|
18
|
+
# БИБЛИОТЕКИ python
|
|
19
|
+
#------------------------------------------
|
|
20
|
+
import platform
|
|
21
|
+
|
|
22
|
+
#------------------------------------------
|
|
23
|
+
# БИБЛИОТЕКИ сторонние
|
|
24
|
+
#------------------------------------------
|
|
25
|
+
# if platform.system() == 'Windows':
|
|
26
|
+
# import win32api
|
|
27
|
+
# import win32con
|
|
28
|
+
# #endif
|
|
29
|
+
|
|
30
|
+
#------------------------------------------
|
|
31
|
+
# БИБЛИОТЕКИ LU
|
|
32
|
+
#------------------------------------------
|
|
33
|
+
|
|
34
|
+
"""
|
|
35
|
+
function GetLocalIP: string;
|
|
36
|
+
var
|
|
37
|
+
WSAData: TWSAData;
|
|
38
|
+
Host: PHostEnt;
|
|
39
|
+
Buf: array [0 .. 127] of Char;
|
|
40
|
+
begin
|
|
41
|
+
if WSAStartup ($101, WSAData) = 0 then
|
|
42
|
+
begin
|
|
43
|
+
if GetHostName (@Buf, 128) = 0 then
|
|
44
|
+
begin
|
|
45
|
+
Host := GetHostByName (@Buf);
|
|
46
|
+
if Host <> nil then
|
|
47
|
+
begin
|
|
48
|
+
Result := iNet_ntoa (PInAddr(Host^.h_addr_list^)^);
|
|
49
|
+
end;
|
|
50
|
+
end;
|
|
51
|
+
WSACleanUP;
|
|
52
|
+
end;
|
|
53
|
+
end;
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
"""
|
|
57
|
+
(*
|
|
58
|
+
Пример получения имени пользователя и домена под которым работает
|
|
59
|
+
текущий поток или процесс
|
|
60
|
+
|
|
61
|
+
Использовать функцию можно так :
|
|
62
|
+
chDomain:=50;
|
|
63
|
+
chUser :=50;
|
|
64
|
+
GetCurrentUserAndDomain(User,chuser,Domain,chDomain)
|
|
65
|
+
Если вам необходимо получить только имя пользователя - используйте GetUserName
|
|
66
|
+
Данный пример можно использовать и для определения - запущен ли процесс
|
|
67
|
+
системой или пользователем. Учетной записи Localsystem соответствует
|
|
68
|
+
имя пользователя - SYSTEM и домен NT AUTORITY (лучше проверить на практике)
|
|
69
|
+
*)
|
|
70
|
+
|
|
71
|
+
function GetCurrentUserAndDomain (szUser: PChar; var chUser: DWORD;
|
|
72
|
+
szDomain: PChar; var chDomain: DWORD): Boolean;
|
|
73
|
+
var
|
|
74
|
+
hToken: THandle;
|
|
75
|
+
cbBuf: Cardinal;
|
|
76
|
+
ptiUser: PTOKEN_USER;
|
|
77
|
+
snu: SID_NAME_USE;
|
|
78
|
+
begin
|
|
79
|
+
Result := False;
|
|
80
|
+
{ Получаем маркер доступа текущего потока нашего процесса }
|
|
81
|
+
if not OpenThreadToken (GetCurrentThread(), TOKEN_QUERY, True, hToken) then
|
|
82
|
+
begin
|
|
83
|
+
if GetLastError () <> ERROR_NO_TOKEN then
|
|
84
|
+
Exit;
|
|
85
|
+
{ В случее ошибки - получаем маркер доступа нашего процесса. }
|
|
86
|
+
if not OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, hToken) then
|
|
87
|
+
Exit;
|
|
88
|
+
end;
|
|
89
|
+
|
|
90
|
+
{ Вывываем GetTokenInformation для получения размера буфера }
|
|
91
|
+
if not GetTokenInformation (hToken, TokenUser, nil, 0, cbBuf) then
|
|
92
|
+
if GetLastError () <> ERROR_INSUFFICIENT_BUFFER then
|
|
93
|
+
begin
|
|
94
|
+
CloseHandle (hToken);
|
|
95
|
+
Exit;
|
|
96
|
+
end;
|
|
97
|
+
|
|
98
|
+
if cbBuf = 0 then
|
|
99
|
+
Exit;
|
|
100
|
+
|
|
101
|
+
{ Выделяем память под буфер }
|
|
102
|
+
GetMem (ptiUser, cbBuf);
|
|
103
|
+
|
|
104
|
+
{ В случае удачного вызова получим указатель на TOKEN_USER }
|
|
105
|
+
if GetTokenInformation (hToken, TokenUser, ptiUser, cbBuf, cbBuf) then
|
|
106
|
+
begin
|
|
107
|
+
{ Ищем имя пользователя и его домен по его SID }
|
|
108
|
+
if LookupAccountSid (nil, ptiUser.User.Sid, szUser, chUser, szDomain,
|
|
109
|
+
chDomain, snu) then
|
|
110
|
+
Result := True;
|
|
111
|
+
end;
|
|
112
|
+
|
|
113
|
+
{ Освобождаем ресурсы }
|
|
114
|
+
CloseHandle (hToken);
|
|
115
|
+
FreeMem (ptiUser);
|
|
116
|
+
end;
|
|
117
|
+
"""
|
|
118
|
+
|
|
119
|
+
"""
|
|
120
|
+
function DivideUserName_02 (S: string; var Domain: string;
|
|
121
|
+
var Username: string): Boolean;
|
|
122
|
+
var
|
|
123
|
+
i: Integer;
|
|
124
|
+
begin
|
|
125
|
+
i := Pos ('\', S);
|
|
126
|
+
if i <> 0 then
|
|
127
|
+
begin
|
|
128
|
+
Domain := Copy (S, 1, i - 1);
|
|
129
|
+
Username := Copy (S, i + 1, Maxint);
|
|
130
|
+
Result := True;
|
|
131
|
+
end else begin
|
|
132
|
+
i := Pos ('@', S);
|
|
133
|
+
if i <> 0 then
|
|
134
|
+
begin
|
|
135
|
+
Username := Copy (S, 1, i - 1);
|
|
136
|
+
Domain := Copy (S, i + 1, Maxint);
|
|
137
|
+
// result := true;
|
|
138
|
+
end else begin
|
|
139
|
+
Domain := '';
|
|
140
|
+
Username := S;
|
|
141
|
+
end;
|
|
142
|
+
Result := False;
|
|
143
|
+
end;
|
|
144
|
+
end;
|
|
145
|
+
"""
|
|
146
|
+
|
|
147
|
+
"""
|
|
148
|
+
function GetCompName_02: string;
|
|
149
|
+
var
|
|
150
|
+
sz: DWORD;
|
|
151
|
+
begin
|
|
152
|
+
SetLength (Result, MAX_COMPUTERNAME_LENGTH);
|
|
153
|
+
sz := MAX_COMPUTERNAME_LENGTH + 1;
|
|
154
|
+
GetComputerName (PChar(Result), sz);
|
|
155
|
+
SetLength (Result, sz);
|
|
156
|
+
end;
|
|
157
|
+
"""
|
|
158
|
+
|
|
159
|
+
"""
|
|
160
|
+
function Error (Res: DWORD): string;
|
|
161
|
+
var
|
|
162
|
+
// FErrorBufPtr: Pointer;
|
|
163
|
+
// FNameBufPtr: Pointer;
|
|
164
|
+
FErrorString: string;
|
|
165
|
+
|
|
166
|
+
function CheckNetError (Res: DWORD): string;
|
|
167
|
+
var
|
|
168
|
+
S: string;
|
|
169
|
+
// Error: EWin32Error;
|
|
170
|
+
begin
|
|
171
|
+
S := '';
|
|
172
|
+
if (Res <> NERR_Success){ and (Res <> ERROR_MORE_DATA) } then
|
|
173
|
+
begin
|
|
174
|
+
S := SysAndNetErrorMessage (Res);
|
|
175
|
+
S := Format ('Net Error code: %d.'#10'"%s"', [Res, S]);
|
|
176
|
+
end;
|
|
177
|
+
Result := S;
|
|
178
|
+
end;
|
|
179
|
+
|
|
180
|
+
begin
|
|
181
|
+
FErrorString := CheckNetError (Res);
|
|
182
|
+
end;
|
|
183
|
+
"""
|
|
184
|
+
|
|
185
|
+
"""
|
|
186
|
+
function GetUserSID_02 (Domain, Username: string; var Sid: PSID;
|
|
187
|
+
var sidType: SID_NAME_USE): Boolean; overload;
|
|
188
|
+
var
|
|
189
|
+
pdomain: PChar;
|
|
190
|
+
Size: DWORD;
|
|
191
|
+
refDomainLen: DWORD;
|
|
192
|
+
S: string;
|
|
193
|
+
begin
|
|
194
|
+
if Domain <> '' then
|
|
195
|
+
pdomain := PChar (Domain)
|
|
196
|
+
else
|
|
197
|
+
pdomain := nil;
|
|
198
|
+
Size := 4096;
|
|
199
|
+
refDomainLen := 0;
|
|
200
|
+
// result := LookupAccountName(pdomain, pchar(userName), nil, size, nil,refDomainLen,sidType);
|
|
201
|
+
S := Error (GetLastError);
|
|
202
|
+
GetMem (Sid, Size);
|
|
203
|
+
SetLength (Domain, refDomainLen);
|
|
204
|
+
Result := LookupAccountName (pdomain, PChar(Username), Sid, Size,
|
|
205
|
+
@Domain[1], refDomainLen, sidType);
|
|
206
|
+
end;
|
|
207
|
+
"""
|
|
208
|
+
|
|
209
|
+
"""
|
|
210
|
+
function GetUserSID_02 (Domain, Username: string; var Sid: PSID)
|
|
211
|
+
: Boolean; overload;
|
|
212
|
+
var
|
|
213
|
+
ignoreSidType: SID_NAME_USE;
|
|
214
|
+
begin
|
|
215
|
+
Result := GetUserSID_02 (Domain, Username, Sid, ignoreSidType);
|
|
216
|
+
end;
|
|
217
|
+
"""
|
|
218
|
+
|
|
219
|
+
"""
|
|
220
|
+
function GetUserSID_02 (Username: string; var Sid: PSID;
|
|
221
|
+
var sidType: SID_NAME_USE): Boolean; overload;
|
|
222
|
+
var
|
|
223
|
+
Domain: string;
|
|
224
|
+
begin
|
|
225
|
+
DivideUserName_02 (Username, Domain, Username);
|
|
226
|
+
Result := GetUserSID_02 (Domain, Username, Sid, sidType);
|
|
227
|
+
end;
|
|
228
|
+
"""
|
|
229
|
+
|
|
230
|
+
"""
|
|
231
|
+
function GetUserSID_02 (Username: string; var Sid: PSID): Boolean; overload;
|
|
232
|
+
var
|
|
233
|
+
ignoreSidType: SID_NAME_USE;
|
|
234
|
+
begin
|
|
235
|
+
Result := GetUserSID_02 (Username, Sid, ignoreSidType);
|
|
236
|
+
end;
|
|
237
|
+
"""
|
|
238
|
+
|
|
239
|
+
"""
|
|
240
|
+
function GetUserName_02 (Sid: PSID; out Username: string): Boolean;
|
|
241
|
+
var
|
|
242
|
+
Name: string;
|
|
243
|
+
nameLen: DWORD;
|
|
244
|
+
Domain: string;
|
|
245
|
+
domainLen: DWORD;
|
|
246
|
+
sidType: SID_NAME_USE;
|
|
247
|
+
begin
|
|
248
|
+
nameLen := 1024;
|
|
249
|
+
SetLength (name, nameLen);
|
|
250
|
+
domainLen := 1024;
|
|
251
|
+
SetLength (Domain, domainLen);
|
|
252
|
+
Result := LookupAccountSid (nil, Sid, @name[1], nameLen, @Domain[1],
|
|
253
|
+
domainLen, sidType);
|
|
254
|
+
if Result then
|
|
255
|
+
begin
|
|
256
|
+
SetLength (name, nameLen);
|
|
257
|
+
SetLength (Domain, domainLen);
|
|
258
|
+
Username := Domain + '\' + name;
|
|
259
|
+
end;
|
|
260
|
+
end;
|
|
261
|
+
"""
|
|
262
|
+
|
|
263
|
+
#------------------------------------------
|
|
264
|
+
def main ():
|
|
265
|
+
#beginfunction
|
|
266
|
+
print('main LUNetwork.py...')
|
|
267
|
+
#endfunction
|
|
268
|
+
|
|
269
|
+
#------------------------------------------
|
|
270
|
+
#
|
|
271
|
+
#------------------------------------------
|
|
272
|
+
#beginmodule
|
|
273
|
+
if __name__ == "__main__":
|
|
274
|
+
main()
|
|
275
|
+
#endif
|
|
276
|
+
|
|
277
|
+
#endmodule
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
"""LUSupport.py"""
|
|
2
|
+
# -*- coding: UTF-8 -*-
|
|
3
|
+
__annotations__ = """
|
|
4
|
+
=======================================================
|
|
5
|
+
Copyright (c) 2023-2024
|
|
6
|
+
Author:
|
|
7
|
+
Lisitsin Y.R.
|
|
8
|
+
Project:
|
|
9
|
+
LU_PY
|
|
10
|
+
Python (LU)
|
|
11
|
+
Module:
|
|
12
|
+
LUNumUtils.py
|
|
13
|
+
|
|
14
|
+
=======================================================
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
#------------------------------------------
|
|
18
|
+
# БИБЛИОТЕКИ python
|
|
19
|
+
#------------------------------------------
|
|
20
|
+
|
|
21
|
+
#------------------------------------------
|
|
22
|
+
# БИБЛИОТЕКИ сторонние
|
|
23
|
+
#------------------------------------------
|
|
24
|
+
#if platform.system() == 'Windows':
|
|
25
|
+
# import win32api
|
|
26
|
+
# import win32con
|
|
27
|
+
##endif
|
|
28
|
+
|
|
29
|
+
#------------------------------------------
|
|
30
|
+
# БИБЛИОТЕКИ LU
|
|
31
|
+
#------------------------------------------
|
|
32
|
+
|
|
33
|
+
"""
|
|
34
|
+
function Dec2Hex (N: Longint; A: Byte): string;
|
|
35
|
+
begin
|
|
36
|
+
Result := IntToHex (N, A);
|
|
37
|
+
end;
|
|
38
|
+
|
|
39
|
+
function D2H (N: Longint; A: Byte): string;
|
|
40
|
+
begin
|
|
41
|
+
Result := IntToHex (N, A);
|
|
42
|
+
end;
|
|
43
|
+
|
|
44
|
+
function Hex2Dec (const S: string): Longint;
|
|
45
|
+
var
|
|
46
|
+
HexStr: string;
|
|
47
|
+
begin
|
|
48
|
+
if Pos ('$', S) = 0 then
|
|
49
|
+
HexStr := '$' + S
|
|
50
|
+
else
|
|
51
|
+
HexStr := S;
|
|
52
|
+
Result := StrToIntDef (HexStr, 0);
|
|
53
|
+
end;
|
|
54
|
+
|
|
55
|
+
function H2D (const S: string): Longint;
|
|
56
|
+
begin
|
|
57
|
+
Result := Hex2Dec (S);
|
|
58
|
+
end;
|
|
59
|
+
|
|
60
|
+
function Dec2Numb (N: Longint; A, B: Byte): string;
|
|
61
|
+
var
|
|
62
|
+
C: Integer;
|
|
63
|
+
{$IFDEF RX_D4}
|
|
64
|
+
Number: Cardinal;
|
|
65
|
+
{$ELSE}
|
|
66
|
+
Number: Longint;
|
|
67
|
+
{$ENDIF}
|
|
68
|
+
begin
|
|
69
|
+
if N = 0 then
|
|
70
|
+
Result := '0'
|
|
71
|
+
else
|
|
72
|
+
begin
|
|
73
|
+
{$IFDEF RX_D4}
|
|
74
|
+
Number := Cardinal (N);
|
|
75
|
+
{$ELSE}
|
|
76
|
+
Number := N;
|
|
77
|
+
{$ENDIF}
|
|
78
|
+
Result := '';
|
|
79
|
+
while Number > 0 do
|
|
80
|
+
begin
|
|
81
|
+
C := Number mod B;
|
|
82
|
+
if C > 9 then
|
|
83
|
+
C := C + 55
|
|
84
|
+
else
|
|
85
|
+
C := C + 48;
|
|
86
|
+
Result := Chr (C) + Result;
|
|
87
|
+
Number := Number div B;
|
|
88
|
+
end;
|
|
89
|
+
end;
|
|
90
|
+
if Result <> '' then
|
|
91
|
+
Result := AddChar ('0', Result, A);
|
|
92
|
+
end;
|
|
93
|
+
|
|
94
|
+
function Numb2Dec (S: string; B: Byte): Longint;
|
|
95
|
+
var
|
|
96
|
+
I, P: Longint;
|
|
97
|
+
begin
|
|
98
|
+
I := Length (S);
|
|
99
|
+
Result := 0;
|
|
100
|
+
S := UpperCase (S);
|
|
101
|
+
P := 1;
|
|
102
|
+
while (I >= 1) do
|
|
103
|
+
begin
|
|
104
|
+
if S[I] > '@' then
|
|
105
|
+
Result := Result + (Ord(S[I]) - 55) * P
|
|
106
|
+
else
|
|
107
|
+
Result := Result + (Ord(S[I]) - 48) * P;
|
|
108
|
+
Dec (I);
|
|
109
|
+
P := P * B;
|
|
110
|
+
end;
|
|
111
|
+
end;
|
|
112
|
+
|
|
113
|
+
function RomanToInt (const S: string): Longint;
|
|
114
|
+
const
|
|
115
|
+
RomanChars = ['C', 'D', 'I', 'L', 'M', 'V', 'X'];
|
|
116
|
+
RomanValues: array ['C' .. 'X'] of Word = (100, 500, 0, 0, 0, 0, 1, 0, 0,
|
|
117
|
+
50, 1000, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 10);
|
|
118
|
+
var
|
|
119
|
+
Index, Next: Char;
|
|
120
|
+
I: Integer;
|
|
121
|
+
Negative: Boolean;
|
|
122
|
+
begin
|
|
123
|
+
Result := 0;
|
|
124
|
+
I := 0;
|
|
125
|
+
Negative := (Length(S) > 0) and (S[1] = '-');
|
|
126
|
+
if Negative then
|
|
127
|
+
Inc (I);
|
|
128
|
+
while (I < Length(S)) do
|
|
129
|
+
begin
|
|
130
|
+
Inc (I);
|
|
131
|
+
index := UpCase (S[I]);
|
|
132
|
+
if index in RomanChars then
|
|
133
|
+
begin
|
|
134
|
+
if Succ (I) <= Length (S) then
|
|
135
|
+
Next := UpCase (S[I + 1])
|
|
136
|
+
else
|
|
137
|
+
Next := #0;
|
|
138
|
+
if (Next in RomanChars) and (RomanValues[index] < RomanValues[Next])
|
|
139
|
+
then
|
|
140
|
+
begin
|
|
141
|
+
Inc (Result, RomanValues[Next]);
|
|
142
|
+
Dec (Result, RomanValues[index]);
|
|
143
|
+
Inc (I);
|
|
144
|
+
end
|
|
145
|
+
else
|
|
146
|
+
Inc (Result, RomanValues[index]);
|
|
147
|
+
end else begin
|
|
148
|
+
Result := 0;
|
|
149
|
+
Exit;
|
|
150
|
+
end;
|
|
151
|
+
end;
|
|
152
|
+
if Negative then
|
|
153
|
+
Result := - Result;
|
|
154
|
+
end;
|
|
155
|
+
|
|
156
|
+
function IntToRoman (Value: Longint): string;
|
|
157
|
+
label A500,
|
|
158
|
+
A400,
|
|
159
|
+
A100,
|
|
160
|
+
A90,
|
|
161
|
+
A50,
|
|
162
|
+
A40,
|
|
163
|
+
A10,
|
|
164
|
+
A9,
|
|
165
|
+
A5,
|
|
166
|
+
A4,
|
|
167
|
+
A1;
|
|
168
|
+
begin
|
|
169
|
+
Result := '';
|
|
170
|
+
{$IFNDEF WIN32}
|
|
171
|
+
if (Value > MaxInt * 2) then
|
|
172
|
+
Exit;
|
|
173
|
+
{$ENDIF}
|
|
174
|
+
while Value >= 1000 do
|
|
175
|
+
begin
|
|
176
|
+
Dec (Value, 1000);
|
|
177
|
+
Result := Result + 'M';
|
|
178
|
+
end;
|
|
179
|
+
if Value < 900 then
|
|
180
|
+
goto A500
|
|
181
|
+
else
|
|
182
|
+
begin
|
|
183
|
+
Dec (Value, 900);
|
|
184
|
+
Result := Result + 'CM';
|
|
185
|
+
end;
|
|
186
|
+
goto A90;
|
|
187
|
+
A400:
|
|
188
|
+
if Value < 400 then
|
|
189
|
+
goto A100
|
|
190
|
+
else
|
|
191
|
+
begin
|
|
192
|
+
Dec (Value, 400);
|
|
193
|
+
Result := Result + 'CD';
|
|
194
|
+
end;
|
|
195
|
+
goto A90;
|
|
196
|
+
A500:
|
|
197
|
+
if Value < 500 then
|
|
198
|
+
goto A400
|
|
199
|
+
else
|
|
200
|
+
begin
|
|
201
|
+
Dec (Value, 500);
|
|
202
|
+
Result := Result + 'D';
|
|
203
|
+
end;
|
|
204
|
+
A100:
|
|
205
|
+
while Value >= 100 do
|
|
206
|
+
begin
|
|
207
|
+
Dec (Value, 100);
|
|
208
|
+
Result := Result + 'C';
|
|
209
|
+
end;
|
|
210
|
+
A90:
|
|
211
|
+
if Value < 90 then
|
|
212
|
+
goto A50
|
|
213
|
+
else
|
|
214
|
+
begin
|
|
215
|
+
Dec (Value, 90);
|
|
216
|
+
Result := Result + 'XC';
|
|
217
|
+
end;
|
|
218
|
+
goto A9;
|
|
219
|
+
A40:
|
|
220
|
+
if Value < 40 then
|
|
221
|
+
goto A10
|
|
222
|
+
else
|
|
223
|
+
begin
|
|
224
|
+
Dec (Value, 40);
|
|
225
|
+
Result := Result + 'XL';
|
|
226
|
+
end;
|
|
227
|
+
goto A9;
|
|
228
|
+
A50:
|
|
229
|
+
if Value < 50 then
|
|
230
|
+
goto A40
|
|
231
|
+
else
|
|
232
|
+
begin
|
|
233
|
+
Dec (Value, 50);
|
|
234
|
+
Result := Result + 'L';
|
|
235
|
+
end;
|
|
236
|
+
A10:
|
|
237
|
+
while Value >= 10 do
|
|
238
|
+
begin
|
|
239
|
+
Dec (Value, 10);
|
|
240
|
+
Result := Result + 'X';
|
|
241
|
+
end;
|
|
242
|
+
A9:
|
|
243
|
+
if Value < 9 then
|
|
244
|
+
goto A5
|
|
245
|
+
else
|
|
246
|
+
begin
|
|
247
|
+
Result := Result + 'IX';
|
|
248
|
+
end;
|
|
249
|
+
Exit;
|
|
250
|
+
A4:
|
|
251
|
+
if Value < 4 then
|
|
252
|
+
goto A1
|
|
253
|
+
else
|
|
254
|
+
begin
|
|
255
|
+
Result := Result + 'IV';
|
|
256
|
+
end;
|
|
257
|
+
Exit;
|
|
258
|
+
A5:
|
|
259
|
+
if Value < 5 then
|
|
260
|
+
goto A4
|
|
261
|
+
else
|
|
262
|
+
begin
|
|
263
|
+
Dec (Value, 5);
|
|
264
|
+
Result := Result + 'V';
|
|
265
|
+
end;
|
|
266
|
+
goto A1;
|
|
267
|
+
A1:
|
|
268
|
+
while Value >= 1 do
|
|
269
|
+
begin
|
|
270
|
+
Dec (Value);
|
|
271
|
+
Result := Result + 'I';
|
|
272
|
+
end;
|
|
273
|
+
end;
|
|
274
|
+
|
|
275
|
+
function IntToBin (Value: Longint; Digits, Spaces: Integer): string;
|
|
276
|
+
begin
|
|
277
|
+
Result := '';
|
|
278
|
+
if Digits > 32 then
|
|
279
|
+
Digits := 32;
|
|
280
|
+
while Digits > 0 do
|
|
281
|
+
begin
|
|
282
|
+
if (Digits mod Spaces) = 0 then
|
|
283
|
+
Result := Result + ' ';
|
|
284
|
+
Dec (Digits);
|
|
285
|
+
Result := Result + IntToStr ((Value shr Digits) and 1);
|
|
286
|
+
end;
|
|
287
|
+
end;
|
|
288
|
+
|
|
289
|
+
"""
|
|
290
|
+
|
|
291
|
+
#------------------------------------------
|
|
292
|
+
def main ():
|
|
293
|
+
#beginfunction
|
|
294
|
+
print('main LUNumUtils.py...')
|
|
295
|
+
#endfunction
|
|
296
|
+
|
|
297
|
+
#------------------------------------------
|
|
298
|
+
#
|
|
299
|
+
#------------------------------------------
|
|
300
|
+
#beginmodule
|
|
301
|
+
if __name__ == "__main__":
|
|
302
|
+
main()
|
|
303
|
+
#endif
|
|
304
|
+
|
|
305
|
+
#endmodule
|