Skip to content

Commit bae6b4d

Browse files
committed
Doc readonly module and usage
1 parent 1426c15 commit bae6b4d

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

docs/tutorial/obfuscation.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,42 @@ Now do above test again, it should work::
172172
... import joker OK
173173
... import joker.queens
174174

175+
.. _using readonly module:
176+
177+
Using readonly module
178+
---------------------
179+
180+
.. versionadded:: 8.1.9
181+
182+
Readonly module is one simple way to protect the obfuscated package, it only allows the plain scripts import and read the obfuscated module, but can't write or change any attribute or method of obfuscated modules.
183+
184+
Enable readonly module by this way::
185+
186+
$ pyarmor cfg readonly_module=1
187+
188+
Then obfuscate the whole package::
189+
190+
$ pyarmor gen --enable-jit --mix-str joker/
191+
192+
Test it::
193+
194+
$ cd dist
195+
$ python
196+
>>> import joker
197+
>>> dir(joker)
198+
>>> joker.aaa = 1
199+
Traceback (most recent call last):
200+
File "<stdin>", line 1, in <module>
201+
RuntimeError: protection exception (16782406)
202+
203+
If only need export a few modules, for example, `joker.card` and `joker.__init__`, the other modules in the package need not be exported, the best way is like these::
204+
205+
$ pyarmor cfg readonly_module=1
206+
$ pyarmor cfg exclude_restrict_modules="__init__ joker.card"
207+
$ pyarmor gen --enable-jit --mix-str --assert-call --assert-import --restrict joker/
208+
209+
The modules list in the `exclude_restrict_modules` are readonly, all the others are more restricted.
210+
175211
Copying package data files
176212
==========================
177213

0 commit comments

Comments
 (0)