Skip to content

Commit

Permalink
1. fix utils.code_inline gzip compress mtime to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
lidong committed Sep 24, 2024
1 parent bd752c9 commit e6e9f71
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 1.1.7 (2024-09-24)
1. fix `utils.code_inline` gzip compress `mtime` to 0
2.

### 1.1.6 (2024-09-09)
1. add filename_filter to utils.format_error
2. add `functools.get_function` to find function from entrypoint
Expand Down
14 changes: 10 additions & 4 deletions doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,17 @@

```python

>>> code1 = ''
>>> code2 = code_inline("variable=12345")
>>> # import base64,gzip;exec(gzip.decompress(base64.b85decode("ABzY8mBl+`0{<&ZEXqtw%1N~~G%_|Z1ptx!(o_xr000".encode("u8"))))
>>> code1 = code_inline('def test_code1(): return 12345')
>>> code1
'import base64,gzip;exec(gzip.decompress(base64.b85decode("ABzY8000000t!n>O;adIEiQ>q&QD1-)X=n2C`v6UEy`0cG%_|Z1psqiSP>oo000".encode("u8"))))'
>>> exec(code1)
>>> test_code1()
12345
>>> code2 = code_inline("v=12345")
>>> code2
'import base64,gzip;exec(gzip.decompress(base64.b85decode("ABzY8000000tzd$H8e6dF$Dk}<L9Rb0000".encode("u8"))))'
>>> exec(code2)
>>> variable
>>> v
12345

Args:
Expand Down
16 changes: 11 additions & 5 deletions morebuiltins/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,17 @@ def code_inline(
) -> str:
"""Minifies Python source code into a single line.
>>> code1 = ''
>>> code2 = code_inline("variable=12345")
>>> # import base64,gzip;exec(gzip.decompress(base64.b85decode("ABzY8mBl+`0{<&ZEXqtw%1N~~G%_|Z1ptx!(o_xr000".encode("u8"))))
>>> code1 = code_inline('def test_code1(): return 12345')
>>> code1
'import base64,gzip;exec(gzip.decompress(base64.b85decode("ABzY8000000t!n>O;adIEiQ>q&QD1-)X=n2C`v6UEy`0cG%_|Z1psqiSP>oo000".encode("u8"))))'
>>> exec(code1)
>>> test_code1()
12345
>>> code2 = code_inline("v=12345")
>>> code2
'import base64,gzip;exec(gzip.decompress(base64.b85decode("ABzY8000000tzd$H8e6dF$Dk}<L9Rb0000".encode("u8"))))'
>>> exec(code2)
>>> variable
>>> v
12345
Args:
Expand All @@ -429,7 +435,7 @@ def code_inline(
"""
_encoder = getattr(base64, f"{encoder}encode")
_source = source_code.encode(encoding="u8")
_source = gzip.compress(_source)
_source = gzip.compress(_source, mtime=0)
_source = _encoder(_source)
code = _source.decode("u8")
result = (
Expand Down

0 comments on commit e6e9f71

Please sign in to comment.