Remove to_unicode.

This commit is contained in:
Ryan Stein 2017-11-03 12:36:45 -04:00
parent 7d524ac328
commit 6f91e1e546
15 changed files with 23 additions and 70 deletions

View file

@ -22,7 +22,7 @@ from evennia.comms.models import ChannelDB
from evennia.commands import cmdhandler from evennia.commands import cmdhandler
from evennia.utils import logger from evennia.utils import logger
from evennia.utils.utils import (lazy_property, from evennia.utils.utils import (lazy_property,
make_iter, to_unicode, is_iter, make_iter, is_iter,
variable_from_module) variable_from_module)
from evennia.typeclasses.attributes import NickHandler from evennia.typeclasses.attributes import NickHandler
from evennia.scripts.scripthandler import ScriptHandler from evennia.scripts.scripthandler import ScriptHandler
@ -446,7 +446,6 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
commands at run-time. commands at run-time.
""" """
raw_string = to_unicode(raw_string)
raw_string = self.nicks.nickreplace(raw_string, categories=("inputline", "channel"), include_account=False) raw_string = self.nicks.nickreplace(raw_string, categories=("inputline", "channel"), include_account=False)
if not session and _MULTISESSION_MODE in (0, 1): if not session and _MULTISESSION_MODE in (0, 1):
# for these modes we use the first/only session # for these modes we use the first/only session

View file

@ -46,7 +46,7 @@ from django.conf import settings
from evennia.commands.command import InterruptCommand from evennia.commands.command import InterruptCommand
from evennia.comms.channelhandler import CHANNELHANDLER from evennia.comms.channelhandler import CHANNELHANDLER
from evennia.utils import logger, utils 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 _ from django.utils.translation import ugettext as _
@ -618,8 +618,6 @@ def cmdhandler(called_by, raw_string, _testing=False, callertype="session", sess
finally: finally:
_COMMAND_NESTING[called_by] -= 1 _COMMAND_NESTING[called_by] -= 1
raw_string = to_unicode(raw_string, force_string=True)
session, account, obj = session, None, None session, account, obj = session, None, None
if callertype == "session": if callertype == "session":
session = called_by session = called_by

View file

@ -533,7 +533,7 @@ class CmdOption(COMMAND_DEFAULT_CLASS):
def validate_encoding(new_encoding): def validate_encoding(new_encoding):
# helper: change encoding # helper: change encoding
try: try:
utils.to_str(utils.to_unicode("test-string"), encoding=new_encoding) b"test-string".decode(new_encoding)
except LookupError: except LookupError:
raise RuntimeError("The encoding '|w%s|n' is invalid. " % new_encoding) raise RuntimeError("The encoding '|w%s|n' is invalid. " % new_encoding)
return val return val

View file

@ -1940,7 +1940,6 @@ class CmdExamine(ObjManipCommand):
if not isinstance(value, str): if not isinstance(value, str):
value = utils.to_str(value, force_string=True) value = utils.to_str(value, force_string=True)
value = utils.crop(value) value = utils.crop(value)
value = utils.to_unicode(value)
string = "\n %s = %s" % (attr, value) string = "\n %s = %s" % (attr, value)
string = raw(string) string = raw(string)

View file

@ -481,7 +481,7 @@ class CmdUnconnectedEncoding(COMMAND_DEFAULT_CLASS):
old_encoding = self.session.protocol_flags.get("ENCODING", None) old_encoding = self.session.protocol_flags.get("ENCODING", None)
encoding = self.args encoding = self.args
try: try:
utils.to_str(utils.to_unicode("test-string"), encoding=encoding) utils.to_str(b"test-string".decode(encoding))
except LookupError: except LookupError:
string = "|rThe encoding '|w%s|r' is invalid. Keeping the previous encoding '|w%s|r'.|n"\ string = "|rThe encoding '|w%s|r' is invalid. Keeping the previous encoding '|w%s|r'.|n"\
% (encoding, old_encoding) % (encoding, old_encoding)

View file

@ -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 x in range(len(game_map[y])):
for key in legend: for key in legend:
# obs - we must use == for unicode # 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 = legend[key](x, y, iteration=iteration,
room_dict=room_dict, room_dict=room_dict,
caller=caller) caller=caller)

View file

@ -7,7 +7,7 @@ from django.db.models import Q
from django.conf import settings from django.conf import settings
from django.db.models.fields import exceptions from django.db.models.fields import exceptions
from evennia.typeclasses.managers import TypedObjectManager, TypeclassManager 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 from builtins import int
__all__ = ("ObjectManager",) __all__ = ("ObjectManager",)
@ -72,7 +72,7 @@ class ObjectDBManager(TypedObjectManager):
match (Object or list): One or more matching results. match (Object or list): One or more matching results.
""" """
ostring = to_unicode(ostring).lstrip('*') ostring = str(ostring).lstrip('*')
# simplest case - search by dbref # simplest case - search by dbref
dbref = self.dbref(ostring) dbref = self.dbref(ostring)
if dbref: if dbref:
@ -196,8 +196,6 @@ class ObjectDBManager(TypedObjectManager):
typeclasses (list, optional): List of typeclass-path strings to restrict matches with 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 isinstance(property_name, str):
if not property_name.startswith('db_'): if not property_name.startswith('db_'):
property_name = "db_%s" % property_name property_name = "db_%s" % property_name

View file

@ -22,7 +22,7 @@ from evennia.commands import cmdhandler
from evennia.utils import search from evennia.utils import search
from evennia.utils import logger from evennia.utils import logger
from evennia.utils.utils import (variable_from_module, lazy_property, 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 _ from django.utils.translation import ugettext as _
_MULTISESSION_MODE = settings.MULTISESSION_MODE _MULTISESSION_MODE = settings.MULTISESSION_MODE
@ -479,7 +479,6 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
""" """
# nick replacement - we require full-word matching. # nick replacement - we require full-word matching.
# do text encoding conversion # do text encoding conversion
raw_string = to_unicode(raw_string)
raw_string = self.nicks.nickreplace(raw_string, categories=("inputline", "channel"), include_account=True) raw_string = self.nicks.nickreplace(raw_string, categories=("inputline", "channel"), include_account=True)
return cmdhandler.cmdhandler(self, raw_string, callertype="object", session=session, **kwargs) return cmdhandler.cmdhandler(self, raw_string, callertype="object", session=session, **kwargs)

View file

@ -25,7 +25,7 @@ from django.conf import settings
from evennia.commands.cmdhandler import cmdhandler from evennia.commands.cmdhandler import cmdhandler
from evennia.accounts.models import AccountDB from evennia.accounts.models import AccountDB
from evennia.utils.logger import log_err 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 BrowserSessionStore = importlib.import_module(settings.SESSION_ENGINE).SessionStore
@ -176,7 +176,7 @@ def client_options(session, *args, **kwargs):
def validate_encoding(val): def validate_encoding(val):
# helper: change encoding # helper: change encoding
try: try:
to_str(to_unicode("test-string"), encoding=val) b"test-string".decode(val)
except LookupError: except LookupError:
raise RuntimeError("The encoding '|w%s|n' is invalid. " % val) raise RuntimeError("The encoding '|w%s|n' is invalid. " % val)
return val return val

View file

@ -20,7 +20,7 @@ from django.conf import settings
from evennia.commands.cmdhandler import CMD_LOGINSTART from evennia.commands.cmdhandler import CMD_LOGINSTART
from evennia.utils.logger import log_trace from evennia.utils.logger import log_trace
from evennia.utils.utils import (variable_from_module, is_iter, from evennia.utils.utils import (variable_from_module, is_iter,
to_str, to_unicode, to_str,
make_iter, make_iter,
callables_from_module) callables_from_module)
from evennia.utils.inlinefuncs import parse_inlinefunc from evennia.utils.inlinefuncs import parse_inlinefunc

View file

@ -7,7 +7,7 @@ all Attributes and TypedObjects).
import shlex import shlex
from django.db.models import Q from django.db.models import Q
from evennia.utils import idmapper 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", ) __all__ = ("TypedObjectManager", )
_GA = object.__getattribute__ _GA = object.__getattribute__
@ -494,7 +494,7 @@ class TypeclassManager(TypedObjectManager):
""" """
# shlex splits by spaces unless escaped by quotes # 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 = [], [], [], [], [] queries, plustags, plusattrs, negtags, negattrs = [], [], [], [], []
for ipart, part in enumerate(querysplit): for ipart, part in enumerate(querysplit):
key, rest = part, "" key, rest = part, ""

View file

@ -23,7 +23,7 @@ from django.conf import settings
from evennia.utils import utils from evennia.utils import utils
from evennia.utils import logger 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 from future.utils import with_metaclass
@ -690,7 +690,7 @@ class ANSIString(with_metaclass(ANSIMeta, str)):
decoded = True decoded = True
if not decoded: if not decoded:
# Completely new ANSI String # 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) string = parser.parse_ansi(string, xterm256=True, mxp=True)
elif clean_string is not None: elif clean_string is not None:
# We have an explicit clean string. # We have an explicit clean string.

View file

@ -140,7 +140,7 @@ from builtins import object, range
import re import re
import copy import copy
from evennia.utils.evtable import EvCell, EvTable 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 from evennia.utils.ansi import ANSIString
# non-valid form-identifying characters (which can thus be # non-valid form-identifying characters (which can thus be
@ -164,7 +164,7 @@ def _to_ansi(obj, regexable=False):
elif is_iter(obj): elif is_iter(obj):
return [_to_ansi(o) for o in obj] return [_to_ansi(o) for o in obj]
else: else:
return ANSIString(to_unicode(obj), regexable=regexable) return ANSIString(obj, regexable=regexable)
class EvForm(object): class EvForm(object):
@ -407,7 +407,7 @@ class EvForm(object):
self.tablechar = tablechar[0] if len(tablechar) > 1 else tablechar 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] # 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 # strip first line
self.raw_form = self.raw_form[1:] if self.raw_form else self.raw_form self.raw_form = self.raw_form[1:] if self.raw_form else self.raw_form

View file

@ -120,7 +120,7 @@ from future.utils import listitems
from django.conf import settings from django.conf import settings
from textwrap import TextWrapper from textwrap import TextWrapper
from copy import deepcopy, copy 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 from evennia.utils.ansi import ANSIString
_DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH _DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH
@ -137,7 +137,7 @@ def _to_ansi(obj):
if is_iter(obj): if is_iter(obj):
return [_to_ansi(o) for o in obj] return [_to_ansi(o) for o in obj]
else: else:
return ANSIString(to_unicode(obj)) return ANSIString(obj)
_unicode = str _unicode = str

View file

@ -96,7 +96,6 @@ def wrap(text, width=_DEFAULT_WIDTH, indent=0):
""" """
if not text: if not text:
return "" return ""
text = to_unicode(text)
indent = " " * indent indent = " " * indent
return to_str(textwrap.fill(text, width, initial_indent=indent, subsequent_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(text)
ltext = len(utext)
if ltext <= width: if ltext <= width:
return text return text
else: else:
lsuffix = len(suffix) lsuffix = len(suffix)
utext = utext[:width] if lsuffix >= width else "%s%s" % (utext[:width - lsuffix], suffix) text = text[:width] if lsuffix >= width else "%s%s" % (text[:width - lsuffix], suffix)
return to_str(utext) return to_str(text)
def dedent(text): def dedent(text):
@ -702,44 +700,6 @@ def latinify(unicode_string, default='?', pure_ascii=False):
return ''.join(converted) 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): def to_str(obj, encoding='utf-8', force_string=False):
""" """
This function is deprecated in the Python 3 version of Evennia and is This function is deprecated in the Python 3 version of Evennia and is