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:
Griatch 2011-04-16 22:26:22 +00:00
parent 14db4bea4d
commit 7d30b337d9
27 changed files with 873 additions and 1048 deletions

View file

@ -48,9 +48,8 @@ def start_reload_loop():
"default callback"
cemit_info(" Asynchronous server reload finished.\n" + '-'*50)
def at_err(e):
"error callback"
string = "%s\n reload: Asynchronous reset loop exited with an error." % e
string += "\n This might be harmless. Wait a moment then reload again to see if the problem persists."
"error callback"
string = "Reload: Asynchronous reset exited with an error:\n{r%s{n" % e.getErrorMessage()
cemit_info(string)
utils.run_async(run_loop, at_return, at_err)

View file

@ -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.