Changeset View
Changeset View
Standalone View
Standalone View
pykolab/imap_utf7.py
Show All 25 Lines | |||||
class FolderNameError(ValueError): | class FolderNameError(ValueError): | ||||
pass | pass | ||||
def encode(s): | def encode(s): | ||||
if isinstance(s, str) and sum(n for n in (ord(c) for c in s) if n > 127): | if isinstance(s, str) and sum(n for n in (ord(c) for c in s) if n > 127): | ||||
try: | try: | ||||
s = unicode(s, "UTF-8") | s = unicode(s, "UTF-8") | ||||
except Exception, errmsg: | except Exception: | ||||
raise FolderNameError("%r contains characters not valid in a str folder name. " | raise FolderNameError("%r contains characters not valid in a str folder name. " | ||||
"Convert to unicode first?" % s) | "Convert to unicode first?" % s) | ||||
r = [] | r = [] | ||||
_in = [] | _in = [] | ||||
for c in s: | for c in s: | ||||
if ord(c) in (range(0x20, 0x26) + range(0x27, 0x7f)): | if ord(c) in (range(0x20, 0x26) + range(0x27, 0x7f)): | ||||
if _in: | if _in: | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |