Ran black on sources

This commit is contained in:
Griatch 2023-11-02 20:56:31 +01:00
parent 24d52f229f
commit f6b43b0416
125 changed files with 355 additions and 329 deletions

View file

@ -335,7 +335,6 @@ class ANSIParser(object):
red, green, blue = gray, gray, gray
if use_xterm256:
if not grayscale:
colval = 16 + (red * 36) + (green * 6) + blue
@ -347,56 +346,55 @@ class ANSIParser(object):
else:
# xterm256 not supported, convert the rgb value to ansi instead
rgb = (red, green, blue)
def _convert_for_ansi(val):
return int((val+1)//2)
return int((val + 1) // 2)
# greys
if (max(rgb) - min(rgb)) <= 1:
match rgb:
case (0,0,0):
case (0, 0, 0):
return ANSI_BACK_BLACK if background else ANSI_NORMAL + ANSI_BLACK
case ((1|2), (1|2), (1|2)):
case ((1 | 2), (1 | 2), (1 | 2)):
return ANSI_BACK_BLACK if background else ANSI_HILITE + ANSI_BLACK
case ((2|3), (2|3), (2|3)):
case ((2 | 3), (2 | 3), (2 | 3)):
return ANSI_BACK_WHITE if background else ANSI_NORMAL + ANSI_WHITE
case ((3|4), (3|4), (3|4)):
case ((3 | 4), (3 | 4), (3 | 4)):
return ANSI_BACK_WHITE if background else ANSI_NORMAL + ANSI_WHITE
case ((4|5), (4|5), (4|5)):
case ((4 | 5), (4 | 5), (4 | 5)):
return ANSI_BACK_WHITE if background else ANSI_HILITE + ANSI_WHITE
match tuple(_convert_for_ansi(c) for c in rgb):
# red
case ((2|3), (0|1), (0|1)):
case ((2 | 3), (0 | 1), (0 | 1)):
return ANSI_BACK_RED if background else ANSI_HILITE + ANSI_RED
case ((1|2), 0, 0):
case ((1 | 2), 0, 0):
return ANSI_BACK_RED if background else ANSI_NORMAL + ANSI_RED
# green
case ((0|1), (2|3), (0|1)):
case ((0 | 1), (2 | 3), (0 | 1)):
return ANSI_BACK_GREEN if background else ANSI_HILITE + ANSI_GREEN
case ((0 | 1), 1, 0) if green > red:
return ANSI_BACK_GREEN if background else ANSI_NORMAL + ANSI_GREEN
# blue
case ((0|1), (0|1), (2|3)):
case ((0 | 1), (0 | 1), (2 | 3)):
return ANSI_BACK_BLUE if background else ANSI_HILITE + ANSI_BLUE
case (0, 0, 1):
return ANSI_BACK_BLUE if background else ANSI_NORMAL + ANSI_BLUE
# cyan
case ((0|1|2), (2|3), (2|3)) if red == min(rgb):
case ((0 | 1 | 2), (2 | 3), (2 | 3)) if red == min(rgb):
return ANSI_BACK_CYAN if background else ANSI_HILITE + ANSI_CYAN
case (0, (1|2), (1|2)):
case (0, (1 | 2), (1 | 2)):
return ANSI_BACK_CYAN if background else ANSI_NORMAL + ANSI_CYAN
# yellow
case ((2|3), (2|3), (0|1|2)) if blue == min(rgb):
case ((2 | 3), (2 | 3), (0 | 1 | 2)) if blue == min(rgb):
return ANSI_BACK_YELLOW if background else ANSI_HILITE + ANSI_YELLOW
case ((2|1), (2|1), (0|1)):
case ((2 | 1), (2 | 1), (0 | 1)):
return ANSI_BACK_YELLOW if background else ANSI_NORMAL + ANSI_YELLOW
# magenta
case ((2|3), (0|1|2), (2|3)) if green == min(rgb):
case ((2 | 3), (0 | 1 | 2), (2 | 3)) if green == min(rgb):
return ANSI_BACK_MAGENTA if background else ANSI_HILITE + ANSI_MAGENTA
case ((1|2), 0, (1|2)):
case ((1 | 2), 0, (1 | 2)):
return ANSI_BACK_MAGENTA if background else ANSI_NORMAL + ANSI_MAGENTA
def strip_raw_codes(self, string):
"""

View file

@ -30,6 +30,7 @@ except ImportError:
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ObjectDoesNotExist
from django.utils.safestring import SafeString
import evennia
from evennia.utils import logger
from evennia.utils.utils import is_iter, to_bytes, uses_database
@ -130,6 +131,7 @@ def _init_globals():
_TO_MODEL_MAP[src_key] = _TO_MODEL_MAP.get(dst_key, None)
_IGNORE_DATETIME_MODELS.append(src_key)
#
# SaverList, SaverDict, SaverSet - Attribute-specific helper classes and functions
#

View file

@ -431,8 +431,7 @@ class EvForm:
return rects
# Map EvCells into form rectangles
for (key, y, x, width, height) in _get_rectangles(formchar):
for key, y, x, width, height in _get_rectangles(formchar):
# get data to populate cell
data = self.cells_mapping.get(key, "")
if isinstance(data, EvCell):
@ -455,8 +454,7 @@ class EvForm:
mapping[key] = (y, x, width, height, cell)
# Map EvTables into form rectangles
for (key, y, x, width, height) in _get_rectangles(tablechar):
for key, y, x, width, height in _get_rectangles(tablechar):
# get EvTable from mapping
table = self.tables_mapping.get(key, None)
@ -479,7 +477,6 @@ class EvForm:
mapping = self.mapping
for key, (y, x, width, height, cell_or_table) in mapping.items():
# rect is a list of <height> lines, each <width> wide
rect = cell_or_table.get()
for il, rectline in enumerate(rect):

View file

@ -276,12 +276,22 @@ from django.conf import settings
# i18n
from django.utils.translation import gettext as _
from evennia import CmdSet, Command
from evennia.commands import cmdhandler
from evennia.utils import logger
from evennia.utils.ansi import strip_ansi
from evennia.utils.evtable import EvColumn, EvTable
from evennia.utils.utils import crop, dedent, is_iter, m_len, make_iter, mod_import, pad, to_str
from evennia.utils.utils import (
crop,
dedent,
is_iter,
m_len,
make_iter,
mod_import,
pad,
to_str,
)
# read from protocol NAWS later?
_MAX_TEXT_WIDTH = settings.CLIENT_DEFAULT_WIDTH
@ -919,7 +929,7 @@ class EvMenu:
# ((key,aliases)-value) pairs.
# make sure helptext is defined
helptext = ""
helptext = ""
if is_iter(nodetext):
nodetext, *helptext = nodetext
helptext = helptext[0] if helptext else ""

View file

@ -40,6 +40,7 @@ from django.conf import settings
from django.core.paginator import Paginator
from django.db.models.query import QuerySet
from django.utils.translation import gettext as _
from evennia.commands import cmdhandler
from evennia.commands.cmdset import CmdSet
from evennia.commands.command import Command

View file

@ -118,6 +118,7 @@ from copy import copy, deepcopy
from textwrap import TextWrapper
from django.conf import settings
from evennia.utils.ansi import ANSIString
from evennia.utils.utils import display_len as d_len
from evennia.utils.utils import is_iter, justify
@ -220,7 +221,6 @@ class ANSITextWrapper(TextWrapper):
chunks.reverse()
while chunks:
# Start the list of chunks that will make up the current line.
# cur_len is just the length of all the chunks in cur_line.
cur_line = []
@ -1401,7 +1401,6 @@ class EvTable:
if self.height:
# if we are fixing the table height, it means cells must crop text instead of resizing.
if nrowmax:
# get minimum possible cell heights for each column
cheights_min = [
max(cell.get_min_height() for cell in (col[iy] for col in self.worktable))

View file

@ -48,6 +48,7 @@ import inspect
import random
from django.conf import settings
from evennia.utils import logger, search
from evennia.utils.utils import (
callables_from_module,
@ -333,7 +334,6 @@ class FuncParser:
literal_infuncstr = False
for char in string:
if escaped:
# always store escaped characters verbatim
if curr_func:
@ -1298,8 +1298,11 @@ def funcparser_callable_your(
if caller == receiver:
return "Your" if capitalize else "your"
name = caller.get_display_name(looker=receiver) \
if hasattr(caller, "get_display_name") else str(caller)
name = (
caller.get_display_name(looker=receiver)
if hasattr(caller, "get_display_name")
else str(caller)
)
return name + "'s"

View file

@ -84,7 +84,6 @@ class TestCreateScript(BaseEvenniaTest):
class TestCreateHelpEntry(TestCase):
help_entry = """
Qui laborum voluptas quis commodi ipsum quo temporibus eum. Facilis
assumenda facilis architecto in corrupti. Est placeat eum amet qui beatae
@ -130,7 +129,6 @@ class TestCreateHelpEntry(TestCase):
class TestCreateMessage(BaseEvenniaTest):
msgtext = """
Qui laborum voluptas quis commodi ipsum quo temporibus eum. Facilis
assumenda facilis architecto in corrupti. Est placeat eum amet qui beatae

View file

@ -5,9 +5,10 @@ Tests for dbserialize module
from collections import defaultdict, deque
from django.test import TestCase
from parameterized import parameterized
from evennia.objects.objects import DefaultObject
from evennia.utils import dbserialize
from parameterized import parameterized
class TestDbSerialize(TestCase):
@ -203,7 +204,6 @@ class DbObjWrappers(TestCase):
self.assertEqual(self.dbobj1.db.dict["key2"].hidden_obj, self.dbobj2)
def test_dbobj_hidden_defaultdict(self):
con1 = _ValidContainer(self.dbobj2)
con2 = _ValidContainer(self.dbobj2)

View file

@ -10,7 +10,6 @@ from evennia.utils import ansi, evform, evtable
class TestEvForm(TestCase):
maxDiff = None
def _parse_form(self):
@ -275,7 +274,6 @@ class TestEvFormErrors(TestCase):
maxDiff = None
def _form(self, form, **kwargs):
formdict = {
"form": form,
"formchar": "x",

View file

@ -21,9 +21,10 @@ import copy
from anything import Anything
from django.test import TestCase
from mock import MagicMock
from evennia.utils import ansi, evmenu
from evennia.utils.test_resources import BaseEvenniaTest
from mock import MagicMock
class TestEvMenu(TestCase):

View file

@ -113,7 +113,6 @@ class TestFuncParser(TestCase):
"""
def setUp(self):
self.parser = funcparser.FuncParser(_test_callables)
def test_constructor_wrong_args(self):
@ -154,55 +153,55 @@ class TestFuncParser(TestCase):
(r'Test args10 $foo(",")', "Test args10 _test(,)"),
("Test args11 $foo(()", "Test args11 $foo(()"), # invalid syntax
(
r'Test kwarg1 $bar(foo=1, bar="foo", too=ere)',
"Test kwarg1 _test(foo=1, bar=foo, too=ere)",
r'Test kwarg1 $bar(foo=1, bar="foo", too=ere)',
"Test kwarg1 _test(foo=1, bar=foo, too=ere)",
),
("Test kwarg2 $bar(foo,bar,too=ere)", "Test kwarg2 _test(foo, bar, too=ere)"),
("test kwarg3 $foo(foo = bar, bar = ere )", "test kwarg3 _test(foo=bar, bar=ere)"),
(
r"test kwarg4 $foo(foo =' bar ',\" bar \"= ere )",
"test kwarg4 _test(foo=' bar ', \" bar \"=ere)",
r"test kwarg4 $foo(foo =' bar ',\" bar \"= ere )",
"test kwarg4 _test(foo=' bar ', \" bar \"=ere)",
),
(
"Test nest1 $foo($bar(foo,bar,too=ere))",
"Test nest1 _test(_test(foo, bar, too=ere))",
"Test nest1 $foo($bar(foo,bar,too=ere))",
"Test nest1 _test(_test(foo, bar, too=ere))",
),
(
"Test nest2 $foo(bar,$repl(a),$repl()=$repl(),a=b) etc",
"Test nest2 _test(bar, rar, rr=rr, a=b) etc",
"Test nest2 $foo(bar,$repl(a),$repl()=$repl(),a=b) etc",
"Test nest2 _test(bar, rar, rr=rr, a=b) etc",
),
("Test nest3 $foo(bar,$repl($repl($repl(c))))", "Test nest3 _test(bar, rrrcrrr)"),
(
"Test nest4 $foo($bar(a,b),$bar(a,$repl()),$bar())",
"Test nest4 _test(_test(a, b), _test(a, rr), _test())",
"Test nest4 $foo($bar(a,b),$bar(a,$repl()),$bar())",
"Test nest4 _test(_test(a, b), _test(a, rr), _test())",
),
("Test escape1 \\$repl(foo)", "Test escape1 $repl(foo)"),
(
'Test escape2 "This is $foo() and $bar($bar())", $repl()',
'Test escape2 "This is _test() and _test(_test())", rr',
'Test escape2 "This is $foo() and $bar($bar())", $repl()',
'Test escape2 "This is _test() and _test(_test())", rr',
),
(
"Test escape3 'This is $foo() and $bar($bar())', $repl()",
"Test escape3 'This is _test() and _test(_test())', rr",
"Test escape3 'This is $foo() and $bar($bar())', $repl()",
"Test escape3 'This is _test() and _test(_test())', rr",
),
(
"Test escape4 $$foo() and $$bar(a,b), $repl()",
"Test escape4 $foo() and $bar(a,b), rr",
"Test escape4 $$foo() and $$bar(a,b), $repl()",
"Test escape4 $foo() and $bar(a,b), rr",
),
("Test with color |r$foo(a,b)|n is ok", "Test with color |r_test(a, b)|n is ok"),
("Test malformed1 This is $foo( and $bar(", "Test malformed1 This is $foo( and $bar("),
(
"Test malformed2 This is $foo( and $bar()",
"Test malformed2 This is $foo( and _test()",
"Test malformed2 This is $foo( and $bar()",
"Test malformed2 This is $foo( and _test()",
),
("Test malformed3 $", "Test malformed3 $"),
(
"Test malformed4 This is $foo(a=b and $bar(",
"Test malformed4 This is $foo(a=b and $bar(",
"Test malformed4 This is $foo(a=b and $bar(",
"Test malformed4 This is $foo(a=b and $bar(",
),
(
"Test malformed5 This is $foo(a=b, and $repl()",
"Test malformed5 This is $foo(a=b, and rr",
"Test malformed5 This is $foo(a=b, and $repl()",
"Test malformed5 This is $foo(a=b, and rr",
),
("Test nonstr 4x2 = $double(4)", "Test nonstr 4x2 = 8"),
("Test nonstr 4x2 = $double(foo)", "Test nonstr 4x2 = N/A"),
@ -212,8 +211,8 @@ class TestFuncParser(TestCase):
("Test eval3 $eval(\"'21' + 'foo' + 'bar'\")", "Test eval3 21foobar"),
(r"Test eval4 $eval('21' + '$repl()' + \"\" + str(10 // 2))", "Test eval4 21rr5"),
(
r"Test eval5 $eval(\'21\' + \'\$repl()\' + \'\' + str(10 // 2))",
"Test eval5 21$repl()5",
r"Test eval5 $eval(\'21\' + \'\$repl()\' + \'\' + str(10 // 2))",
"Test eval5 21$repl()5",
),
("Test eval6 $eval(\"'$repl(a)' + '$repl(b)'\")", "Test eval6 rarrbr"),
("Test type1 $typ([1,2,3,4])", "Test type1 <class 'list'>"),
@ -222,8 +221,8 @@ class TestFuncParser(TestCase):
("Test type4 $typ({1:2,3:4})", "Test type4 <class 'dict'>"),
("Test type5 $typ(1), $typ(1.0)", "Test type5 <class 'int'>, <class 'float'>"),
(
"Test type6 $typ(\"'1'\"), $typ('\"1.0\"')",
"Test type6 <class 'str'>, <class 'str'>",
"Test type6 $typ(\"'1'\"), $typ('\"1.0\"')",
"Test type6 <class 'str'>, <class 'str'>",
),
("Test add1 $add(1, 2)", "Test add1 3"),
("Test add2 $add([1,2,3,4], [5,6])", "Test add2 [1, 2, 3, 4, 5, 6]"),
@ -248,8 +247,8 @@ class TestFuncParser(TestCase):
@parameterized.expand(
(
"Test malformed This is $dummy(a, b) and $bar(",
"Test $funcNotFound()",
"Test malformed This is $dummy(a, b) and $bar(",
"Test $funcNotFound()",
)
)
def test_parse_raise_unparseable(self, unparseable):
@ -437,24 +436,24 @@ class TestDefaultCallables(TestCase):
("$You() $conj(smile) at $You(char1).", "You smile at You.", "Char1 smiles at Char1."),
("$You() $conj(smile) at $You(char2).", "You smile at Char2.", "Char1 smiles at You."),
(
"$You(char2) $conj(smile) at $you(char1).",
"Char2 smile at you.",
"You smiles at Char1.",
"$You(char2) $conj(smile) at $you(char1).",
"Char2 smile at you.",
"You smiles at Char1.",
),
(
"$You() $conj(smile) to $pron(yourself,m).",
"You smile to yourself.",
"Char1 smiles to himself.",
"$You() $conj(smile) to $pron(yourself,m).",
"You smile to yourself.",
"Char1 smiles to himself.",
),
(
"$You() $conj(smile) to $pron(herself).",
"You smile to yourself.",
"Char1 smiles to herself.",
"$You() $conj(smile) to $pron(herself).",
"You smile to yourself.",
"Char1 smiles to herself.",
), # reverse reference
(
"$Your() smile is the greatest ever.",
"Your smile is the greatest ever.",
"Char1's smile is the greatest ever."
"$Your() smile is the greatest ever.",
"Your smile is the greatest ever.",
"Char1's smile is the greatest ever.",
),
]
)
@ -516,8 +515,8 @@ class TestDefaultCallables(TestCase):
[
("Test $pad(Hello, 20, c, -) there", "Test -------Hello-------- there"),
(
"Test $pad(Hello, width=20, align=c, fillchar=-) there",
"Test -------Hello-------- there",
"Test $pad(Hello, width=20, align=c, fillchar=-) there",
"Test -------Hello-------- there",
),
("Test $crop(This is a long test, 12)", "Test This is[...]"),
("Some $space(10) here", "Some here"),
@ -533,16 +532,16 @@ class TestDefaultCallables(TestCase):
("Some $rjust(Hello, width=30)", "Some Hello"),
("Some $cjust(Hello, 30)", "Some Hello "),
(
"There $pluralize(is, 1, are) one $pluralize(goose, 1, geese) here.",
"There is one goose here.",
"There $pluralize(is, 1, are) one $pluralize(goose, 1, geese) here.",
"There is one goose here.",
),
(
"There $pluralize(is, 2, are) two $pluralize(goose, 2, geese) here.",
"There are two geese here.",
"There $pluralize(is, 2, are) two $pluralize(goose, 2, geese) here.",
"There are two geese here.",
),
(
"There is $int2str(1) murderer, but $int2str(12) suspects.",
"There is one murderer, but twelve suspects.",
"There is $int2str(1) murderer, but $int2str(12) suspects.",
"There is one murderer, but twelve suspects.",
),
("There is $an(thing) here", "There is a thing here"),
("Some $eval(\"'-'*20\")Hello", "Some --------------------Hello"),

View file

@ -318,7 +318,6 @@ class LatinifyTest(TestCase):
class TestFormatGrid(TestCase):
maxDiff = None
def setUp(self):

View file

@ -128,7 +128,6 @@ class TestValidatorFuncs(TestCase):
validatorfuncs.boolean(b)
def test_timezone_ok(self):
for tz in ["America/Chicago", "GMT", "UTC"]:
self.assertEqual(tz, validatorfuncs.timezone(tz).zone)

View file

@ -27,7 +27,6 @@ from os.path import join as osjoin
from string import punctuation
from unicodedata import east_asian_width
import evennia
from django.apps import apps
from django.conf import settings
from django.core.exceptions import ValidationError as DjangoValidationError
@ -35,12 +34,14 @@ from django.core.validators import validate_email as django_validate_email
from django.utils import timezone
from django.utils.html import strip_tags
from django.utils.translation import gettext as _
from evennia.utils import logger
from simpleeval import simple_eval
from twisted.internet import reactor, threads
from twisted.internet.defer import returnValue # noqa - used as import target
from twisted.internet.task import deferLater
import evennia
from evennia.utils import logger
_MULTIMATCH_TEMPLATE = settings.SEARCH_MULTIMATCH_TEMPLATE
_EVENNIA_DIR = settings.EVENNIA_DIR
_GAME_DIR = settings.GAME_DIR
@ -2941,4 +2942,3 @@ def str2int(number):
# invalid number-word, raise ValueError
raise ValueError(f"String {original_input} cannot be converted to int.")
return sum(sums)