Resolve merge conflicts

This commit is contained in:
Griatch 2020-07-18 15:56:47 +02:00
commit 862d2a5d06
9 changed files with 228 additions and 121 deletions

View file

@ -65,6 +65,7 @@ never traceback.
import re
import fnmatch
import random as base_random
from django.conf import settings
from evennia.utils import utils, logger
@ -72,6 +73,53 @@ from evennia.utils import utils, logger
# example/testing inline functions
def random(*args, **kwargs):
"""
Inlinefunc. Returns a random number between
0 and 1, from 0 to a maximum value, or within a given range (inclusive).
Args:
minval (str, optional): Minimum value. If not given, assumed 0.
maxval (str, optional): Maximum value.
Keyword argumuents:
session (Session): Session getting the string.
Notes:
If either of the min/maxvalue has a '.' in it, a floating-point random
value will be returned. Otherwise it will be an integer value in the
given range.
Example:
`$random()`
`$random(5)`
`$random(5, 10)`
"""
nargs = len(args)
if nargs == 1:
# only maxval given
minval, maxval = '0', args[0]
elif nargs > 1:
minval, maxval = args[:2]
else:
minval, maxval = ('0', '1')
if "." in minval or "." in maxval:
# float mode
try:
minval, maxval = float(minval), float(maxval)
except ValueError:
minval, maxval = 0, 1
return "{:.2f}".format(minval + maxval * base_random.random())
else:
# int mode
try:
minval, maxval = int(minval), int(maxval)
except ValueError:
minval, maxval = 0, 1
return str(base_random.randint(minval, maxval))
def pad(*args, **kwargs):
"""
@ -82,7 +130,8 @@ def pad(*args, **kwargs):
width (str, optional): Will be converted to integer. Width
of padding.
align (str, optional): Alignment of padding; one of 'c', 'l' or 'r'.
fillchar (str, optional): Character used for padding. Defaults to a space.
fillchar (str, optional): Character used for padding. Defaults to a
space.
Keyword args:
session (Session): Session performing the pad.
@ -468,6 +517,17 @@ def parse_inlinefunc(string, strip=False, available_funcs=None, stacktrace=False
return retval
def raw(string):
"""
Escape all inlinefuncs in a string so they won't get parsed.
Args:
string (str): String with inlinefuncs to escape.
"""
def _escape(match):
return "\\" + match.group(0)
return _RE_STARTTOKEN.sub(_escape, string)
#
# Nick templating
#

View file

@ -2025,8 +2025,8 @@ def display_len(target):
strip MXP patterns.
Args:
target (string): A string with potential MXP components
to search.
target (any): Something to measure the length of. If a string, it will be
measured keeping asian-character and MXP links in mind.
Return:
int: The visible width of the target.