Changeset View
Changeset View
Standalone View
Standalone View
cyruslib.py
Context not available. | |||||
elif not isinstance(s, (six.text_type, six.binary_type)): | elif not isinstance(s, (six.text_type, six.binary_type)): | ||||
raise TypeError("not expecting type '%s'" % type(s)) | raise TypeError("not expecting type '%s'" % type(s)) | ||||
return s | return s | ||||
def ensure_binary(s, encoding='utf-8', errors='strict'): | |||||
"""Coerce **s** to six.binary_type. | |||||
For Python 2: | |||||
- `unicode` -> encoded to `str` | |||||
- `str` -> `str` | |||||
For Python 3: | |||||
- `str` -> encoded to `bytes` | |||||
- `bytes` -> `bytes` | |||||
Copied from six (not available < 1.12), and extended with list support. | |||||
""" | |||||
if isinstance(s, list): | |||||
#FIXME pass encoding | |||||
return list(map(ensure_binary, s)) | |||||
if isinstance(s, six.binary_type): | |||||
return s | |||||
if isinstance(s, six.text_type): | |||||
return s.encode(encoding, errors) | |||||
raise TypeError("not expecting type '%s'" % type(s)) | |||||
def ok(res): | def ok(res): | ||||
return res.upper().startswith('OK') | return res.upper().startswith('OK') | ||||
Context not available. | |||||
return ok(res), dat[0] | return ok(res), dat[0] | ||||
def getannotation(self, mailbox, pattern='*', shared=None): | def getannotation(self, mailbox, pattern='*', shared=None): | ||||
if shared == None: | if shared is None: | ||||
typ, dat = self._simple_command('GETANNOTATION', mailbox, quote(pattern), quote('*')) | typ, dat = self._simple_command('GETANNOTATION', mailbox, quote(pattern), quote('*')) | ||||
elif shared: | elif shared: | ||||
typ, dat = self._simple_command('GETANNOTATION', mailbox, quote(pattern), quote('value.shared')) | typ, dat = self._simple_command('GETANNOTATION', mailbox, quote(pattern), quote('value.shared')) | ||||
Context not available. | |||||
return ok(res), dat[0] | return ok(res), dat[0] | ||||
def getannotation(self, mailbox, pattern='*', shared=None): | def getannotation(self, mailbox, pattern='*', shared=None): | ||||
if shared == None: | if shared is None: | ||||
typ, dat = self._simple_command('GETANNOTATION', mailbox, quote(pattern), quote('*')) | typ, dat = self._simple_command('GETANNOTATION', mailbox, quote(pattern), quote('*')) | ||||
elif shared: | elif shared: | ||||
typ, dat = self._simple_command('GETANNOTATION', mailbox, quote(pattern), quote('value.shared')) | typ, dat = self._simple_command('GETANNOTATION', mailbox, quote(pattern), quote('value.shared')) | ||||
Context not available. | |||||
elif self.ENCODING in self.ENCODING_LIST: | elif self.ENCODING in self.ENCODING_LIST: | ||||
return self.__decode(text) | return self.__decode(text) | ||||
def lm(self, pattern="*"): | def lm(self, pattern=b"*"): | ||||
sicherha: In D3884 you try to ensure that `lm()` always receives a `str`. Here, by contrast, you change… | |||||
ghaneAuthorUnsubmitted Not Done Inline ActionsAs it is decoded in line 582 it doesn't harm anyway, but as in line 578 and 579 the pattern is the same. Because of "def decode" D3884 also dellivers a string like " b'mailbox' " as pattern ghane: As it is decoded in line 582 it doesn't harm anyway, but as in line 578 and 579 the pattern is… | |||||
""" | """ | ||||
List mailboxes, returns dict with list of mailboxes | List mailboxes, returns dict with list of mailboxes | ||||
Context not available. | |||||
""" | """ | ||||
self.__prepare('LIST') | self.__prepare('LIST') | ||||
if pattern == '': pattern = "*" | if pattern == b'': pattern = b"*" | ||||
if pattern == '%': | if pattern == b'%': | ||||
res, ml = self.__docommand('list', '', '%') | res, ml = self.__docommand('list', '', '%') | ||||
else: | else: | ||||
res, ml = self.__docommand('list', '""', self.decode(pattern)) | res, ml = self.__docommand('list', '""', self.decode(pattern)) | ||||
Context not available. | |||||
def dm(self, mailbox, recursive=True): | def dm(self, mailbox, recursive=True): | ||||
"""Delete mailbox""" | """Delete mailbox""" | ||||
self.__prepare('DELETE', mailbox) | self.__prepare('DELETE', mailbox) | ||||
mbxTmp = mailbox.split(self.SEP) | SEPARATOR = ensure_binary(self.SEP) | ||||
mbxTmp = mailbox.split(SEPARATOR) | |||||
# Cyrus is not recursive for user subfolders and global folders | # Cyrus is not recursive for user subfolders and global folders | ||||
if (recursive and mbxTmp[0] != "user") or (len(mbxTmp) > 2): | if (recursive and mbxTmp[0] != "user") or (len(mbxTmp) > 2): | ||||
mbxList = self.lm("%s%s*" % (mailbox, self.SEP)) | mbxList = self.lm("%s%s*" % (mailbox, self.SEP)) | ||||
Context not available. | |||||
"""Get Annotation""" | """Get Annotation""" | ||||
self.__prepare('GETANNOTATION') | self.__prepare('GETANNOTATION') | ||||
res, data = self.__docommand('getannotation', self.decode(mailbox), pattern) | res, data = self.__docommand('getannotation', self.decode(mailbox), pattern) | ||||
data = ensure_str(data) | |||||
if (len(data) == 1) and data[0] is None: | if (len(data) == 1) and data[0] is None: | ||||
self.__verbose( '[GETANNOTATION %s] No results' % (mailbox) ) | self.__verbose( '[GETANNOTATION %s] No results' % (mailbox) ) | ||||
return {} | return {} | ||||
ann = {} | ann = {} | ||||
annotations = [] | annotations = [] | ||||
empty_values = [ "NIL", '" "', None, '', ' ' ] | empty_values = ["NIL", '" "', None, '', ' '] | ||||
concat_items = [] | concat_items = [] | ||||
for item in data: | for item in data: | ||||
Context not available. | |||||
if value_shared in empty_values: | if value_shared in empty_values: | ||||
value_shared = None | value_shared = None | ||||
if not value_priv == None: | if value_priv is not None: | ||||
ann[folder]['/private' + key] = value_priv | ann[folder]['/private' + key] = value_priv | ||||
if not value_shared == None: | if value_shared is not None: | ||||
ann[folder]['/shared' + key] = value_shared | ann[folder]['/shared' + key] = value_shared | ||||
return ann | return ann | ||||
Context not available. | |||||
self.__prepare('LSUB') | self.__prepare('LSUB') | ||||
if pattern == '': pattern = "*" | if pattern == '': pattern = "*" | ||||
res, ml = self.__docommand('lsub', '*', pattern) | res, ml = self.__docommand('lsub', '*', pattern) | ||||
ml = ensure_str(ml) | |||||
if not ok(res): | if not ok(res): | ||||
self.__verbose( '[LIST] %s: %s' % (res, ml) ) | self.__verbose( '[LIST] %s: %s' % (res, ml) ) | ||||
return [] | return [] | ||||
Context not available. |
In D3884 you try to ensure that lm() always receives a str. Here, by contrast, you change the parameter's default value to the type bytes. That looks inconsistent to me.