pymud 0.21.0a4__py3-none-any.whl → 0.21.0a5__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.
- pymud/__init__.py +5 -5
- pymud/decorators.py +234 -0
- pymud/extras.py +1 -1
- pymud/lang/i18n_chs.py +6 -2
- pymud/lang/i18n_eng.py +13 -6
- pymud/main.py +17 -4
- pymud/modules.py +33 -180
- pymud/objects.py +77 -70
- pymud/protocol.py +7 -7
- pymud/pymud.py +3 -3
- pymud/session.py +182 -154
- pymud/settings.py +2 -2
- {pymud-0.21.0a4.dist-info → pymud-0.21.0a5.dist-info}/METADATA +33 -4
- pymud-0.21.0a5.dist-info/RECORD +23 -0
- pymud-0.21.0a4.dist-info/RECORD +0 -22
- {pymud-0.21.0a4.dist-info → pymud-0.21.0a5.dist-info}/WHEEL +0 -0
- {pymud-0.21.0a4.dist-info → pymud-0.21.0a5.dist-info}/entry_points.txt +0 -0
- {pymud-0.21.0a4.dist-info → pymud-0.21.0a5.dist-info}/licenses/LICENSE.txt +0 -0
- {pymud-0.21.0a4.dist-info → pymud-0.21.0a5.dist-info}/top_level.txt +0 -0
pymud/modules.py
CHANGED
@@ -1,175 +1,9 @@
|
|
1
1
|
|
2
|
-
import importlib, importlib.util,
|
3
|
-
from
|
4
|
-
from typing import Any, Optional, Union, List, Dict
|
5
|
-
from .objects import BaseObject, Command, Trigger, Alias, Timer, GMCPTrigger
|
2
|
+
import importlib, importlib.util, traceback
|
3
|
+
from typing import Any
|
6
4
|
from .settings import Settings
|
7
5
|
from .extras import DotDict
|
8
|
-
|
9
|
-
|
10
|
-
class PymudDecorator:
|
11
|
-
"""
|
12
|
-
装饰器基类。使用装饰器可以快捷创建各类Pymud基础对象。
|
13
|
-
|
14
|
-
:param type: 装饰器的类型,用于区分不同的装饰器,为字符串类型。
|
15
|
-
:param args: 可变位置参数,用于传递额外的参数。
|
16
|
-
:param kwargs: 可变关键字参数,用于传递额外的键值对参数。
|
17
|
-
"""
|
18
|
-
def __init__(self, type: str, *args, **kwargs):
|
19
|
-
self.type = type
|
20
|
-
self.args = args
|
21
|
-
self.kwargs = kwargs
|
22
|
-
|
23
|
-
def __call__(self, func):
|
24
|
-
decos = getattr(func, "__pymud_decorators__", [])
|
25
|
-
decos.append(self)
|
26
|
-
func.__pymud_decorators__ = decos
|
27
|
-
|
28
|
-
return func
|
29
|
-
return self
|
30
|
-
|
31
|
-
def __repr__(self):
|
32
|
-
return f"<{self.__class__.__name__} type = {self.type} args = {self.args} kwargs = {self.kwargs}>"
|
33
|
-
|
34
|
-
|
35
|
-
def alias(
|
36
|
-
patterns: Union[List[str], str],
|
37
|
-
id: Optional[str] = None,
|
38
|
-
group: str = "",
|
39
|
-
enabled: bool = True,
|
40
|
-
ignoreCase: bool = False,
|
41
|
-
isRegExp: bool = True,
|
42
|
-
keepEval: bool = False,
|
43
|
-
expandVar: bool = True,
|
44
|
-
priority: int = 100,
|
45
|
-
oneShot: bool = False,
|
46
|
-
*args, **kwargs):
|
47
|
-
"""
|
48
|
-
使用装饰器创建一个别名(Alias)对象。被装饰的函数将在别名成功匹配时调用。
|
49
|
-
被装饰的函数,除第一个参数为类实例本身self之外,另外包括id, line, wildcards三个参数。
|
50
|
-
其中id为别名对象的唯一标识符,line为匹配的文本行,wildcards为匹配的通配符列表。
|
51
|
-
|
52
|
-
:param patterns: 别名匹配的模式。
|
53
|
-
:param id: 别名对象的唯一标识符,不指定时将自动生成唯一标识符。
|
54
|
-
:param group: 别名所属的组名,默认为空字符串。
|
55
|
-
:param enabled: 别名是否启用,默认为 True。
|
56
|
-
:param ignoreCase: 匹配时是否忽略大小写,默认为 False。
|
57
|
-
:param isRegExp: 模式是否为正则表达式,默认为 True。
|
58
|
-
:param keepEval: 若存在多个可匹配的别名时,是否持续匹配,默认为 False。
|
59
|
-
:param expandVar: 是否展开变量,默认为 True。
|
60
|
-
:param priority: 别名的优先级,值越小优先级越高,默认为 100。
|
61
|
-
:param oneShot: 别名是否只触发一次后自动失效,默认为 False。
|
62
|
-
:param args: 可变位置参数,用于传递额外的参数。
|
63
|
-
:param kwargs: 可变关键字参数,用于传递额外的键值对参数。
|
64
|
-
:return: PymudDecorator 实例,类型为 "alias"。
|
65
|
-
"""
|
66
|
-
# 将传入的参数更新到 kwargs 字典中
|
67
|
-
kwargs.update({
|
68
|
-
"patterns": patterns,
|
69
|
-
"id": id,
|
70
|
-
"group": group,
|
71
|
-
"enabled": enabled,
|
72
|
-
"ignoreCase": ignoreCase,
|
73
|
-
"isRegExp": isRegExp,
|
74
|
-
"keepEval": keepEval,
|
75
|
-
"expandVar": expandVar,
|
76
|
-
"priority": priority,
|
77
|
-
"oneShot": oneShot})
|
78
|
-
|
79
|
-
# 如果 id 为 None,则从 kwargs 中移除 "id" 键
|
80
|
-
if not id:
|
81
|
-
kwargs.pop("id")
|
82
|
-
|
83
|
-
return PymudDecorator("alias", *args, **kwargs)
|
84
|
-
|
85
|
-
def trigger(
|
86
|
-
patterns: Union[List[str], str],
|
87
|
-
id: Optional[str] = None,
|
88
|
-
group: str = "",
|
89
|
-
enabled: bool = True,
|
90
|
-
ignoreCase: bool = False,
|
91
|
-
isRegExp: bool = True,
|
92
|
-
keepEval: bool = False,
|
93
|
-
expandVar: bool = True,
|
94
|
-
raw: bool = False,
|
95
|
-
priority: int = 100,
|
96
|
-
oneShot: bool = False,
|
97
|
-
*args, **kwargs):
|
98
|
-
"""
|
99
|
-
使用装饰器创建一个触发器(Trigger)对象。
|
100
|
-
|
101
|
-
:param patterns: 触发器匹配的模式。单行模式可以是字符串或正则表达式,多行模式必须是元组或列表,其中每个元素都是字符串或正则表达式。
|
102
|
-
:param id: 触发器对象的唯一标识符,不指定时将自动生成唯一标识符。
|
103
|
-
:param group: 触发器所属的组名,默认为空字符串。
|
104
|
-
:param enabled: 触发器是否启用,默认为 True。
|
105
|
-
:param ignoreCase: 匹配时是否忽略大小写,默认为 False。
|
106
|
-
:param isRegExp: 模式是否为正则表达式,默认为 True。
|
107
|
-
:param keepEval: 若存在多个可匹配的触发器时,是否持续匹配,默认为 False。
|
108
|
-
:param expandVar: 是否展开变量,默认为 True。
|
109
|
-
:param raw: 是否使用原始匹配方式,默认为 False。原始匹配方式下,不对 VT100 下的 ANSI 颜色进行解码,因此可以匹配颜色;正常匹配仅匹配文本。
|
110
|
-
:param priority: 触发器的优先级,值越小优先级越高,默认为 100。
|
111
|
-
:param oneShot: 触发器是否只触发一次后自动失效,默认为 False。
|
112
|
-
:param args: 可变位置参数,用于传递额外的参数。
|
113
|
-
:param kwargs: 可变关键字参数,用于传递额外的键值对参数。
|
114
|
-
:return: PymudDecorator 实例,类型为 "trigger"。
|
115
|
-
"""
|
116
|
-
# 将传入的参数更新到 kwargs 字典中
|
117
|
-
kwargs.update({
|
118
|
-
"patterns": patterns,
|
119
|
-
"id": id,
|
120
|
-
"group": group,
|
121
|
-
"enabled": enabled,
|
122
|
-
"ignoreCase": ignoreCase,
|
123
|
-
"isRegExp": isRegExp,
|
124
|
-
"keepEval": keepEval,
|
125
|
-
"expandVar": expandVar,
|
126
|
-
"raw": raw,
|
127
|
-
"priority": priority,
|
128
|
-
"oneShot": oneShot})
|
129
|
-
if not id:
|
130
|
-
kwargs.pop("id")
|
131
|
-
return PymudDecorator("trigger", *args, **kwargs)
|
132
|
-
|
133
|
-
def timer(timeout: float, id: Optional[str] = None, group: str = "", enabled: bool = True, *args, **kwargs):
|
134
|
-
"""
|
135
|
-
使用装饰器创建一个定时器(Timer)对象。
|
136
|
-
|
137
|
-
:param timeout: 定时器超时时间,单位为秒。
|
138
|
-
:param id: 定时器对象的唯一标识符,不指定时将自动生成唯一标识符。
|
139
|
-
:param group: 定时器所属的组名,默认为空字符串。
|
140
|
-
:param enabled: 定时器是否启用,默认为 True。
|
141
|
-
:param args: 可变位置参数,用于传递额外的参数。
|
142
|
-
:param kwargs: 可变关键字参数,用于传递额外的键值对参数。
|
143
|
-
:return: PymudDecorator 实例,类型为 "timer"。
|
144
|
-
"""
|
145
|
-
kwargs.update({
|
146
|
-
"timeout": timeout,
|
147
|
-
"id": id,
|
148
|
-
"group": group,
|
149
|
-
"enabled": enabled
|
150
|
-
})
|
151
|
-
if not id:
|
152
|
-
kwargs.pop("id")
|
153
|
-
return PymudDecorator("timer", *args, **kwargs)
|
154
|
-
|
155
|
-
def gmcp(name: str, group: str = "", enabled: bool = True, *args, **kwargs):
|
156
|
-
"""
|
157
|
-
使用装饰器创建一个GMCP触发器(GMCPTrigger)对象。
|
158
|
-
|
159
|
-
:param name: GMCP触发器的名称。
|
160
|
-
:param group: GMCP触发器所属的组名,默认为空字符串。
|
161
|
-
:param enabled: GMCP触发器是否启用,默认为 True。
|
162
|
-
:param args: 可变位置参数,用于传递额外的参数。
|
163
|
-
:param kwargs: 可变关键字参数,用于传递额外的键值对参数。
|
164
|
-
:return: PymudDecorator 实例,类型为 "gmcp"。
|
165
|
-
"""
|
166
|
-
kwargs.update({
|
167
|
-
"id": name,
|
168
|
-
"group": group,
|
169
|
-
"enabled": enabled
|
170
|
-
})
|
171
|
-
|
172
|
-
return PymudDecorator("gmcp", *args, **kwargs)
|
6
|
+
from .decorators import exception, async_exception, PymudDecorator, print_exception
|
173
7
|
|
174
8
|
class PymudMeta(type):
|
175
9
|
def __new__(cls, name, bases, attrs):
|
@@ -193,7 +27,9 @@ class ModuleInfo:
|
|
193
27
|
|
194
28
|
"""
|
195
29
|
def __init__(self, module_name: str, session):
|
196
|
-
|
30
|
+
from .session import Session
|
31
|
+
if isinstance(session, Session):
|
32
|
+
self.session = session
|
197
33
|
self._name = module_name
|
198
34
|
self._ismainmodule = False
|
199
35
|
self.load()
|
@@ -223,6 +59,7 @@ class ModuleInfo:
|
|
223
59
|
return result
|
224
60
|
|
225
61
|
def _unload(self):
|
62
|
+
from .objects import BaseObject, Command
|
226
63
|
for key, config in self._config.items():
|
227
64
|
if isinstance(config, Command):
|
228
65
|
# Command 对象在从会话中移除时,自动调用其 unload 系列方法,因此不能产生递归
|
@@ -283,17 +120,15 @@ class ModuleInfo:
|
|
283
120
|
"只读属性,区分是否主模块(即包含具体config的模块)"
|
284
121
|
return self._ismainmodule
|
285
122
|
|
286
|
-
class
|
123
|
+
class IConfigBase(metaclass = PymudMeta):
|
287
124
|
"""
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
在应用自动创建 IConfig 实例时,除 session 参数外,还会传递一个 reload 参数 (bool类型),表示是首次加载还是重新加载特性。
|
293
|
-
可以从kwargs 中获取该参数,并针对性的设计相应代码。例如,重新加载相关联的其他模块等。
|
125
|
+
用于支持对装饰器写法对象进行管理的基础类。
|
126
|
+
该类型相当于原来的IConfig类,唯一区别时,模块加载时,不会对本类型创建实例对象。
|
127
|
+
主要用于对插件中定义的Command提供装饰器写法支持,因为这些Command是在会话构建时创建,因此不能在模块加载时自动创建,也就不能继承自IConfig。
|
294
128
|
"""
|
295
129
|
def __init__(self, session, *args, **kwargs):
|
296
130
|
from .session import Session
|
131
|
+
from .objects import Alias, Trigger, Timer, GMCPTrigger
|
297
132
|
if isinstance(session, Session):
|
298
133
|
self.session = session
|
299
134
|
self.__inline_objects__ = DotDict()
|
@@ -323,6 +158,7 @@ class IConfig(metaclass = PymudMeta):
|
|
323
158
|
self.__inline_objects__[gmcp.id] = gmcp
|
324
159
|
|
325
160
|
def __unload__(self):
|
161
|
+
from .objects import BaseObject
|
326
162
|
if self.session:
|
327
163
|
self.session.delObjects(self.__inline_objects__)
|
328
164
|
if isinstance(self, BaseObject):
|
@@ -333,9 +169,19 @@ class IConfig(metaclass = PymudMeta):
|
|
333
169
|
"返回内联自动创建的对象字典"
|
334
170
|
return self.__inline_objects__
|
335
171
|
|
336
|
-
def obj(self, obj_id: str)
|
172
|
+
def obj(self, obj_id: str):
|
337
173
|
"根据对象ID返回内联自动创建的对象"
|
338
174
|
return self.__inline_objects__.get(obj_id, None) # type: ignore
|
175
|
+
|
176
|
+
class IConfig(IConfigBase):
|
177
|
+
"""
|
178
|
+
用于提示PyMUD应用是否自动创建该配置类型的基础类。
|
179
|
+
|
180
|
+
继承 IConfig 类型让应用自动管理该类型,唯一需要的是,构造函数中,仅存在一个必须指定的参数 Session。
|
181
|
+
|
182
|
+
在应用自动创建 IConfig 实例时,除 session 参数外,还会传递一个 reload 参数 (bool类型),表示是首次加载还是重新加载特性。
|
183
|
+
可以从kwargs 中获取该参数,并针对性的设计相应代码。例如,重新加载相关联的其他模块等。
|
184
|
+
"""
|
339
185
|
|
340
186
|
class Plugin:
|
341
187
|
"""
|
@@ -411,7 +257,11 @@ class Plugin:
|
|
411
257
|
|
412
258
|
:param session: 新创建的会话对象实例
|
413
259
|
"""
|
414
|
-
|
260
|
+
try:
|
261
|
+
self._session_create(session)
|
262
|
+
except Exception as e:
|
263
|
+
print_exception(session, e)
|
264
|
+
|
415
265
|
|
416
266
|
def onSessionDestroy(self, session):
|
417
267
|
"""
|
@@ -419,7 +269,10 @@ class Plugin:
|
|
419
269
|
|
420
270
|
:param session: 所关闭的会话对象实例
|
421
271
|
"""
|
422
|
-
|
272
|
+
try:
|
273
|
+
self._session_destroy(session)
|
274
|
+
except Exception as e:
|
275
|
+
print_exception(session, e)
|
423
276
|
|
424
277
|
def onAppDestroy(self, app):
|
425
278
|
"""
|
pymud/objects.py
CHANGED
@@ -9,6 +9,7 @@ from collections.abc import Iterable
|
|
9
9
|
from collections import namedtuple
|
10
10
|
from typing import Any
|
11
11
|
from .settings import Settings
|
12
|
+
from .decorators import exception, async_exception, print_exception
|
12
13
|
|
13
14
|
class CodeLine:
|
14
15
|
"""
|
@@ -448,10 +449,13 @@ class GMCPTrigger(BaseObject):
|
|
448
449
|
|
449
450
|
self.line = value
|
450
451
|
self.value = value_exp
|
451
|
-
|
452
|
+
|
452
453
|
if callable(self._onSuccess):
|
453
454
|
self.event.set()
|
454
|
-
|
455
|
+
try:
|
456
|
+
self._onSuccess(self.id, value, value_exp)
|
457
|
+
except Exception as e:
|
458
|
+
print_exception(self.session, e)
|
455
459
|
|
456
460
|
def __detailed__(self) -> str:
|
457
461
|
group = f'group = "{self.group}" ' if self.group else ''
|
@@ -548,76 +552,79 @@ class MatchObject(BaseObject):
|
|
548
552
|
|
549
553
|
:return: BaseObject.State 类型,一个包含 result, id, name, line, wildcards 的命名元组对象
|
550
554
|
"""
|
551
|
-
|
552
|
-
|
553
|
-
if not self.multiline: # 非多行
|
554
|
-
if self.isRegExp:
|
555
|
-
m = self._regExp.match(line)
|
556
|
-
if m:
|
557
|
-
result = self.SUCCESS
|
558
|
-
self.wildcards.clear()
|
559
|
-
if len(m.groups()) > 0:
|
560
|
-
self.wildcards.extend(m.groups())
|
555
|
+
try:
|
556
|
+
result = self.NOTSET
|
561
557
|
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
else: # 多行匹配情况
|
574
|
-
# multilines match. 多行匹配时,受限于行的捕获方式,必须一行一行来,设置状态标志进行处理。
|
575
|
-
if self._mline == 0: # 当尚未开始匹配时,匹配第1行
|
576
|
-
m = self._regExps[0].match(line)
|
577
|
-
if m:
|
578
|
-
self.lines.clear()
|
579
|
-
self.lines.append(line)
|
580
|
-
self.wildcards.clear()
|
581
|
-
if len(m.groups()) > 0:
|
582
|
-
self.wildcards.extend(m.groups())
|
583
|
-
self._mline = 1 # 下一状态 (中间行)
|
584
|
-
elif (self._mline > 0) and (self._mline < self.linesToMatch - 1):
|
585
|
-
m = self._regExps[self._mline].match(line)
|
586
|
-
if m:
|
587
|
-
self.lines.append(line)
|
588
|
-
if len(m.groups()) > 0:
|
589
|
-
self.wildcards.extend(m.groups())
|
590
|
-
self._mline += 1
|
558
|
+
if not self.multiline: # 非多行
|
559
|
+
if self.isRegExp:
|
560
|
+
m = self._regExp.match(line)
|
561
|
+
if m:
|
562
|
+
result = self.SUCCESS
|
563
|
+
self.wildcards.clear()
|
564
|
+
if len(m.groups()) > 0:
|
565
|
+
self.wildcards.extend(m.groups())
|
566
|
+
|
567
|
+
self.lines.clear()
|
568
|
+
self.lines.append(line)
|
591
569
|
else:
|
592
|
-
self.
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
self.wildcards.
|
599
|
-
|
600
|
-
|
601
|
-
|
570
|
+
#if line.find(self.patterns) >= 0:
|
571
|
+
#if line == self.patterns:
|
572
|
+
if isinstance(self.patterns, str) and (self.patterns in line):
|
573
|
+
result = self.SUCCESS
|
574
|
+
self.lines.clear()
|
575
|
+
self.lines.append(line)
|
576
|
+
self.wildcards.clear()
|
577
|
+
|
578
|
+
else: # 多行匹配情况
|
579
|
+
# multilines match. 多行匹配时,受限于行的捕获方式,必须一行一行来,设置状态标志进行处理。
|
580
|
+
if self._mline == 0: # 当尚未开始匹配时,匹配第1行
|
581
|
+
m = self._regExps[0].match(line)
|
582
|
+
if m:
|
583
|
+
self.lines.clear()
|
584
|
+
self.lines.append(line)
|
585
|
+
self.wildcards.clear()
|
586
|
+
if len(m.groups()) > 0:
|
587
|
+
self.wildcards.extend(m.groups())
|
588
|
+
self._mline = 1 # 下一状态 (中间行)
|
589
|
+
elif (self._mline > 0) and (self._mline < self.linesToMatch - 1):
|
590
|
+
m = self._regExps[self._mline].match(line)
|
591
|
+
if m:
|
592
|
+
self.lines.append(line)
|
593
|
+
if len(m.groups()) > 0:
|
594
|
+
self.wildcards.extend(m.groups())
|
595
|
+
self._mline += 1
|
596
|
+
else:
|
597
|
+
self._mline = 0
|
598
|
+
elif self._mline == self.linesToMatch - 1: # 最终行
|
599
|
+
m = self._regExps[self._mline].match(line)
|
600
|
+
if m:
|
601
|
+
self.lines.append(line)
|
602
|
+
if len(m.groups()) > 0:
|
603
|
+
self.wildcards.extend(m.groups())
|
604
|
+
result = self.SUCCESS
|
602
605
|
|
603
|
-
|
606
|
+
self._mline = 0
|
604
607
|
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
self.event.set()
|
608
|
+
state = BaseObject.State(result, self.id, "\n".join(self.lines), tuple(self.wildcards))
|
609
|
+
|
610
|
+
# 采用回调方式执行的时候,执行函数回调(仅当self.sync和docallback均为真时才执行同步
|
611
|
+
# 当docallback为真时,是真正的进行匹配和触发,为false时,仅返回匹配结果,不实际触发
|
612
|
+
if docallback:
|
613
|
+
if self.sync:
|
614
|
+
if state.result == self.SUCCESS:
|
615
|
+
self._onSuccess(state.id, state.line, state.wildcards)
|
616
|
+
elif state.result == self.FAILURE:
|
617
|
+
self._onFailure(state.id, state.line, state.wildcards)
|
618
|
+
elif state.result == self.TIMEOUT:
|
619
|
+
self._onTimeout(state.id, state.line, state.wildcards)
|
618
620
|
|
619
|
-
|
620
|
-
|
621
|
+
if state.result == self.SUCCESS:
|
622
|
+
self.event.set()
|
623
|
+
|
624
|
+
self.state = state
|
625
|
+
return state
|
626
|
+
except Exception as e:
|
627
|
+
print_exception(self.session, e)
|
621
628
|
|
622
629
|
async def matched(self) -> BaseObject.State:
|
623
630
|
"""
|
@@ -630,10 +637,10 @@ class MatchObject(BaseObject):
|
|
630
637
|
self.reset()
|
631
638
|
await self.event.wait()
|
632
639
|
self.reset()
|
633
|
-
except Exception as e:
|
634
|
-
self.error(Settings.gettext("exception_in_async", e))
|
635
640
|
|
636
|
-
|
641
|
+
return self.state
|
642
|
+
except Exception as e:
|
643
|
+
print_exception(self.session, e)
|
637
644
|
|
638
645
|
def __detailed__(self) -> str:
|
639
646
|
group = f'group = "{self.group}" ' if self.group else ''
|
pymud/protocol.py
CHANGED
@@ -146,7 +146,7 @@ class MudClientProtocol(Protocol):
|
|
146
146
|
subfunc = getattr(self, f"handle_{v.lower()}_sb", None) # 子协商处理函数
|
147
147
|
self._iac_subneg_handlers[k] = subfunc
|
148
148
|
|
149
|
-
self.encoding = Settings.server["default_encoding"] # 字节串基本编码
|
149
|
+
self.encoding = kwargs.get("encoding", Settings.server["default_encoding"]) # 字节串基本编码
|
150
150
|
self.encoding_errors = Settings.server["encoding_errors"] # 编码解码错误时的处理
|
151
151
|
self.mnes = Settings.mnes
|
152
152
|
|
@@ -767,9 +767,9 @@ class MudClientProtocol(Protocol):
|
|
767
767
|
state_machine = "wait_val_in_table"
|
768
768
|
elif byte in (IAC, MSDP_VAR, MSDP_VAL): # 正常数据 value 结束
|
769
769
|
current_val = val_in_text.decode(self.encoding)
|
770
|
-
msdp_data[current_var] = current_val
|
770
|
+
msdp_data[current_var] = current_val # type: ignore
|
771
771
|
state_machine = "wait_end"
|
772
|
-
self.log.debug(f"收到文本形式的MSDP子协商数据: {current_var} = '{current_val}'")
|
772
|
+
self.log.debug(f"收到文本形式的MSDP子协商数据: {current_var} = '{current_val}'") # type: ignore
|
773
773
|
else: # value是正常数据
|
774
774
|
val_in_text.append(byte)
|
775
775
|
elif state_machine == "wait_val_in_array":
|
@@ -777,9 +777,9 @@ class MudClientProtocol(Protocol):
|
|
777
777
|
# 最后一个val 已结束
|
778
778
|
val_in_array.append(val_in_text.decode(self.encoding))
|
779
779
|
val_in_text.clear()
|
780
|
-
msdp_data[current_var] = val_in_array
|
780
|
+
msdp_data[current_var] = val_in_array # type: ignore
|
781
781
|
state_machine = "wait_end"
|
782
|
-
self.log.debug(f"收到数组形式的MSDP子协商数据: {current_var} = '{val_in_array}'")
|
782
|
+
self.log.debug(f"收到数组形式的MSDP子协商数据: {current_var} = '{val_in_array}'") # type: ignore
|
783
783
|
elif byte == MSDP_VAL:
|
784
784
|
if len(val_in_text) > 0: # 一个VAL已完成,保存到array,后面还有val
|
785
785
|
val_in_array.append(val_in_text.decode(self.encoding))
|
@@ -791,9 +791,9 @@ class MudClientProtocol(Protocol):
|
|
791
791
|
if byte == MSDP_TABLE_CLOSE:
|
792
792
|
# 最后一组已结束
|
793
793
|
val_in_table[table_var_name.decode(self.encoding)] = table_var_value.decode(self.encoding)
|
794
|
-
msdp_data[current_var] = val_in_table
|
794
|
+
msdp_data[current_var] = val_in_table # type: ignore
|
795
795
|
state_machine = "wait_end"
|
796
|
-
self.log.debug(f"收到表格形式的MSDP子协商数据: {current_var} = '{val_in_table}'")
|
796
|
+
self.log.debug(f"收到表格形式的MSDP子协商数据: {current_var} = '{val_in_table}'") # type: ignore
|
797
797
|
elif byte == MSDP_VAR:
|
798
798
|
if len(table_var_name) > 0: # 上一个VAL已完成,保存到table,后面继续为VAR
|
799
799
|
val_in_table[table_var_name.decode(self.encoding)] = table_var_value.decode(self.encoding)
|
pymud/pymud.py
CHANGED
@@ -765,21 +765,21 @@ class PyMudApp:
|
|
765
765
|
val = not Settings.client["beautify"]
|
766
766
|
Settings.client["beautify"] = val
|
767
767
|
if self.current_session:
|
768
|
-
self.current_session.info(f'{Settings.gettext("msg_beautify")}{Settings.gettext("
|
768
|
+
self.current_session.info(f'{Settings.gettext("msg_beautify")}{Settings.gettext("msg_open") if val else Settings.gettext("msg_close")}!')
|
769
769
|
|
770
770
|
def act_echoinput(self):
|
771
771
|
"菜单: 显示/隐藏输入指令"
|
772
772
|
val = not Settings.client["echo_input"]
|
773
773
|
Settings.client["echo_input"] = val
|
774
774
|
if self.current_session:
|
775
|
-
self.current_session.info(f'{Settings.gettext("msg_echoinput")}{Settings.gettext("
|
775
|
+
self.current_session.info(f'{Settings.gettext("msg_echoinput")}{Settings.gettext("msg_open") if val else Settings.gettext("msg_close")}!')
|
776
776
|
|
777
777
|
def act_autoreconnect(self):
|
778
778
|
"菜单: 打开/关闭自动重连"
|
779
779
|
val = not Settings.client["auto_reconnect"]
|
780
780
|
Settings.client["auto_reconnect"] = val
|
781
781
|
if self.current_session:
|
782
|
-
self.current_session.info(f'{Settings.gettext("msg_autoreconnect")}{Settings.gettext("
|
782
|
+
self.current_session.info(f'{Settings.gettext("msg_autoreconnect")}{Settings.gettext("msg_open") if val else Settings.gettext("msg_close")}')
|
783
783
|
|
784
784
|
def act_copy(self):
|
785
785
|
"菜单: 复制纯文本"
|