mirror of
https://github.com/evennia/evennia.git
synced 2026-03-17 05:16:31 +01:00
Remove to_unicode.
This commit is contained in:
parent
7d524ac328
commit
6f91e1e546
15 changed files with 23 additions and 70 deletions
|
|
@ -22,7 +22,7 @@ from evennia.comms.models import ChannelDB
|
|||
from evennia.commands import cmdhandler
|
||||
from evennia.utils import logger
|
||||
from evennia.utils.utils import (lazy_property,
|
||||
make_iter, to_unicode, is_iter,
|
||||
make_iter, is_iter,
|
||||
variable_from_module)
|
||||
from evennia.typeclasses.attributes import NickHandler
|
||||
from evennia.scripts.scripthandler import ScriptHandler
|
||||
|
|
@ -446,7 +446,6 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
|
|||
commands at run-time.
|
||||
|
||||
"""
|
||||
raw_string = to_unicode(raw_string)
|
||||
raw_string = self.nicks.nickreplace(raw_string, categories=("inputline", "channel"), include_account=False)
|
||||
if not session and _MULTISESSION_MODE in (0, 1):
|
||||
# for these modes we use the first/only session
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ from django.conf import settings
|
|||
from evennia.commands.command import InterruptCommand
|
||||
from evennia.comms.channelhandler import CHANNELHANDLER
|
||||
from evennia.utils import logger, utils
|
||||
from evennia.utils.utils import string_suggestions, to_unicode
|
||||
from evennia.utils.utils import string_suggestions
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
|
|
@ -618,8 +618,6 @@ def cmdhandler(called_by, raw_string, _testing=False, callertype="session", sess
|
|||
finally:
|
||||
_COMMAND_NESTING[called_by] -= 1
|
||||
|
||||
raw_string = to_unicode(raw_string, force_string=True)
|
||||
|
||||
session, account, obj = session, None, None
|
||||
if callertype == "session":
|
||||
session = called_by
|
||||
|
|
|
|||
|
|
@ -533,7 +533,7 @@ class CmdOption(COMMAND_DEFAULT_CLASS):
|
|||
def validate_encoding(new_encoding):
|
||||
# helper: change encoding
|
||||
try:
|
||||
utils.to_str(utils.to_unicode("test-string"), encoding=new_encoding)
|
||||
b"test-string".decode(new_encoding)
|
||||
except LookupError:
|
||||
raise RuntimeError("The encoding '|w%s|n' is invalid. " % new_encoding)
|
||||
return val
|
||||
|
|
|
|||
|
|
@ -1940,7 +1940,6 @@ class CmdExamine(ObjManipCommand):
|
|||
if not isinstance(value, str):
|
||||
value = utils.to_str(value, force_string=True)
|
||||
value = utils.crop(value)
|
||||
value = utils.to_unicode(value)
|
||||
|
||||
string = "\n %s = %s" % (attr, value)
|
||||
string = raw(string)
|
||||
|
|
|
|||
|
|
@ -481,7 +481,7 @@ class CmdUnconnectedEncoding(COMMAND_DEFAULT_CLASS):
|
|||
old_encoding = self.session.protocol_flags.get("ENCODING", None)
|
||||
encoding = self.args
|
||||
try:
|
||||
utils.to_str(utils.to_unicode("test-string"), encoding=encoding)
|
||||
utils.to_str(b"test-string".decode(encoding))
|
||||
except LookupError:
|
||||
string = "|rThe encoding '|w%s|r' is invalid. Keeping the previous encoding '|w%s|r'.|n"\
|
||||
% (encoding, old_encoding)
|
||||
|
|
|
|||
|
|
@ -324,7 +324,7 @@ def build_map(caller, game_map, legend, iterations=1, build_exits=True):
|
|||
for x in range(len(game_map[y])):
|
||||
for key in legend:
|
||||
# obs - we must use == for unicode
|
||||
if utils.to_unicode(game_map[y][x]) == utils.to_unicode(key):
|
||||
if game_map[y][x] == key:
|
||||
room = legend[key](x, y, iteration=iteration,
|
||||
room_dict=room_dict,
|
||||
caller=caller)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from django.db.models import Q
|
|||
from django.conf import settings
|
||||
from django.db.models.fields import exceptions
|
||||
from evennia.typeclasses.managers import TypedObjectManager, TypeclassManager
|
||||
from evennia.utils.utils import to_unicode, is_iter, make_iter, string_partial_matching
|
||||
from evennia.utils.utils import is_iter, make_iter, string_partial_matching
|
||||
from builtins import int
|
||||
|
||||
__all__ = ("ObjectManager",)
|
||||
|
|
@ -72,7 +72,7 @@ class ObjectDBManager(TypedObjectManager):
|
|||
match (Object or list): One or more matching results.
|
||||
|
||||
"""
|
||||
ostring = to_unicode(ostring).lstrip('*')
|
||||
ostring = str(ostring).lstrip('*')
|
||||
# simplest case - search by dbref
|
||||
dbref = self.dbref(ostring)
|
||||
if dbref:
|
||||
|
|
@ -196,8 +196,6 @@ class ObjectDBManager(TypedObjectManager):
|
|||
typeclasses (list, optional): List of typeclass-path strings to restrict matches with
|
||||
|
||||
"""
|
||||
if isinstance(property_value, str):
|
||||
property_value = to_unicode(property_value)
|
||||
if isinstance(property_name, str):
|
||||
if not property_name.startswith('db_'):
|
||||
property_name = "db_%s" % property_name
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ from evennia.commands import cmdhandler
|
|||
from evennia.utils import search
|
||||
from evennia.utils import logger
|
||||
from evennia.utils.utils import (variable_from_module, lazy_property,
|
||||
make_iter, to_unicode, is_iter)
|
||||
make_iter, is_iter)
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
_MULTISESSION_MODE = settings.MULTISESSION_MODE
|
||||
|
|
@ -479,7 +479,6 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
|
|||
"""
|
||||
# nick replacement - we require full-word matching.
|
||||
# do text encoding conversion
|
||||
raw_string = to_unicode(raw_string)
|
||||
raw_string = self.nicks.nickreplace(raw_string, categories=("inputline", "channel"), include_account=True)
|
||||
return cmdhandler.cmdhandler(self, raw_string, callertype="object", session=session, **kwargs)
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ from django.conf import settings
|
|||
from evennia.commands.cmdhandler import cmdhandler
|
||||
from evennia.accounts.models import AccountDB
|
||||
from evennia.utils.logger import log_err
|
||||
from evennia.utils.utils import to_str, to_unicode
|
||||
from evennia.utils.utils import to_str
|
||||
|
||||
BrowserSessionStore = importlib.import_module(settings.SESSION_ENGINE).SessionStore
|
||||
|
||||
|
|
@ -176,7 +176,7 @@ def client_options(session, *args, **kwargs):
|
|||
def validate_encoding(val):
|
||||
# helper: change encoding
|
||||
try:
|
||||
to_str(to_unicode("test-string"), encoding=val)
|
||||
b"test-string".decode(val)
|
||||
except LookupError:
|
||||
raise RuntimeError("The encoding '|w%s|n' is invalid. " % val)
|
||||
return val
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ from django.conf import settings
|
|||
from evennia.commands.cmdhandler import CMD_LOGINSTART
|
||||
from evennia.utils.logger import log_trace
|
||||
from evennia.utils.utils import (variable_from_module, is_iter,
|
||||
to_str, to_unicode,
|
||||
to_str,
|
||||
make_iter,
|
||||
callables_from_module)
|
||||
from evennia.utils.inlinefuncs import parse_inlinefunc
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ all Attributes and TypedObjects).
|
|||
import shlex
|
||||
from django.db.models import Q
|
||||
from evennia.utils import idmapper
|
||||
from evennia.utils.utils import make_iter, variable_from_module, to_unicode
|
||||
from evennia.utils.utils import make_iter, variable_from_module
|
||||
|
||||
__all__ = ("TypedObjectManager", )
|
||||
_GA = object.__getattribute__
|
||||
|
|
@ -494,7 +494,7 @@ class TypeclassManager(TypedObjectManager):
|
|||
|
||||
"""
|
||||
# shlex splits by spaces unless escaped by quotes
|
||||
querysplit = shlex.split(to_unicode(query, force_string=True))
|
||||
querysplit = shlex.split(query)
|
||||
queries, plustags, plusattrs, negtags, negattrs = [], [], [], [], []
|
||||
for ipart, part in enumerate(querysplit):
|
||||
key, rest = part, ""
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ from django.conf import settings
|
|||
from evennia.utils import utils
|
||||
from evennia.utils import logger
|
||||
|
||||
from evennia.utils.utils import to_str, to_unicode
|
||||
from evennia.utils.utils import to_str
|
||||
from future.utils import with_metaclass
|
||||
|
||||
|
||||
|
|
@ -690,7 +690,7 @@ class ANSIString(with_metaclass(ANSIMeta, str)):
|
|||
decoded = True
|
||||
if not decoded:
|
||||
# Completely new ANSI String
|
||||
clean_string = to_unicode(parser.parse_ansi(string, strip_ansi=True, mxp=True))
|
||||
clean_string = parser.parse_ansi(string, strip_ansi=True, mxp=True)
|
||||
string = parser.parse_ansi(string, xterm256=True, mxp=True)
|
||||
elif clean_string is not None:
|
||||
# We have an explicit clean string.
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ from builtins import object, range
|
|||
import re
|
||||
import copy
|
||||
from evennia.utils.evtable import EvCell, EvTable
|
||||
from evennia.utils.utils import all_from_module, to_str, to_unicode, is_iter
|
||||
from evennia.utils.utils import all_from_module, to_str, is_iter
|
||||
from evennia.utils.ansi import ANSIString
|
||||
|
||||
# non-valid form-identifying characters (which can thus be
|
||||
|
|
@ -164,7 +164,7 @@ def _to_ansi(obj, regexable=False):
|
|||
elif is_iter(obj):
|
||||
return [_to_ansi(o) for o in obj]
|
||||
else:
|
||||
return ANSIString(to_unicode(obj), regexable=regexable)
|
||||
return ANSIString(obj, regexable=regexable)
|
||||
|
||||
|
||||
class EvForm(object):
|
||||
|
|
@ -407,7 +407,7 @@ class EvForm(object):
|
|||
self.tablechar = tablechar[0] if len(tablechar) > 1 else tablechar
|
||||
|
||||
# split into a list of list of lines. Form can be indexed with form[iy][ix]
|
||||
self.raw_form = _to_ansi(to_unicode(datadict.get("FORM", "")).split("\n"))
|
||||
self.raw_form = _to_ansi(datadict.get("FORM", "").split("\n"))
|
||||
# strip first line
|
||||
self.raw_form = self.raw_form[1:] if self.raw_form else self.raw_form
|
||||
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ from future.utils import listitems
|
|||
from django.conf import settings
|
||||
from textwrap import TextWrapper
|
||||
from copy import deepcopy, copy
|
||||
from evennia.utils.utils import to_unicode, m_len, is_iter
|
||||
from evennia.utils.utils import m_len, is_iter
|
||||
from evennia.utils.ansi import ANSIString
|
||||
|
||||
_DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH
|
||||
|
|
@ -137,7 +137,7 @@ def _to_ansi(obj):
|
|||
if is_iter(obj):
|
||||
return [_to_ansi(o) for o in obj]
|
||||
else:
|
||||
return ANSIString(to_unicode(obj))
|
||||
return ANSIString(obj)
|
||||
|
||||
|
||||
_unicode = str
|
||||
|
|
|
|||
|
|
@ -96,7 +96,6 @@ def wrap(text, width=_DEFAULT_WIDTH, indent=0):
|
|||
"""
|
||||
if not text:
|
||||
return ""
|
||||
text = to_unicode(text)
|
||||
indent = " " * indent
|
||||
return to_str(textwrap.fill(text, width, initial_indent=indent, subsequent_indent=indent))
|
||||
|
||||
|
|
@ -149,14 +148,13 @@ def crop(text, width=_DEFAULT_WIDTH, suffix="[...]"):
|
|||
|
||||
"""
|
||||
|
||||
utext = to_unicode(text)
|
||||
ltext = len(utext)
|
||||
ltext = len(text)
|
||||
if ltext <= width:
|
||||
return text
|
||||
else:
|
||||
lsuffix = len(suffix)
|
||||
utext = utext[:width] if lsuffix >= width else "%s%s" % (utext[:width - lsuffix], suffix)
|
||||
return to_str(utext)
|
||||
text = text[:width] if lsuffix >= width else "%s%s" % (text[:width - lsuffix], suffix)
|
||||
return to_str(text)
|
||||
|
||||
|
||||
def dedent(text):
|
||||
|
|
@ -702,44 +700,6 @@ def latinify(unicode_string, default='?', pure_ascii=False):
|
|||
return ''.join(converted)
|
||||
|
||||
|
||||
def to_unicode(obj, encoding='utf-8', force_string=False):
|
||||
"""
|
||||
This function is deprecated in the Python 3 version of Evennia and is
|
||||
likely to be phased out in future releases.
|
||||
|
||||
---
|
||||
This decodes a suitable object to the unicode format.
|
||||
|
||||
Args:
|
||||
obj (any): Object to decode to unicode.
|
||||
encoding (str, optional): The encoding type to use for the
|
||||
dedoding.
|
||||
force_string (bool, optional): Always convert to string, no
|
||||
matter what type `obj` is initially.
|
||||
|
||||
Returns:
|
||||
result (unicode or any): Will return a unicode object if input
|
||||
was a string. If input was not a string, the original will be
|
||||
returned unchanged unless `force_string` is also set.
|
||||
|
||||
Notes:
|
||||
One needs to encode the obj back to utf-8 before writing to disk
|
||||
or printing. That non-string objects are let through without
|
||||
conversion is important for e.g. Attributes.
|
||||
|
||||
"""
|
||||
|
||||
if isinstance(obj, (str, bytes, )):
|
||||
return obj
|
||||
|
||||
if force_string:
|
||||
# some sort of other object. Try to
|
||||
# convert it to a string representation.
|
||||
obj = str(obj)
|
||||
|
||||
return obj
|
||||
|
||||
|
||||
def to_str(obj, encoding='utf-8', force_string=False):
|
||||
"""
|
||||
This function is deprecated in the Python 3 version of Evennia and is
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue