File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -164,6 +164,42 @@ Pyarmor 使用 :ref:`pyarmor gen` 加密不同的脚本,它提供了丰富的
164164 ... import joker OK
165165 ... import joker.queens
166166
167+ .. _using readonly module :
168+
169+ 使用只读模式保护包
170+ ------------------
171+
172+ .. versionadded :: 8.1.9
173+
174+ 对于包的保护也可以使用只读模式,这种模式允许外部模块导入和使用加密包中模块,但是不允许外部模块修改加密模块的属性和方法,是一种相对简单的保护模式。
175+
176+ 使用下面的配置命令启用只读模式::
177+
178+ $ pyarmor cfg readonly_module=1
179+
180+ 然后在加密整个包::
181+
182+ $ pyarmor gen --enable-jit --mix-str joker/
183+
184+ 简单测试一下::
185+
186+ $ cd dist
187+ $ python
188+ >>> import joker
189+ >>> dir(joker)
190+ >>> joker.aaa = 1
191+ Traceback (most recent call last):
192+ File "<stdin>", line 1, in <module>
193+ RuntimeError: protection exception (16782406)
194+
195+ 如果是仅仅需要输出模块 `joker.card ` 以及 `joker.__init__ ` ,包中的其中模块依旧需要其它保护,那么可以启用只读模式,把需要输出的模块增加到配置项 `exclude_restrict_modules ` 中,然后在进行加密。例如::
196+
197+ $ pyarmor cfg readonly_module=1
198+ $ pyarmor cfg exclude_restrict_modules="joker.card joker.__init__"
199+ $ pyarmor gen --enable-jit --mix-str --assert-call --assert-import --restrict joker/
200+
201+ 因为使用 `--private/restrict ` 或者 `--assert-call/import ` 加密的模块,默认情况下是不允许外部模块导入的,所以必须把输出模块增加到配置项 `exclude_restrict_modules ` 中。
202+
167203拷贝数据文件
168204============
169205
You can’t perform that action at this time.
0 commit comments