Run black reformatter on code
This commit is contained in:
parent
4582eb4085
commit
bd3e31bf3c
178 changed files with 4511 additions and 3385 deletions
|
|
@ -173,10 +173,10 @@ class AttributeProperty:
|
|||
foo = AttributeProperty(default="Bar")
|
||||
|
||||
"""
|
||||
|
||||
attrhandler_name = "attributes"
|
||||
|
||||
def __init__(self, default=None, category=None, strattr=False, lockstring="",
|
||||
autocreate=False):
|
||||
def __init__(self, default=None, category=None, strattr=False, lockstring="", autocreate=False):
|
||||
"""
|
||||
Initialize an Attribute as a property descriptor.
|
||||
|
||||
|
|
@ -218,13 +218,12 @@ class AttributeProperty:
|
|||
"""
|
||||
value = self._default
|
||||
try:
|
||||
value = (
|
||||
getattr(instance, self.attrhandler_name)
|
||||
.get(key=self._key,
|
||||
default=self._default,
|
||||
category=self._category,
|
||||
strattr=self._strattr,
|
||||
raise_exception=self._autocreate)
|
||||
value = getattr(instance, self.attrhandler_name).get(
|
||||
key=self._key,
|
||||
default=self._default,
|
||||
category=self._category,
|
||||
strattr=self._strattr,
|
||||
raise_exception=self._autocreate,
|
||||
)
|
||||
except AttributeError:
|
||||
if self._autocreate:
|
||||
|
|
@ -241,12 +240,13 @@ class AttributeProperty:
|
|||
|
||||
"""
|
||||
(
|
||||
getattr(instance, self.attrhandler_name)
|
||||
.add(self._key,
|
||||
value,
|
||||
category=self._category,
|
||||
lockstring=self._lockstring,
|
||||
strattr=self._strattr)
|
||||
getattr(instance, self.attrhandler_name).add(
|
||||
self._key,
|
||||
value,
|
||||
category=self._category,
|
||||
lockstring=self._lockstring,
|
||||
strattr=self._strattr,
|
||||
)
|
||||
)
|
||||
|
||||
def __delete__(self, instance):
|
||||
|
|
@ -254,11 +254,7 @@ class AttributeProperty:
|
|||
Called when running `del` on the field. Will remove/clear the Attribute.
|
||||
|
||||
"""
|
||||
(
|
||||
getattr(instance, self.attrhandler_name)
|
||||
.remove(key=self._key,
|
||||
category=self._category)
|
||||
)
|
||||
(getattr(instance, self.attrhandler_name).remove(key=self._key, category=self._category))
|
||||
|
||||
|
||||
class NAttributeProperty(AttributeProperty):
|
||||
|
|
@ -273,6 +269,7 @@ class NAttributeProperty(AttributeProperty):
|
|||
foo = NAttributeProperty(default="Bar")
|
||||
|
||||
"""
|
||||
|
||||
attrhandler_name = "nattributes"
|
||||
|
||||
|
||||
|
|
@ -357,7 +354,7 @@ class Attribute(IAttribute, SharedMemoryModel):
|
|||
self.save(update_fields=["db_lock_storage"])
|
||||
|
||||
def __lock_storage_del(self):
|
||||
self.db_lock_storage = ''
|
||||
self.db_lock_storage = ""
|
||||
self.save(update_fields=["db_lock_storage"])
|
||||
|
||||
lock_storage = property(__lock_storage_get, __lock_storage_set, __lock_storage_del)
|
||||
|
|
@ -387,6 +384,7 @@ class Attribute(IAttribute, SharedMemoryModel):
|
|||
"""Deleter. Allows for del attr.value. This removes the entire attribute."""
|
||||
self.delete()
|
||||
|
||||
|
||||
#
|
||||
# Handlers making use of the Attribute model
|
||||
#
|
||||
|
|
@ -1465,15 +1463,14 @@ def initialize_nick_templates(pattern, replacement, pattern_is_regex=False):
|
|||
# groups. we need to split out any | - separated parts so we can
|
||||
# attach the line-break/ending extras all regexes require.
|
||||
pattern_regex_string = r"|".join(
|
||||
or_part + r"(?:[\n\r]*?)\Z"
|
||||
for or_part in _RE_OR.split(pattern))
|
||||
or_part + r"(?:[\n\r]*?)\Z" for or_part in _RE_OR.split(pattern)
|
||||
)
|
||||
|
||||
else:
|
||||
# Shell pattern syntax - convert $N to argN groups
|
||||
# for the shell pattern we make sure we have matching $N on both sides
|
||||
pattern_args = [match.group(1) for match in _RE_NICK_RAW_ARG.finditer(pattern)]
|
||||
replacement_args = [
|
||||
match.group(1) for match in _RE_NICK_RAW_ARG.finditer(replacement)]
|
||||
replacement_args = [match.group(1) for match in _RE_NICK_RAW_ARG.finditer(replacement)]
|
||||
if set(pattern_args) != set(replacement_args):
|
||||
# We don't have the same amount of argN/$N tags in input/output.
|
||||
raise NickTemplateInvalid("Nicks: Both in/out-templates must contain the same $N tags.")
|
||||
|
|
@ -1482,7 +1479,8 @@ def initialize_nick_templates(pattern, replacement, pattern_is_regex=False):
|
|||
pattern_regex_string = fnmatch.translate(pattern)
|
||||
pattern_regex_string = _RE_NICK_SPACE.sub(r"\\s+", pattern_regex_string)
|
||||
pattern_regex_string = _RE_NICK_ARG.sub(
|
||||
lambda m: "(?P<arg%s>.+?)" % m.group(2), pattern_regex_string)
|
||||
lambda m: "(?P<arg%s>.+?)" % m.group(2), pattern_regex_string
|
||||
)
|
||||
# we must account for a possible line break coming over the wire
|
||||
pattern_regex_string = pattern_regex_string[:-2] + r"(?:[\n\r]*?)\Z"
|
||||
|
||||
|
|
@ -1509,8 +1507,9 @@ def parse_nick_template(string, template_regex, outtemplate):
|
|||
"""
|
||||
match = template_regex.match(string)
|
||||
if match:
|
||||
matchdict = {key: value if value is not None else ""
|
||||
for key, value in match.groupdict().items()}
|
||||
matchdict = {
|
||||
key: value if value is not None else "" for key, value in match.groupdict().items()
|
||||
}
|
||||
return True, outtemplate.format(**matchdict)
|
||||
return False, string
|
||||
|
||||
|
|
@ -1613,9 +1612,11 @@ class NickHandler(AttributeHandler):
|
|||
|
||||
"""
|
||||
nick_regex, nick_template = initialize_nick_templates(
|
||||
pattern, replacement, pattern_is_regex=pattern_is_regex)
|
||||
super().add(pattern, (nick_regex, nick_template, pattern, replacement),
|
||||
category=category, **kwargs)
|
||||
pattern, replacement, pattern_is_regex=pattern_is_regex
|
||||
)
|
||||
super().add(
|
||||
pattern, (nick_regex, nick_template, pattern, replacement), category=category, **kwargs
|
||||
)
|
||||
|
||||
def remove(self, key, category="inputline", **kwargs):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -514,7 +514,8 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
|
|||
typeclass=F("db_typeclass_path"),
|
||||
# Calculate this class' percentage of total composition
|
||||
percent=ExpressionWrapper(
|
||||
((F("count") / float(self.count())) * 100.0), output_field=FloatField(),
|
||||
((F("count") / float(self.count())) * 100.0),
|
||||
output_field=FloatField(),
|
||||
),
|
||||
)
|
||||
.values("typeclass", "count", "percent")
|
||||
|
|
@ -750,11 +751,7 @@ class TypeclassManager(TypedObjectManager):
|
|||
Returns:
|
||||
Annotated queryset.
|
||||
"""
|
||||
return (
|
||||
super()
|
||||
.filter(db_typeclass_path=self.model.path)
|
||||
.annotate(*args, **kwargs)
|
||||
)
|
||||
return super().filter(db_typeclass_path=self.model.path).annotate(*args, **kwargs)
|
||||
|
||||
def values(self, *args, **kwargs):
|
||||
"""
|
||||
|
|
@ -766,11 +763,7 @@ class TypeclassManager(TypedObjectManager):
|
|||
Returns:
|
||||
Queryset of values dictionaries, just filtered by typeclass first.
|
||||
"""
|
||||
return (
|
||||
super()
|
||||
.filter(db_typeclass_path=self.model.path)
|
||||
.values(*args, **kwargs)
|
||||
)
|
||||
return super().filter(db_typeclass_path=self.model.path).values(*args, **kwargs)
|
||||
|
||||
def values_list(self, *args, **kwargs):
|
||||
"""
|
||||
|
|
@ -782,11 +775,7 @@ class TypeclassManager(TypedObjectManager):
|
|||
Returns:
|
||||
Queryset of value_list tuples, just filtered by typeclass first.
|
||||
"""
|
||||
return (
|
||||
super()
|
||||
.filter(db_typeclass_path=self.model.path)
|
||||
.values_list(*args, **kwargs)
|
||||
)
|
||||
return super().filter(db_typeclass_path=self.model.path).values_list(*args, **kwargs)
|
||||
|
||||
def _get_subclasses(self, cls):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ class TypedObject(SharedMemoryModel):
|
|||
max_length=255,
|
||||
null=True,
|
||||
help_text="this defines what 'type' of entity this is. This variable holds "
|
||||
"a Python path to a module with a valid Evennia Typeclass.",
|
||||
"a Python path to a module with a valid Evennia Typeclass.",
|
||||
db_index=True,
|
||||
)
|
||||
# Creation date. This is not changed once the object is created.
|
||||
|
|
@ -223,19 +223,19 @@ class TypedObject(SharedMemoryModel):
|
|||
"locks",
|
||||
blank=True,
|
||||
help_text="locks limit access to an entity. A lock is defined as a 'lock string' "
|
||||
"on the form 'type:lockfunctions', defining what functionality is locked and "
|
||||
"how to determine access. Not defining a lock means no access is granted.",
|
||||
"on the form 'type:lockfunctions', defining what functionality is locked and "
|
||||
"how to determine access. Not defining a lock means no access is granted.",
|
||||
)
|
||||
# many2many relationships
|
||||
db_attributes = models.ManyToManyField(
|
||||
Attribute,
|
||||
help_text="attributes on this object. An attribute can hold any pickle-able "
|
||||
"python object (see docs for special cases).",
|
||||
"python object (see docs for special cases).",
|
||||
)
|
||||
db_tags = models.ManyToManyField(
|
||||
Tag,
|
||||
help_text="tags on this object. Tags are simple string markers to identify, "
|
||||
"group and alias objects.",
|
||||
"group and alias objects.",
|
||||
)
|
||||
|
||||
# Database manager
|
||||
|
|
|
|||
|
|
@ -102,7 +102,8 @@ class TestTypedObjectManager(BaseEvenniaTest):
|
|||
[self.obj1, self.obj2],
|
||||
)
|
||||
self.assertEqual(
|
||||
self._manager("get_by_tag", ["tag5", "tag7"], "category1"), [self.obj1, self.obj2],
|
||||
self._manager("get_by_tag", ["tag5", "tag7"], "category1"),
|
||||
[self.obj1, self.obj2],
|
||||
)
|
||||
self.assertEqual(self._manager("get_by_tag", category="category1"), [self.obj1, self.obj2])
|
||||
self.assertEqual(self._manager("get_by_tag", category="category2"), [self.obj2])
|
||||
|
|
@ -180,45 +181,96 @@ class TestNickHandler(BaseEvenniaTest):
|
|||
Test the nick handler replacement.
|
||||
|
||||
"""
|
||||
@parameterized.expand([
|
||||
# shell syntax
|
||||
("gr $1 $2 at $3", "emote with a $1 smile, $2 grins at $3.", False,
|
||||
"gr happy Foo at Bar", "emote with a happy smile, Foo grins at Bar."),
|
||||
# regex syntax
|
||||
("gr (?P<arg1>.+?) (?P<arg2>.+?) at (?P<arg3>.+?)",
|
||||
"emote with a $1 smile, $2 grins at $3.", True,
|
||||
"gr happy Foo at Bar", "emote with a happy smile, Foo grins at Bar."),
|
||||
# channel-style syntax
|
||||
("groo $1", "channel groo = $1", False,
|
||||
"groo Hello world", "channel groo = Hello world"),
|
||||
(r"groo\s*?|groo\s+?(?P<arg1>.+?)", "channel groo = $1", True,
|
||||
"groo Hello world", "channel groo = Hello world"),
|
||||
(r"groo\s*?|groo\s+?(?P<arg1>.+?)", "channel groo = $1", True,
|
||||
"groo ", "channel groo = "),
|
||||
(r"groo\s*?|groo\s*?(?P<arg1>.+?)", "channel groo = $1", True,
|
||||
"groo", "channel groo = "),
|
||||
(r"groo\s*?|groo\s+?(?P<arg1>.+?)", "channel groo = $1", True,
|
||||
"grooHello world", "grooHello world"), # not matched - this is correct!
|
||||
# optional, space-separated arguments
|
||||
(r"groo\s*?|groo\s+?(?P<arg1>.+?)(?:\s+?(?P<arg2>.+?)){0,1}",
|
||||
"channel groo = $1 and $2", True,
|
||||
"groo Hello World", "channel groo = Hello and World"),
|
||||
(r"groo\s*?|groo\s+?(?P<arg1>.+?)(?:\s+?(?P<arg2>.+?)){0,1}",
|
||||
"channel groo = $1 and $2", True,
|
||||
"groo Hello", "channel groo = Hello and "),
|
||||
(r"groo\s*?|groo\s+?(?P<arg1>.+?)(?:\s+?(?P<arg2>.+?)){0,1}",
|
||||
"channel groo = $1 and $2", True,
|
||||
"groo", "channel groo = and "), # $1/$2 replaced by ''
|
||||
])
|
||||
def test_nick_parsing(self, pattern, replacement, pattern_is_regex,
|
||||
inp_string, expected_replaced):
|
||||
|
||||
@parameterized.expand(
|
||||
[
|
||||
# shell syntax
|
||||
(
|
||||
"gr $1 $2 at $3",
|
||||
"emote with a $1 smile, $2 grins at $3.",
|
||||
False,
|
||||
"gr happy Foo at Bar",
|
||||
"emote with a happy smile, Foo grins at Bar.",
|
||||
),
|
||||
# regex syntax
|
||||
(
|
||||
"gr (?P<arg1>.+?) (?P<arg2>.+?) at (?P<arg3>.+?)",
|
||||
"emote with a $1 smile, $2 grins at $3.",
|
||||
True,
|
||||
"gr happy Foo at Bar",
|
||||
"emote with a happy smile, Foo grins at Bar.",
|
||||
),
|
||||
# channel-style syntax
|
||||
(
|
||||
"groo $1",
|
||||
"channel groo = $1",
|
||||
False,
|
||||
"groo Hello world",
|
||||
"channel groo = Hello world",
|
||||
),
|
||||
(
|
||||
r"groo\s*?|groo\s+?(?P<arg1>.+?)",
|
||||
"channel groo = $1",
|
||||
True,
|
||||
"groo Hello world",
|
||||
"channel groo = Hello world",
|
||||
),
|
||||
(
|
||||
r"groo\s*?|groo\s+?(?P<arg1>.+?)",
|
||||
"channel groo = $1",
|
||||
True,
|
||||
"groo ",
|
||||
"channel groo = ",
|
||||
),
|
||||
(
|
||||
r"groo\s*?|groo\s*?(?P<arg1>.+?)",
|
||||
"channel groo = $1",
|
||||
True,
|
||||
"groo",
|
||||
"channel groo = ",
|
||||
),
|
||||
(
|
||||
r"groo\s*?|groo\s+?(?P<arg1>.+?)",
|
||||
"channel groo = $1",
|
||||
True,
|
||||
"grooHello world",
|
||||
"grooHello world",
|
||||
), # not matched - this is correct!
|
||||
# optional, space-separated arguments
|
||||
(
|
||||
r"groo\s*?|groo\s+?(?P<arg1>.+?)(?:\s+?(?P<arg2>.+?)){0,1}",
|
||||
"channel groo = $1 and $2",
|
||||
True,
|
||||
"groo Hello World",
|
||||
"channel groo = Hello and World",
|
||||
),
|
||||
(
|
||||
r"groo\s*?|groo\s+?(?P<arg1>.+?)(?:\s+?(?P<arg2>.+?)){0,1}",
|
||||
"channel groo = $1 and $2",
|
||||
True,
|
||||
"groo Hello",
|
||||
"channel groo = Hello and ",
|
||||
),
|
||||
(
|
||||
r"groo\s*?|groo\s+?(?P<arg1>.+?)(?:\s+?(?P<arg2>.+?)){0,1}",
|
||||
"channel groo = $1 and $2",
|
||||
True,
|
||||
"groo",
|
||||
"channel groo = and ",
|
||||
), # $1/$2 replaced by ''
|
||||
]
|
||||
)
|
||||
def test_nick_parsing(
|
||||
self, pattern, replacement, pattern_is_regex, inp_string, expected_replaced
|
||||
):
|
||||
"""
|
||||
Setting up nick patterns and make sure they replace as expected.
|
||||
|
||||
"""
|
||||
# from evennia import set_trace;set_trace()
|
||||
self.char1.nicks.add(pattern, replacement,
|
||||
category="inputline", pattern_is_regex=pattern_is_regex)
|
||||
self.char1.nicks.add(
|
||||
pattern, replacement, category="inputline", pattern_is_regex=pattern_is_regex
|
||||
)
|
||||
actual_replaced = self.char1.nicks.nickreplace(inp_string)
|
||||
|
||||
self.assertEqual(expected_replaced, actual_replaced)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue