mirror of
https://github.com/evennia/evennia.git
synced 2026-03-21 15:26:30 +01:00
Cleanups and bug fixes. Fixed the @unlink command and also made it overally more stable. Resolves issue 161. Added more string conversion routines to handle non-ascii variables being stored in an Attribute. Resolves issue 160.
This commit is contained in:
parent
14db4bea4d
commit
7d30b337d9
27 changed files with 873 additions and 1048 deletions
|
|
@ -12,6 +12,8 @@ from twisted.internet import threads
|
|||
from django.conf import settings
|
||||
from src.utils import ansi
|
||||
|
||||
ENCODINGS = settings.ENCODINGS
|
||||
|
||||
def is_iter(iterable):
|
||||
"""
|
||||
Checks if an object behaves iterably. However,
|
||||
|
|
@ -225,29 +227,39 @@ def to_unicode(obj, encoding='utf-8'):
|
|||
needs to encode it back to utf-8
|
||||
before writing to disk or printing.
|
||||
"""
|
||||
if isinstance(obj, basestring) \
|
||||
and not isinstance(obj, unicode):
|
||||
if isinstance(obj, basestring) and not isinstance(obj, unicode):
|
||||
try:
|
||||
obj = unicode(obj, encoding)
|
||||
return obj
|
||||
except UnicodeDecodeError:
|
||||
raise Exception("Error: '%s' contains invalid character(s) not in %s." % (obj, encoding))
|
||||
return obj
|
||||
for alt_encoding in ENCODINGS:
|
||||
try:
|
||||
obj = unicode(obj, alt_encoding)
|
||||
return obj
|
||||
except UnicodeDecodeError:
|
||||
pass
|
||||
raise Exception("Error: '%s' contains invalid character(s) not in %s." % (obj, encoding))
|
||||
return obj
|
||||
|
||||
def to_str(obj, encoding='utf-8'):
|
||||
"""
|
||||
This encodes a unicode string
|
||||
back to byte-representation,
|
||||
This encodes a unicode string back to byte-representation,
|
||||
for printing, writing to disk etc.
|
||||
"""
|
||||
if isinstance(obj, basestring) \
|
||||
and isinstance(obj, unicode):
|
||||
if isinstance(obj, basestring) and isinstance(obj, unicode):
|
||||
try:
|
||||
obj = obj.encode(encoding)
|
||||
return obj
|
||||
except UnicodeEncodeError:
|
||||
raise Exception("Error: Unicode could not encode unicode string '%s'(%s) to a bytestring. " % (obj, encoding))
|
||||
for alt_encoding in ENCODINGS:
|
||||
try:
|
||||
obj = obj.encode(encoding)
|
||||
return obj
|
||||
except UnicodeEncodeError:
|
||||
pass
|
||||
raise Exception("Error: Unicode could not encode unicode string '%s'(%s) to a bytestring. " % (obj, encoding))
|
||||
return obj
|
||||
|
||||
|
||||
def validate_email_address(emailaddress):
|
||||
"""
|
||||
Checks if an email address is syntactically correct.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue