Skip to content

Commit 69c8822

Browse files
author
lidong
committed
6. fix utils.code_inline gzip compress mtime to 0
7. fix systemd.timer typing hint error
1 parent 52c94f9 commit 69c8822

File tree

5 files changed

+22
-43
lines changed

5 files changed

+22
-43
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
3. add `cmd.os.linux.systemd.service` and `cmd.os.linux.systemd.timer`
55
4. add `functools.to_thread`, same as `asyncio.to_thread` in python 3.9+.
66
5. add `functools.AsyncQueueListener` for asyncio non-block logging.
7+
6. fix `utils.code_inline` gzip compress `mtime` to 0
8+
7. fix systemd.timer typing hint error
79

810
### 1.1.8 (2024-12-11)
911
1. add `utils.i2b` and `utils.b2i`, integer and fixed-length byte strings conversion.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ print(morebuiltins.__file__)
149149

150150
3.12 `get_function` - Get the function object from entrypoint.
151151

152+
3.13 `to_thread` - Asynchronously run function *func* in a separate thread, same as `asyncio.to_thread` in python 3.9+.
153+
152154

153155
## 4. morebuiltins.ipc
154156

doc.md

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,13 @@
227227

228228
>>> code1 = code_inline('def test_code1(): return 12345')
229229
>>> code1
230-
'import base64,gzip;exec(gzip.decompress(base64.b85decode("ABzY80RR910{=@%O;adIEiQ>q&QD1-)X=n2C`v6UEy`0cG%_|Z1psqiSP>oo000".encode("u8"))))'
230+
'import base64,gzip;exec(gzip.decompress(base64.b85decode("ABzY8000000t!n>O;adIEiQ>q&QD1-)X=n2C`v6UEy`0cG%_|Z1psqiSP>oo000".encode("u8"))))'
231231
>>> exec(code1)
232232
>>> test_code1()
233233
12345
234234
>>> code2 = code_inline("v=12345")
235235
>>> code2
236-
'import base64,gzip;exec(gzip.decompress(base64.b85decode("ABzY80RR910{<(sH8e6dF$Dk}<L9Rb0000".encode("u8"))))'
236+
'import base64,gzip;exec(gzip.decompress(base64.b85decode("ABzY8000000tzd$H8e6dF$Dk}<L9Rb0000".encode("u8"))))'
237237
>>> exec(code2)
238238
>>> v
239239
12345
@@ -505,41 +505,6 @@
505505
... except Exception as e:
506506
... format_error(e, index=slice(-1, None, None))
507507
'[<doctest>:func2(3)] def func2(): 1 / 0 >>> ZeroDivisionError(division by zero)'
508-
>>> try:
509-
... # test without filter
510-
... from pip._internal.utils.encoding import auto_decode
511-
... auto_decode(0)
512-
... except Exception as e:
513-
... "encoding.py:auto_decode" in format_error(e, filter=None)
514-
True
515-
>>> try:
516-
... # test with custom filter.
517-
... from pip._internal.utils.encoding import auto_decode
518-
... auto_decode(0)
519-
... except Exception as e:
520-
... format_error(e, filter=lambda i: '<doctest' in str(i))
521-
"[<doctest>:<module>(4)] auto_decode(0) >>> AttributeError('int' object has no attribute 'startswith')"
522-
>>> try:
523-
... # test with default filter(filename skip -packages)
524-
... from pip._internal.utils.encoding import auto_decode
525-
... auto_decode(0)
526-
... except Exception as e:
527-
... format_error(e)
528-
"[<doctest>:<module>(4)] auto_decode(0) >>> AttributeError('int' object has no attribute 'startswith')"
529-
>>> try:
530-
... # test with filename_filter[0] include string, disable the default filter at first
531-
... from pip._internal.utils.encoding import auto_decode
532-
... auto_decode(0)
533-
... except Exception as e:
534-
... "encoding.py:auto_decode" in format_error(e, filter=None, filename_filter=("-packages", ""))
535-
True
536-
>>> try:
537-
... # test with filename_filter[1] exclude string, disable the default filter at first
538-
... from pip._internal.utils.encoding import auto_decode
539-
... auto_decode(0)
540-
... except Exception as e:
541-
... "encoding.py:auto_decode" in format_error(e, filter=None, filename_filter=("", "-packages"))
542-
False
543508

544509
```
545510

@@ -1190,7 +1155,7 @@
11901155
5
11911156
>>> len(test.tasks)
11921157
0
1193-
>>> test.pool.shutdown()
1158+
>>> test.pool.shutdown() # optional
11941159

11951160
```
11961161

@@ -1620,6 +1585,16 @@
16201585
```
16211586

16221587

1588+
---
1589+
1590+
1591+
1592+
3.13 `to_thread` - Asynchronously run function *func* in a separate thread, same as `asyncio.to_thread` in python 3.9+.
1593+
1594+
1595+
1596+
1597+
16231598
---
16241599

16251600

morebuiltins/cmd/systemd/timer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import argparse
22
import sys
3-
from typing import Any, Dict
3+
from typing import Any, Dict, Tuple
44
import subprocess
55
from pathlib import Path
66

@@ -52,7 +52,7 @@ def manage_timer_files(
5252
return 0
5353

5454

55-
def create_timer_file(args: Dict[str, Any]) -> tuple[str, str]:
55+
def create_timer_file(args: Dict[str, Any]) -> Tuple[str, str]:
5656
"""Generate systemd timer and service file content"""
5757
# Generate timer content
5858
timer_content = ["[Unit]"]

morebuiltins/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,13 +418,13 @@ def code_inline(
418418
419419
>>> code1 = code_inline('def test_code1(): return 12345')
420420
>>> code1
421-
'import base64,gzip;exec(gzip.decompress(base64.b85decode("ABzY80RR910{=@%O;adIEiQ>q&QD1-)X=n2C`v6UEy`0cG%_|Z1psqiSP>oo000".encode("u8"))))'
421+
'import base64,gzip;exec(gzip.decompress(base64.b85decode("ABzY8000000t!n>O;adIEiQ>q&QD1-)X=n2C`v6UEy`0cG%_|Z1psqiSP>oo000".encode("u8"))))'
422422
>>> exec(code1)
423423
>>> test_code1()
424424
12345
425425
>>> code2 = code_inline("v=12345")
426426
>>> code2
427-
'import base64,gzip;exec(gzip.decompress(base64.b85decode("ABzY80RR910{<(sH8e6dF$Dk}<L9Rb0000".encode("u8"))))'
427+
'import base64,gzip;exec(gzip.decompress(base64.b85decode("ABzY8000000tzd$H8e6dF$Dk}<L9Rb0000".encode("u8"))))'
428428
>>> exec(code2)
429429
>>> v
430430
12345
@@ -437,7 +437,7 @@ def code_inline(
437437
"""
438438
_encoder = getattr(base64, f"{encoder}encode")
439439
_source = source_code.encode(encoding="u8")
440-
_source = gzip.compress(_source, mtime=1)
440+
_source = gzip.compress(_source, mtime=0)
441441
_source = _encoder(_source)
442442
code = _source.decode("u8")
443443
result = (

0 commit comments

Comments
 (0)